00001 #include "QuizFrame.h"
00002 #include "icons/eye.xpm"
00003 #include "icons/goodAns.xpm"
00004 #include "icons/badAns.xpm"
00005 #include "icons/editTerm.xpm"
00006 #include "icons/maximize.xpm"
00007
00008 QuizFrame::QuizFrame( Controller* controller, QWidget *parent = 0, const char* name = 0 )
00009 : QWidget( parent, name ), controller( controller ) {
00010 init();
00011 }
00012
00013 void QuizFrame::init() {
00014 Preferences& prefs = controller->getPreferences();
00015 QFont largeFont = prefs.getLargeFont();
00016 QFont mediumFont = prefs.getMediumFont();
00017 QFont labelsFont = prefs.getLabelsFont();
00018 QString firstLang( controller->getQuizFirstLanguage() );
00019 QString testLang( controller->getQuizTestLanguage() );
00020
00021 topPanel = new QHBox( this, "TopPanel" );
00022 topLeftPanel = new QVBox( topPanel, "TopLeftPanel" );
00023
00024 firstLangPanel = new QHGroupBox( QObject::tr( firstLang ), topLeftPanel, "FirstLangPanel" );
00025 testLangPanel = new QVGroupBox( QObject::tr( testLang ), topLeftPanel, "TestLangPanel" );
00026
00027 controlPanel = new QWidget( this, "ControlPanel" );
00028 controlPanelLayout = new QHBoxLayout( controlPanel );
00029 controlPanelLayout->setSpacing( 2 );
00030
00031 answerControlPanel = new QHBox( controlPanel, "AnswerControlPanel" );
00032
00033 revealAllDataButton = new QPushButton( tr( "Reveal" ), answerControlPanel, "RevealAllData" );
00034 revealAllDataButton->setPixmap( ZPIXMAP( eye_xpm ) );
00035 revealAllDataButton->setEnabled( false );
00036 revealAllDataButton->installEventFilter( this );
00037 QToolTip::add( revealAllDataButton, tr( "Reveal" ) );
00038 connect( revealAllDataButton, SIGNAL( clicked() ), this, SLOT( reveal() ) );
00039
00040 rightAnswerButton = new QPushButton( tr( "RightAnswer" ), answerControlPanel, "RightAnswer" );
00041 rightAnswerButton->setPixmap( ZPIXMAP( goodAns_xpm ) );
00042 rightAnswerButton->setEnabled( false );
00043 rightAnswerButton->installEventFilter( this );
00044 QToolTip::add( rightAnswerButton, tr( "RightAnswer" ) );
00045 connect( rightAnswerButton, SIGNAL( clicked() ), this, SLOT( rightAnswer() ) );
00046
00047 wrongAnswerButton = new QPushButton( tr( "WrongAnswer" ), answerControlPanel, "WrongAnswer" );
00048 wrongAnswerButton->setPixmap( ZPIXMAP( badAns_xpm ) );
00049 wrongAnswerButton->setEnabled( false );
00050 wrongAnswerButton->installEventFilter( this );
00051 QToolTip::add( wrongAnswerButton, tr( "WrongAnswer" ) );
00052 connect( wrongAnswerButton, SIGNAL( clicked() ), this, SLOT( wrongAnswer() ) );
00053
00054 editionButton = new QPushButton( tr( "EditWord" ), controlPanel, "EditData" );
00055 editionButton->setPixmap( ZPIXMAP( editTerm_xpm ) );
00056 editionButton->setMinimumWidth( 100 );
00057 editionButton->setEnabled( false );
00058 editionButton->installEventFilter( this );
00059 QToolTip::add( editionButton, tr( "EditWord" ) );
00060 connect( editionButton, SIGNAL( clicked() ), this, SLOT( editCurrentTerm() ) );
00061
00062 controlPanelLayout->addWidget( answerControlPanel, 1 );
00063 controlPanelLayout->addWidget( editionButton, 0 );
00064
00065 firstLangTermPanel = new QWidget( firstLangPanel, "FirstLangTermPanel" );
00066 firstLangTermPanelLayout = new QHBoxLayout( firstLangTermPanel );
00067 firstLangTermPanelLayout->setSpacing( 2 );
00068 firstLangTermLabel = new QLabel( tr( "Word/Expr." ), firstLangTermPanel, "FirstLangTermLabel" );
00069
00070 firstLangTermStack = new QWidgetStack( firstLangTermPanel, "FirstLangTermStack" );
00071 firstLangTermLineEdit = new ScrollableLineEdit( firstLangTermStack, "FirstLangTermLineEdit" );
00072 firstLangTermLineEdit->setReadOnly( true );
00073 firstLangTermLineEdit->installEventFilter( this );
00074 firstLangTermButton = new QPushButton( tr( "???" ), firstLangTermStack, "FirstLangTermButton" );
00075 firstLangTermButton->installEventFilter( this );
00076 QToolTip::add( firstLangTermStack, tr( "Reveal" ) );
00077 connect( firstLangTermButton, SIGNAL( clicked() ), this, SLOT( revealFirstLangTerm() ) );
00078 firstLangTermStack->addWidget( firstLangTermLineEdit, 0 );
00079 firstLangTermStack->addWidget( firstLangTermButton, 1 );
00080 firstLangTermStack->setMinimumSize( firstLangTermButton->sizeHint() );
00081
00082 firstLangTermPanelLayout->addWidget( firstLangTermLabel, 0 );
00083 firstLangTermPanelLayout->addWidget( firstLangTermStack, 1 );
00084
00085 testLangTopPanel = new QWidget( testLangPanel, "TestLangTopPanel" );
00086 testLangTopPanelLayout = new QHBoxLayout( testLangTopPanel );
00087 testLangTopPanelLayout->setSpacing( 2 );
00088
00089 testLangLabelsPanel = new QVBox( testLangTopPanel, "TestLangLabelsPanel" );
00090 testLangLabelsPanel->setSpacing( 2 );
00091 testLangTermAltLabel = new QLabel( tr( "Alt./Phon." ), testLangLabelsPanel, "TestLangTermAltLabel" );
00092 testLangTermLabel = new QLabel( tr( "Word/Expr." ), testLangLabelsPanel, "TestLangTermLabel" );
00093
00094 testLangFieldsPanel = new QVBox( testLangTopPanel, "TestLangFieldsPanel" );
00095 testLangFieldsPanel->setSpacing( 2 );
00096 testLangTermAltStack = new QWidgetStack( testLangFieldsPanel, "TestLangTermAltStack" );
00097 testLangTermAltLineEdit = new ScrollableLineEdit( testLangTermAltStack, "TestLangTermAltLineEdit" );
00098 testLangTermAltLineEdit->setReadOnly( true );
00099 testLangTermAltLineEdit->installEventFilter( this );
00100 testLangTermAltButton = new QPushButton( tr( "???" ), testLangTermAltStack, "TestLangTermAltButton" );
00101 testLangTermAltStack->installEventFilter( this );
00102 QToolTip::add( testLangTermAltButton, tr( "Reveal" ) );
00103 connect( testLangTermAltButton, SIGNAL( clicked() ), this, SLOT( revealAltTerm() ) );
00104 testLangTermAltStack->addWidget( testLangTermAltLineEdit, 0 );
00105 testLangTermAltStack->addWidget( testLangTermAltButton, 1 );
00106 testLangTermAltStack->setMinimumSize( testLangTermAltButton->sizeHint() );
00107
00108 testLangTermStack = new QWidgetStack( testLangFieldsPanel, "TestLangTermStack" );
00109 testLangTermLineEdit = new ScrollableLineEdit( testLangTermStack, "TestLangTermLineEdit" );
00110 testLangTermLineEdit->setReadOnly( true );
00111 testLangTermLineEdit->installEventFilter( this );
00112 testLangTermButton = new QPushButton( tr( "???" ), testLangTermStack, "TestLangTermButton" );
00113 testLangTermStack->installEventFilter( this );
00114 QToolTip::add( testLangTermButton, tr( "Reveal" ) );
00115 connect( testLangTermButton, SIGNAL( clicked() ), this, SLOT( revealTestLangTerm() ) );
00116
00117 testLangTermStack->addWidget( testLangTermLineEdit, 0 );
00118 testLangTermStack->addWidget( testLangTermButton, 1 );
00119 testLangTermStack->setMinimumSize( testLangTermButton->sizeHint() );
00120
00121 testLangTopPanelLayout->addWidget( testLangLabelsPanel );
00122 testLangTopPanelLayout->addWidget( testLangFieldsPanel, 1 );
00123
00124 commentBox = new QVBox( this, "CommentBox" );
00125 commentBox->setSpacing( 2 );
00126
00127 commentLabelPanel = new QWidget( commentBox, "CommentLabelPanel" );
00128 commentLabelPanelLayout = new QHBoxLayout( commentLabelPanel );
00129 commentLabelPanelLayout->setSpacing( 2 );
00130 commentLabel = new QLabel( tr( "Examples/Comments" ), commentLabelPanel, "TestLangCommentLabel" );
00131 maximizeCommentButton = new QPushButton( tr( "MaximizeComment" ), commentLabelPanel, "MaximizeCommentButton" );
00132 maximizeCommentButton->setPixmap( ZPIXMAP( maximize_xpm ) );
00133 maximizeCommentButton->setToggleButton( true );
00134 maximizeCommentButton->setMaximumHeight( commentLabel->sizeHint().height() > 24 ? commentLabel->sizeHint().height() : 24 );
00135 maximizeCommentButton->setMaximumWidth( maximizeCommentButton->maximumHeight() );
00136 maximizeCommentButton->installEventFilter( this );
00137 QToolTip::add( maximizeCommentButton, tr( "MaximizeComment" ) );
00138 connect( maximizeCommentButton, SIGNAL( toggled( bool ) ), this, SLOT( toggleMaximizeComment( bool ) ) );
00139 commentLabelPanelLayout->addWidget( commentLabel );
00140 commentLabelPanelLayout->addStretch( 1 );
00141 commentLabelPanelLayout->addWidget( maximizeCommentButton );
00142
00143 commentStack = new QWidgetStack( commentBox, "TestLangCommentStack" );
00144 commentStack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
00145
00146 commentMultiLineEdit = new ScrollableMultiLineEdit( commentStack, "TestLangCommentMultiLineEdit" );
00147 commentMultiLineEdit->setWrapPolicy( QMultiLineEdit::Anywhere );
00148 commentMultiLineEdit->setWordWrap( QMultiLineEdit::WidgetWidth );
00149 commentMultiLineEdit->setReadOnly( true );
00150 commentMultiLineEdit->installEventFilter( this );
00151 commentButton = new QPushButton( tr( "???" ), commentStack, "TestLangCommentButton" );
00152 commentButton->installEventFilter( this );
00153 QToolTip::add( commentButton, tr( "Reveal" ) );
00154 connect( commentButton, SIGNAL( clicked() ), this, SLOT( revealComment() ) );
00155 commentStack->addWidget( commentMultiLineEdit, 0 );
00156 commentStack->addWidget( commentButton, 1 );
00157
00158 imageBox = new ImageBox( tr( "Image" ), tr( "???" ), tr( "Reveal" ), topPanel, "ImageBox" );
00159
00160 topLeftPanel->setMaximumHeight( topLeftPanel->maximumHeight() );
00161 imageBox->setMaximumHeight( topLeftPanel->maximumHeight() );
00162
00163 mainLayout = new QVBoxLayout( this );
00164 mainLayout->setSpacing( 2 );
00165 mainLayout->addWidget( topPanel );
00166 mainLayout->addWidget( commentBox, 1 );
00167 mainLayout->addWidget( controlPanel );
00168 mainLayout->activate();
00169
00170 updateFonts();
00171
00172 setButtonsHidden( prefs.areQuizButtonsHidden() );
00173 }
00174
00175 QuizFrame::~QuizFrame() {
00176 }
00177
00178 void QuizFrame::startQuiz() {
00179 setButtonsEnabled( false );
00180 controller->startQuiz();
00181 controller->prepareQuiz();
00182 updateLanguageLabels();
00183 updateFonts();
00184
00185 if( !controller->isQuizInProgress() ) {
00186 QMessageBox::warning( this, QObject::tr( "Information" ), tr( "NoTermsMarkedForStudy" ) );
00187 return;
00188 }
00189
00190 askNextTerm();
00191 }
00192
00193 void QuizFrame::restartQuiz() {
00194 setButtonsEnabled( false );
00195 controller->restartQuiz();
00196 controller->prepareQuiz();
00197 updateLanguageLabels();
00198 updateFonts();
00199
00200 if( !controller->isQuizInProgress() ) {
00201 QMessageBox::warning( this, QObject::tr( "Information" ), tr( "NoTermsMarkedForStudy" ) );
00202 return;
00203 }
00204
00205 askNextTerm();
00206 }
00207
00208 void QuizFrame::resumeQuiz() {
00209 controller->resumeQuiz();
00210 controller->prepareQuiz();
00211 updateLanguageLabels();
00212 updateFonts();
00213 askCurrentTerm();
00214 }
00215
00216 void QuizFrame::setTerm( const Term& term ) {
00217 Translation firstLangTranslation = term.getTranslation( controller->getQuizFirstLanguage() );
00218 Translation testLangTranslation = term.getTranslation( controller->getQuizTestLanguage() );
00219
00220 const QString firstLangWord = firstLangTranslation.getWord();
00221 const QString testLangAlt = testLangTranslation.getAlt();
00222 const QString testLangWord = testLangTranslation.getWord();
00223
00224 QString comment;
00225 BilingualKey commentKey( controller->getQuizFirstLanguage(), controller->getQuizTestLanguage() );
00226 if( term.isCommentExists( commentKey ) )
00227 comment = term.getComment( commentKey );
00228
00229 firstLangTermLineEdit->setText( firstLangWord );
00230 firstLangTermLineEdit->setCursorPosition( 0 );
00231
00232 testLangTermAltLineEdit->setText( testLangAlt );
00233 testLangTermAltLineEdit->setCursorPosition( 0 );
00234
00235 testLangTermLineEdit->setText( testLangWord );
00236 testLangTermLineEdit->setCursorPosition( 0 );
00237
00238 commentMultiLineEdit->setText( comment );
00239 commentMultiLineEdit->setCursorPosition( 0, 0 );
00240
00241 Folder* vocabTree = controller->getVocabTree();
00242 Vocabulary* vocab = vocabTree->getVocabulary( term.getVocabId() );
00243 if( vocab ) {
00244 QString absPath = controller->getResolvedImagePath( term.getImagePath(), *vocab );
00245 imageBox->setImage( absPath );
00246 }
00247 }
00248
00249 void QuizFrame::concludeQuiz() {
00250 setButtonsEnabled( false );
00251 QMessageBox::information( this, QObject::tr( "Information" ), tr( "WellDone" ).arg( controller->getInitialTermCount() ) );
00252 }
00253
00254 Term* QuizFrame::askCurrentTerm() {
00255 restoreCommentField();
00256
00257 Term* currTerm = controller->getCurrentTerm();
00258 if( currTerm )
00259 askTerm( *currTerm );
00260
00261 return( currTerm );
00262 }
00263
00264 Term* QuizFrame::askNextTerm() {
00265 Term* nextTerm = NULL;
00266 if( controller->hasNextTerm() )
00267 nextTerm = controller->getNextTerm();
00268
00269 if( nextTerm ) {
00270 restoreCommentField();
00271 askTerm( *nextTerm );
00272 return( nextTerm );
00273 }
00274 else {
00275 concludeQuiz();
00276 return( NULL );
00277 }
00278 }
00279
00280 void QuizFrame::askTerm( const Term& term ) {
00281 hideAnswers();
00282 controller->initRevealingSequence();
00283 setTerm( term );
00284 reveal();
00285 setButtonsEnabled( true );
00286 }
00287
00288 void QuizFrame::updateLanguageLabels() {
00289 firstLangPanel->setTitle( QObject::tr( controller->getQuizFirstLanguage() ) );
00290 testLangPanel->setTitle( QObject::tr( controller->getQuizTestLanguage() ) );
00291 }
00292
00293 void QuizFrame::setButtonsHidden( bool areHidden ) {
00294 if( areHidden ) {
00295 controlPanel->hide();
00296 maximizeCommentButton->hide();
00297 buttonsHidden = true;
00298 }
00299 else {
00300
00301
00302 if( !maximizeCommentButton->isOn() )
00303 controlPanel->show();
00304 maximizeCommentButton->show();
00305 buttonsHidden = false;
00306 }
00307 }
00308
00309 bool QuizFrame::areButtonsHidden() const {
00310 return( buttonsHidden );
00311 }
00312
00313 void QuizFrame::showEvent( QShowEvent* showEvt ) {
00314 QWidget::showEvent( showEvt );
00315
00316 action[ ACTION_MAXIMIZE ]->setOn( maximizeCommentButton->isOn() );
00317 emit( quizShown() );
00318 }
00319
00320 void QuizFrame::hideEvent( QHideEvent* hideEvt ) {
00321 QWidget::hideEvent( hideEvt );
00322 emit( quizHidden() );
00323 }
00324
00325
00326 bool QuizFrame::event( QEvent* evt ) {
00327
00328 if( evt->type() == QEvent::LayoutHint ) {
00329 if( firstLangPanel->height() != firstLangPanel->sizeHint().height() )
00330 firstLangPanel->setFixedHeight( firstLangPanel->sizeHint().height() );
00331 if( testLangPanel->height() != testLangPanel->sizeHint().height() )
00332 testLangPanel->setFixedHeight( testLangPanel->sizeHint().height() );
00333 }
00334 return( QWidget::event( evt ) );
00335 }
00336
00337 void QuizFrame::rightAnswer() {
00338 if( controller->isQuizInProgress() ) {
00339 controller->rightAnswer();
00340 askNextTerm();
00341 }
00342 }
00343
00344 void QuizFrame::wrongAnswer() {
00345 if( controller->isQuizInProgress() ) {
00346 controller->wrongAnswer();
00347 askNextTerm();
00348 }
00349 }
00350
00351 void QuizFrame::reveal() {
00352 if( controller->isQuizInProgress() ) {
00353 Sequence seq = controller->getRevealingSequence();
00354 int groupCount = seq.getGroupCount();
00355 bool hasShownSomething = false;
00356 int i = controller->getRevealingSequenceStep();
00357 int stepCount = 0;
00358
00359 for( ; i < groupCount && !hasShownSomething; i++, stepCount++ ) {
00360 Sequence::ItemList group = seq.getGroupAt( i );
00361
00362 int itemCount = group.count();
00363 for( int j = 0; j < itemCount; j++ ) {
00364 Sequence::Item item = group[ j ];
00365
00366 switch( item ) {
00367
00368 case Sequence::FIRST_LANG_TERM :
00369 if( !isFirstLangTermRevealed() ) {
00370 revealFirstLangTerm();
00371 hasShownSomething = true;
00372 }
00373 break;
00374
00375 case Sequence::TEST_LANG_ALT :
00376 if( !isAltTermRevealed() ) {
00377 revealAltTerm();
00378 hasShownSomething = true;
00379 }
00380 break;
00381
00382 case Sequence::TEST_LANG_TERM :
00383 if( !isTestLangTermRevealed() ) {
00384 revealTestLangTerm();
00385 hasShownSomething = true;
00386 }
00387 break;
00388
00389 case Sequence::COMMENT :
00390 if( !isCommentRevealed() ) {
00391 revealComment();
00392 hasShownSomething = true;
00393 }
00394 break;
00395
00396 case Sequence::IMAGE :
00397 if( imageBox->containsValidImage() && !isImageRevealed() ) {
00398 revealImage();
00399 hasShownSomething = true;
00400 }
00401 break;
00402
00403 default:
00404 break;
00405 }
00406 }
00407
00408 }
00409 if( hasShownSomething ) {
00410 for( int k = 0; k < stepCount; k++ )
00411 controller->incrementRevealingSequenceStep();
00412 }
00413 else if( i == groupCount ) {
00414 if( isCommentRevealed() )
00415 toggleMaximizeComment( !maximizeCommentButton->isOn() );
00416 }
00417
00418 QApplication::flushX();
00419 }
00420 }
00421
00422 void QuizFrame::revealAll() {
00423 revealTestLangTerm();
00424 revealAltTerm();
00425 revealComment();
00426 revealImage();
00427 QApplication::flushX();
00428 }
00429
00430 bool QuizFrame::eventFilter( QObject*, QEvent* evt ) {
00431 if( evt->type() == QEvent::KeyPress ) {
00432 QKeyEvent* keyEvt = (QKeyEvent*)evt;
00433 switch( keyEvt->key() ) {
00434
00435 case Qt::Key_Up :
00436 if( keyEvt->state() == Qt::ControlButton )
00437 commentMultiLineEdit->scrollPageUp();
00438 else
00439 commentMultiLineEdit->scrollUp();
00440 return( true );
00441
00442 case Qt::Key_Down :
00443 if( keyEvt->state() == Qt::ControlButton )
00444 commentMultiLineEdit->scrollPageDown();
00445 else
00446 commentMultiLineEdit->scrollDown();
00447 return( true );
00448
00449 case Qt::Key_Left : scrollLeft(); return( true );
00450
00451 case Qt::Key_Right : scrollRight(); return( true );
00452
00453 }
00454 }
00455 return( false );
00456 }
00457
00458 void QuizFrame::scrollLeft() {
00459 firstLangTermLineEdit->scrollLeft();
00460 testLangTermLineEdit->scrollLeft();
00461 testLangTermAltLineEdit->scrollLeft();
00462 }
00463
00464 void QuizFrame::scrollRight() {
00465 firstLangTermLineEdit->scrollRight();
00466 testLangTermLineEdit->scrollRight();
00467 testLangTermAltLineEdit->scrollRight();
00468 }
00469
00470 void QuizFrame::updateFonts() {
00471 QFont largeFont( controller->getPreferences().getLargeFont() );
00472 QFont mediumFont( controller->getPreferences().getMediumFont() );
00473 QFont labelsFont( controller->getPreferences().getLabelsFont() );
00474 QString firstLang( controller->getQuizFirstLanguage() );
00475 QString testLang( controller->getQuizTestLanguage() );
00476
00477 firstLangTermLabel->setFont( labelsFont );
00478 firstLangTermLineEdit->setFont( controller->getPreferences().getMediumFont( firstLang ) );
00479 firstLangTermButton->setFont( labelsFont );
00480 firstLangPanel->setFont( labelsFont );
00481
00482 testLangTermAltLabel->setFont( labelsFont );
00483 testLangTermAltLineEdit->setFont( controller->getPreferences().getMediumFont( testLang ) );
00484 testLangTermLabel->setFont( labelsFont );
00485
00486 testLangTermLineEdit->setFont( controller->getPreferences().getLargeFont( testLang ) );
00487
00488 testLangPanel->setFont( labelsFont );
00489
00490 commentLabel->setFont( labelsFont );
00491 commentMultiLineEdit->setFont( controller->getPreferences().getBestFont( firstLang, testLang ) );
00492
00493 firstLangTermPanel->updateGeometry();
00494 firstLangTermPanel->layout()->invalidate();
00495
00496 firstLangTermStack->updateGeometry();
00497
00498 testLangLabelsPanel->updateGeometry();
00499 testLangLabelsPanel->layout()->invalidate();
00500
00501 testLangFieldsPanel->updateGeometry();
00502 testLangFieldsPanel->layout()->invalidate();
00503
00504 updateGeometry();
00505 layout()->invalidate();
00506 }
00507
00508 void QuizFrame::retranslateUi() {
00509 updateLanguageLabels();
00510 firstLangTermLabel->setText( tr( "Word/Expr." ) );
00511 firstLangTermButton->setText( tr( "???" ) );
00512 testLangTermAltLabel->setText( tr( "Alt./Phon." ) );
00513 testLangTermLabel->setText( tr( "Word/Expr." ) );
00514 testLangTermAltButton->setText( tr( "???" ) );
00515 testLangTermButton->setText( tr( "???" ) );
00516 imageBox->setTitle( tr( "Image" ) );
00517 commentLabel->setText( tr( "Examples/Comments" ) );
00518 commentButton->setText( tr( "???" ) );
00519 }
00520
00521 void QuizFrame::hideAnswers() {
00522 firstLangTermStack->raiseWidget( 1 );
00523 testLangTermAltStack->raiseWidget( 1 );
00524 testLangTermStack->raiseWidget( 1 );
00525 commentStack->raiseWidget( 1 );
00526 imageBox->hideImage();
00527 }
00528
00529 void QuizFrame::setButtonsEnabled( bool isEnabled ) {
00530 revealAllDataButton->setEnabled( isEnabled );
00531 rightAnswerButton->setEnabled( isEnabled );
00532 wrongAnswerButton->setEnabled( isEnabled );
00533 editionButton->setEnabled( isEnabled );
00534 }
00535
00536 void QuizFrame::revealFirstLangTerm() {
00537 firstLangTermStack->raiseWidget( 0 );
00538 }
00539
00540 void QuizFrame::revealAltTerm() {
00541 testLangTermAltStack->raiseWidget( 0 );
00542 }
00543
00544 void QuizFrame::revealTestLangTerm() {
00545 testLangTermStack->raiseWidget( 0 );
00546 }
00547
00548 void QuizFrame::revealComment() {
00549 commentStack->raiseWidget( 0 );
00550 }
00551
00552 void QuizFrame::revealImage() {
00553 imageBox->revealImage();
00554 }
00555
00556 void QuizFrame::toggleMaximizeComment( bool isOn ) {
00557 if( isOn )
00558 maximizeCommentField();
00559 else
00560 restoreCommentField();
00561 }
00562
00563 bool QuizFrame::isFirstLangTermRevealed() const {
00564 return( firstLangTermStack->visibleWidget() == firstLangTermStack->widget( 0 ) );
00565 }
00566
00567 bool QuizFrame::isAltTermRevealed() const {
00568 return( testLangTermAltStack->visibleWidget() == testLangTermAltStack->widget( 0 ) );
00569 }
00570
00571 bool QuizFrame::isTestLangTermRevealed() const {
00572 return( testLangTermStack->visibleWidget() == testLangTermStack->widget( 0 ) );
00573 }
00574
00575 bool QuizFrame::isCommentRevealed() const {
00576 return( commentStack->visibleWidget() == commentStack->widget( 0 ) );
00577 }
00578
00579 bool QuizFrame::isImageRevealed() const {
00580 return( imageBox->isImageRevealed() );
00581 }
00582
00583 void QuizFrame::maximizeCommentField() {
00584 setUpdatesEnabled( false );
00585 action[ ACTION_MAXIMIZE ]->setOn( true );
00586 maximizeCommentButton->setOn( true );
00587 firstLangPanel->hide();
00588 testLangPanel->hide();
00589 imageBox->hide();
00590 controlPanel->hide();
00591 revealComment();
00592 setUpdatesEnabled( true );
00593 }
00594
00595 void QuizFrame::restoreCommentField() {
00596 setUpdatesEnabled( false );
00597 action[ ACTION_MAXIMIZE ]->setOn( false );
00598 maximizeCommentButton->setOn( false );
00599 firstLangPanel->show();
00600 testLangPanel->show();
00601
00602 if( imageBox->containsValidImage() )
00603 imageBox->show();
00604
00605 if( !buttonsHidden )
00606 controlPanel->show();
00607 setUpdatesEnabled( true );
00608 }
00609
00610 void QuizFrame::editCurrentTerm() {
00611 if( controller->isQuizInProgress() ) {
00612 Folder* vocabTree = controller->getVocabTree();
00613 Term* term = controller->getCurrentTerm();
00614 if( !term ) {
00615 QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) );
00616 return;
00617 }
00618
00619 Vocabulary* vocab = vocabTree->getVocabulary( term->getVocabId() );
00620 if( vocab == NULL || !vocab->isTermExists( term->getId() ) ) {
00621 QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) );
00622 return;
00623 }
00624
00625 TermDialog dialog( *vocab, controller, this, *term );
00626 dialog.showMaximized();
00627 int result = dialog.exec();
00628 if( result ) {
00629 QString firstLang( controller->getQuizFirstLanguage() );
00630 QString testLang( controller->getQuizTestLanguage() );
00631 Term newTerm = dialog.getTerm();
00632 Translation firstLangTrans = newTerm.getTranslation( firstLang );
00633 Translation testLangTrans = newTerm.getTranslation( testLang );
00634 term->addTranslation( firstLangTrans );
00635 term->addTranslation( testLangTrans );
00636 BilingualKey commentKey( firstLang, testLang );
00637 term->addComment( commentKey, newTerm.getComment( commentKey ) );
00638 term->setImagePath( newTerm.getImagePath() );
00639 vocab->setModificationDate( QDateTime::currentDateTime() );
00640 vocab->setDirty( true );
00641 setTerm( newTerm );
00642 }
00643 }
00644 }