/* constructor */ TaskView::TaskView(QWidget * parent, const char * name, bool padd_sub, bool pmul_div, unsigned int pnr_ratios, unsigned int pmax_md): ExerciseBase(parent, name), add_sub(padd_sub), mul_div(pmul_div), nr_ratios(pnr_ratios), max_md(pmax_md) { #ifdef DEBUG kdDebug() << "constructor TaskView()" << endl; #endif curr_nr_ratios = nr_ratios; /* create a new task */ QApplication::setOverrideCursor(waitCursor); /* show the sand clock */ current_task.create_task(max_md, nr_ratios, add_sub, mul_div); QApplication::restoreOverrideCursor(); /* show the normal cursor */ // the next thing to do on a button click would be to check the entered // result m_currentState = _CHECK_TASK; baseWidget = new QWidget(this, "baseWidget"); baseGrid = new QGridLayout(this, 1, 1, 0, -1, "baseGrid"); baseGrid->addWidget(baseWidget, 0, 0); // this is a VBox realLayout = new QVBoxLayout(baseWidget, 5, 5, "realLayout"); // add a spacer at the top of the VBox QSpacerItem * v_spacer = new QSpacerItem(1, 1); realLayout->addItem(v_spacer); // now a line holding the task, input fields and result QHBoxLayout * taskLineHBoxLayout = new QHBoxLayout(5, "taskLineHBoxLayout"); realLayout->addLayout(taskLineHBoxLayout); // first left is the task widget m_taskWidget = new TaskWidget(baseWidget, "m_taskWidget", current_task); // now we have the input fields aligned in a VBox QVBoxLayout * inputLayout = new QVBoxLayout(5, "inputLayout"); // to validate, that the input is an int KIntValidator *valnum = new KIntValidator( this ); /* add input box so the user can enter numerator */ numer_edit = new QLineEdit(baseWidget, "numer_edit"); numer_edit->setValidator( valnum ); // use the int validator QToolTip::add(numer_edit, i18n("Enter the numerator of your result")); inputLayout->addWidget(numer_edit); /* add a line between the edit boxes */ edit_line = new QFrame(baseWidget, "edit_line"); edit_line->setGeometry(QRect(100, 100, 20, 20)); edit_line->setFrameStyle(QFrame::HLine | QFrame::Sunken); inputLayout->addWidget(edit_line); /* add input box so the user can enter denominator */ deno_edit = new QLineEdit(baseWidget, "deno_edit"); deno_edit->setValidator( valnum ); // use the int validator QToolTip::add(deno_edit, i18n("Enter the denominator of your result")); inputLayout->addWidget(deno_edit); // next is the result widget m_resultWidget = new ResultWidget(baseWidget, "m_resultWidget", *new ratio()); // at the right end we have a label just showing CORRECT or WRONG result_label = new QLabel(baseWidget, "result_label"); result_label->setText(i18n("WRONG")); result_label->hide(); // add another spacer in the middle of the VBox v_spacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum); // --- that is the end of the horizontal line --- // in RTL desktops, we still need to allign the // execise to the left. On Qt4, you can set the direction // of the layout to LTR (instead of inherit), but on Qt3 // the only way of fixing it is inserting the widgets in reversed // order to the layout. // // if you need help with this feel free to contact me - Diego <*****@*****.**> ) // This should fix parts of bug #116831 if (QApplication::reverseLayout()) { taskLineHBoxLayout->addItem(v_spacer); taskLineHBoxLayout->addWidget(result_label); taskLineHBoxLayout->addWidget(m_resultWidget); taskLineHBoxLayout->addLayout(inputLayout); taskLineHBoxLayout->addWidget(m_taskWidget); } else { taskLineHBoxLayout->addWidget(m_taskWidget); taskLineHBoxLayout->addLayout(inputLayout); taskLineHBoxLayout->addWidget(m_resultWidget); taskLineHBoxLayout->addWidget(result_label); taskLineHBoxLayout->addItem(v_spacer); } // add another spacer in the middle of the VBox v_spacer = new QSpacerItem(1, 1); realLayout->addItem(v_spacer); // the lower part of the VBox holds just a right aligned button QHBoxLayout * lowerHBox = new QHBoxLayout(1, "lowerHBox"); realLayout->addLayout(lowerHBox); lowerHBox->addStretch(100); // the right aligned button m_checkButton = new QPushButton( baseWidget, "m_checkButton" ); m_checkButton->setText(i18n("&Check Task")); m_checkButton->setDefault(true); // is the default button of the dialog QToolTip::add(m_checkButton, i18n("Click on this button to check your result. The button will not work if you have not entered a result yet.")); lowerHBox->addWidget(m_checkButton, 1, Qt::AlignRight); QObject::connect(m_checkButton, SIGNAL(clicked()), this, SLOT(slotCheckButtonClicked())); // that the user can start typing without moving the focus numer_edit->setFocus(); // show the whole layout baseWidget->show(); // show the whole layout m_taskWidget->show(); m_resultWidget->hide(); // add tooltip and qwhatsthis help to the widget QToolTip::add(this, i18n("In this exercise you have to solve a given task with fractions.")); QWhatsThis::add(this, i18n("In this exercise you have to solve the generated task. You have to enter numerator and denominator. You can adjust the difficulty of the task with the boxes in the toolbar. Do not forget to reduce the result!")); }
/* constructor */ ExerciseFactorize::ExerciseFactorize(QWidget * parent, const char * name): ExerciseBase(parent, name) { QPalette pal; QColorGroup cg; #ifdef DEBUG kdDebug() << "constructor ExerciseFactorize()" << endl; #endif /* create a new task */ QApplication::setOverrideCursor(waitCursor); /* show the sand clock */ createTask(); QApplication::restoreOverrideCursor(); /* show the normal cursor */ // the next thing to do on a button click would be to check the entered // result m_currentState = _CHECK_TASK; Form1Layout = new QVBoxLayout( this, 11, 6, "Form1Layout"); layout9 = new QVBoxLayout( 0, 0, 6, "layout9"); // The following method fix the problem in // bug #116831, reverse order in RTL desktops. // Amit Ramon [email protected] layout4 = createFactorsLayout(); layout9->addLayout(layout4); spacer2 = new QSpacerItem( 20, 21, QSizePolicy::Minimum, QSizePolicy::Expanding ); layout9->addItem( spacer2 ); layout2 = new QVBoxLayout( 0, 0, 6, "layout2"); // The following method fix the problem in // bug #116831, reverse order in RTL desktops. // Amit Ramon [email protected] layout1 = createButtonsLayout(); layout2->addLayout(layout1); m_removeLastFactorButton = new QPushButton( this, "m_removeLastFactorButton" ); layout2->addWidget( m_removeLastFactorButton ); layout9->addLayout( layout2 ); spacer4 = new QSpacerItem( 20, 21, QSizePolicy::Minimum, QSizePolicy::Expanding ); layout9->addItem( spacer4 ); layout7 = new QHBoxLayout( 0, 0, 6, "layout7"); spacer3 = new QSpacerItem( 361, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); layout7->addItem( spacer3 ); m_checkButton = new QPushButton( this, "m_checkButton" ); layout7->addWidget( m_checkButton ); layout9->addLayout( layout7 ); Form1Layout->addLayout( layout9 ); // the current task QString tmp_str; tmp_str.setNum(m_taskNumber); m_taskLabel->setText(tmp_str); // now set the color for the task label m_taskLabel->setPaletteForegroundColor(SettingsClass::numberColor()); // the equal sign m_equalSignLabel->setText("="); // now set the color for the equal sign m_equalSignLabel->setPaletteForegroundColor(SettingsClass::operationColor()); // the wrong/correct label, we hide it result_label->setText(i18n("WRONG")); result_label->hide(); // the prime factor buttons m_factor2Button->setText( i18n( "2" ) ); m_factor3Button->setText( i18n( "3" ) ); m_factor5Button->setText( i18n( "5" ) ); m_factor7Button->setText( i18n( "7" ) ); m_factor11Button->setText( i18n( "11" ) ); m_factor13Button->setText( i18n( "13" ) ); m_factor17Button->setText( i18n( "17" ) ); m_factor19Button->setText( i18n( "19" ) ); QObject::connect(m_factor2Button, SIGNAL(clicked()), this, SLOT(slotFactor2ButtonClicked())); QObject::connect(m_factor3Button, SIGNAL(clicked()), this, SLOT(slotFactor3ButtonClicked())); QObject::connect(m_factor5Button, SIGNAL(clicked()), this, SLOT(slotFactor5ButtonClicked())); QObject::connect(m_factor7Button, SIGNAL(clicked()), this, SLOT(slotFactor7ButtonClicked())); QObject::connect(m_factor11Button, SIGNAL(clicked()), this, SLOT(slotFactor11ButtonClicked())); QObject::connect(m_factor13Button, SIGNAL(clicked()), this, SLOT(slotFactor13ButtonClicked())); QObject::connect(m_factor17Button, SIGNAL(clicked()), this, SLOT(slotFactor17ButtonClicked())); QObject::connect(m_factor19Button, SIGNAL(clicked()), this, SLOT(slotFactor19ButtonClicked())); // add tooltips to the factor buttons QToolTip::add(m_factor2Button, i18n("Add prime factor 2.")); QToolTip::add(m_factor3Button, i18n("Add prime factor 3.")); QToolTip::add(m_factor5Button, i18n("Add prime factor 5.")); QToolTip::add(m_factor7Button, i18n("Add prime factor 7.")); QToolTip::add(m_factor11Button, i18n("Add prime factor 11.")); QToolTip::add(m_factor13Button, i18n("Add prime factor 13.")); QToolTip::add(m_factor17Button, i18n("Add prime factor 17.")); QToolTip::add(m_factor19Button, i18n("Add prime factor 19.")); // the remove last factor button m_removeLastFactorButton->setText( i18n( "&Remove Last Factor" ) ); m_removeLastFactorButton->setEnabled(false); QObject::connect(m_removeLastFactorButton, SIGNAL(clicked()), this, SLOT(slotRemoveLastFactorButtonClicked())); QToolTip::add(m_removeLastFactorButton, i18n("Removes the last entered prime factor.")); // the check task button m_checkButton->setText( i18n( "&Check Task" ) ); QToolTip::add(m_checkButton, i18n("Click on this button to check your result. The button will not work if you have not entered a result yet.")); QObject::connect(m_checkButton, SIGNAL(clicked()), this, SLOT(slotCheckButtonClicked())); m_checkButton->setDefault(true); // is the default button of the dialog // that the user can start choosing the prime factors m_factor2Button->setFocus(); // set the tab order setTabOrder(m_factor2Button, m_factor3Button); setTabOrder(m_factor3Button, m_factor5Button); setTabOrder(m_factor5Button, m_factor7Button); setTabOrder(m_factor7Button, m_factor11Button); setTabOrder(m_factor13Button, m_factor17Button); setTabOrder(m_factor17Button, m_factor19Button); setTabOrder(m_factor19Button, m_removeLastFactorButton); // add tooltip and qwhatsthis help to the widget QToolTip::add(this, i18n("In this exercise you have to factorize a given number.")); QWhatsThis::add(this, i18n("In this exercise you have to factorize a given number. You have to enter all prime factors of the number. You can add a prime factor by clicking on the corresponding button. The chosen prime factors will be shown in the input field. Do not forget to enter all prime factors, even when a prime factor repeats several times!")); }