File indexing completed on 2024-04-28 03:41:58

0001 /*
0002     SPDX-FileCopyrightText: 2004 Sebastian Stein <seb.kde@hpfsc.de>
0003     SPDX-FileCopyrightText: 2008 Tadeu Araujo <tadeu.araujo@ltia.fc.unesp.br>
0004     SPDX-FileCopyrightText: 2008 Danilo Balzaque <danilo.balzaque@ltia.fc.unesp.br>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #include "ExerciseFactorize.h"
0010 
0011 /* these includes are needed for KDE support */
0012 #include <KLocalizedString>
0013 
0014 /* these includes are needed for Qt support */
0015 #include <QApplication>
0016 #include <QGridLayout>
0017 #include <QLabel>
0018 #include <QPushButton>
0019 #include <QRandomGenerator>
0020 
0021 #ifdef DEBUG
0022 #include <QDebug>
0023 #endif
0024 
0025 /* standard C++ library includes */
0026 #include <cstdlib>
0027 
0028 #include "PrimeNumber.h"
0029 #include "RationalWidget.h"
0030 #include "settingsclass.h"
0031 
0032 /* ----- public member functions ----- */
0033 
0034 /* constructor */
0035 ExerciseFactorize::ExerciseFactorize(QWidget * parent) :
0036     ExerciseBase(parent)
0037 {
0038 #ifdef DEBUG
0039     qDebug() << QStringLiteral("constructor ExerciseFactorize()");
0040 #endif
0041 
0042     /* create a new task */
0043     QApplication::setOverrideCursor(Qt::WaitCursor);  /* show the sand clock */
0044     createTask();
0045     QApplication::restoreOverrideCursor(); /* show the normal cursor */
0046 
0047     // the next thing to do on a button click would be to check the entered
0048     // result
0049     m_currentState = _CHECK_TASK;
0050 
0051     QFont defaultFont = SettingsClass::taskFont();
0052 
0053     taskWidget = new QWidget(this);
0054     taskWidget->setObjectName(QStringLiteral("taskWidget"));
0055     checkWidget = new QWidget(this);
0056     checkWidget->setObjectName(QStringLiteral("checkWidget"));
0057 
0058     baseGrid = new QGridLayout(this);
0059     baseGrid->setObjectName(QStringLiteral("baseGrid"));
0060     baseGrid->setColumnStretch(0, 1);
0061 
0062     baseGrid->addWidget(taskWidget, 0, 0);
0063     baseGrid->addWidget(checkWidget, 0, 1);
0064 
0065     taskLayout = new QGridLayout(taskWidget);
0066     taskLayout->setObjectName(QStringLiteral("taskLayout"));
0067     taskLayout->setRowStretch(0, 1);
0068     taskLayout->setRowStretch(6, 1);
0069     taskLayout->setColumnStretch(0, 1);
0070     taskLayout->setColumnStretch(7, 1);
0071 
0072     checkLayout = new QGridLayout(checkWidget);
0073     checkLayout->setObjectName(QStringLiteral("checkLayout"));
0074 
0075     m_taskLabel = new QLabel(this);
0076     m_taskLabel->setObjectName(QStringLiteral("taskLabel"));
0077     m_taskLabel->setFont(defaultFont);
0078     taskLayout->addWidget(m_taskLabel, 1, 1);
0079 
0080     defaultFont.setBold(true);
0081 
0082     m_equalSignLabel = new QLabel(this);
0083     m_equalSignLabel->setObjectName(QStringLiteral("equalSignLabel"));
0084     m_equalSignLabel->setText(QStringLiteral("="));
0085     m_equalSignLabel->setFont(defaultFont);
0086     taskLayout->addWidget(m_equalSignLabel, 1, 2);
0087 
0088     m_factorsEnteredEdit = new PrimeFactorsLineEdit(this);
0089     m_factorsEnteredEdit->setObjectName(QStringLiteral("factorsEnteredEdit"));
0090     QPalette pal;
0091     pal.setColor(m_factorsEnteredEdit->foregroundRole(), QColor(0, 0, 0));
0092     //m_factorsEnteredEdit->setPalette (pal);
0093     m_factorsEnteredEdit->setFont(defaultFont);
0094     m_factorsEnteredEdit->setFixedSize(320, 35);
0095     taskLayout->addWidget(m_factorsEnteredEdit, 1, 3, 1, 5);
0096 
0097     connect(m_factorsEnteredEdit, &PrimeFactorsLineEdit::contentIsRight, this, &ExerciseFactorize::editContentChanged);
0098     connect(m_factorsEnteredEdit, &PrimeFactorsLineEdit::returnPressed, this, &ExerciseFactorize::slotFactorsEditReturnPressed);
0099 
0100     defaultFont.setPointSize(10);
0101 
0102     m_factor2Button = new QPushButton(this);
0103     m_factor2Button->setObjectName(QStringLiteral("factor2Button"));
0104     m_factor2Button->setFixedSize(50, 35);
0105     m_factor2Button->setFont(defaultFont);
0106     taskLayout->addWidget(m_factor2Button, 4, 3);
0107 
0108     m_factor3Button = new QPushButton(this);
0109     m_factor3Button->setObjectName(QStringLiteral("factor3Button"));
0110     m_factor3Button->setFixedSize(50, 35);
0111     m_factor3Button->setFont(defaultFont);
0112     taskLayout->addWidget(m_factor3Button, 4, 4);
0113 
0114     m_factor5Button = new QPushButton(this);
0115     m_factor5Button->setObjectName(QStringLiteral("factor5Button"));
0116     m_factor5Button->setFixedSize(50, 35);
0117     m_factor5Button->setFont(defaultFont);
0118     taskLayout->addWidget(m_factor5Button, 4, 5);
0119 
0120     m_factor7Button = new QPushButton(this);
0121     m_factor7Button->setObjectName(QStringLiteral("factor7Button"));
0122     m_factor7Button->setFixedSize(50, 35);
0123     m_factor7Button->setFont(defaultFont);
0124     taskLayout->addWidget(m_factor7Button, 4, 6);
0125 
0126     m_factor11Button = new QPushButton(this);
0127     m_factor11Button->setObjectName(QStringLiteral("factor11Button"));
0128     m_factor11Button->setFixedSize(50, 35);
0129     m_factor11Button->setFont(defaultFont);
0130     taskLayout->addWidget(m_factor11Button, 5, 3);
0131 
0132     m_factor13Button = new QPushButton(this);
0133     m_factor13Button->setObjectName(QStringLiteral("factor13Button"));
0134     m_factor13Button->setFixedSize(50, 35);
0135     m_factor13Button->setFont(defaultFont);
0136     taskLayout->addWidget(m_factor13Button, 5, 4);
0137 
0138     m_factor17Button = new QPushButton(this);
0139     m_factor17Button->setObjectName(QStringLiteral("factor17Button"));
0140     m_factor17Button->setFixedSize(50, 35);
0141     m_factor17Button->setFont(defaultFont);
0142     taskLayout->addWidget(m_factor17Button, 5, 5);
0143 
0144     m_factor19Button = new QPushButton(this);
0145     m_factor19Button->setObjectName(QStringLiteral("factor19Button"));
0146     m_factor19Button->setFixedSize(50, 35);
0147     m_factor19Button->setFont(defaultFont);
0148     taskLayout->addWidget(m_factor19Button, 5, 6);
0149 
0150     m_removeLastFactorButton = new QPushButton(this);
0151     m_removeLastFactorButton->setObjectName(QStringLiteral("removeLastFactor"));
0152     m_removeLastFactorButton->setFixedSize(115, 35);
0153     m_removeLastFactorButton->setFont(defaultFont);
0154     m_removeLastFactorButton->setText(i18n("Backspace"));
0155     taskLayout->addWidget(m_removeLastFactorButton, 3, 4, 1, 3, Qt::AlignRight);
0156 
0157     defaultFont.setPointSize(10);
0158 
0159     m_skipButton = new QPushButton(this);
0160     m_skipButton->setObjectName(QStringLiteral("m_skipButton"));
0161     m_skipButton->setText(i18n("&Skip"));
0162     m_skipButton->setToolTip(i18n("Click on this button to skip this question."));
0163     m_skipButton->setFont(defaultFont);
0164     QObject::connect(m_skipButton, &QPushButton::clicked, this, &ExerciseFactorize::slotSkipButtonClicked);
0165     checkLayout->addWidget(m_skipButton, 1, 1);
0166 
0167     // the check task button
0168     m_checkButton = new QPushButton(this);
0169     m_checkButton->setObjectName(QStringLiteral("m_checkButton"));
0170     m_checkButton->setText(i18n("&Check"));
0171     m_checkButton->setToolTip(i18n("Click on this button to check your result. The button will not work if you have not entered a result yet."));
0172     QObject::connect(m_checkButton, &QPushButton::clicked, this, &ExerciseFactorize::slotCheckButtonClicked);
0173     m_checkButton->setFont(defaultFont);
0174     m_checkButton->setDefault(true);  // is the default button of the dialog
0175     checkLayout->addWidget(m_checkButton, 1, 0);
0176 
0177     // next is the result widget
0178     m_resultWidget = new ResultWidget(this,  m_factorsResult);
0179     m_resultWidget->setObjectName(QStringLiteral("m_resultWidget"));
0180     checkLayout->addWidget(m_resultWidget, 0, 0, 1, 2);
0181 
0182     // the current task
0183     QString tmp_str;
0184     tmp_str.setNum(m_taskNumber);
0185     m_taskLabel->setText(tmp_str);
0186 
0187     // now set the color for the task label
0188     pal = QPalette();
0189     pal.setColor(m_taskLabel->foregroundRole(), SettingsClass::numberColor());
0190     m_taskLabel->setPalette(pal);
0191 
0192     // now set the color for the equal sign
0193     pal = QPalette();
0194     pal.setColor(m_equalSignLabel->foregroundRole(), SettingsClass::operationColor());
0195     m_equalSignLabel->setPalette(pal);
0196 
0197     // the prime factor buttons
0198     m_factor2Button->setText(i18n("2"));
0199     m_factor3Button->setText(i18n("3"));
0200     m_factor5Button->setText(i18n("5"));
0201     m_factor7Button->setText(i18n("7"));
0202     m_factor11Button->setText(i18n("11"));
0203     m_factor13Button->setText(i18n("13"));
0204     m_factor17Button->setText(i18n("17"));
0205     m_factor19Button->setText(i18n("19"));
0206     QObject::connect(m_factor2Button, &QPushButton::clicked, this, &ExerciseFactorize::slotFactor2ButtonClicked);
0207     QObject::connect(m_factor3Button, &QPushButton::clicked, this, &ExerciseFactorize::slotFactor3ButtonClicked);
0208     QObject::connect(m_factor5Button, &QPushButton::clicked, this, &ExerciseFactorize::slotFactor5ButtonClicked);
0209     QObject::connect(m_factor7Button, &QPushButton::clicked, this, &ExerciseFactorize::slotFactor7ButtonClicked);
0210     QObject::connect(m_factor11Button, &QPushButton::clicked, this, &ExerciseFactorize::slotFactor11ButtonClicked);
0211     QObject::connect(m_factor13Button, &QPushButton::clicked, this, &ExerciseFactorize::slotFactor13ButtonClicked);
0212     QObject::connect(m_factor17Button, &QPushButton::clicked, this, &ExerciseFactorize::slotFactor17ButtonClicked);
0213     QObject::connect(m_factor19Button, &QPushButton::clicked, this, &ExerciseFactorize::slotFactor19ButtonClicked);
0214 
0215     // add tooltips to the factor buttons
0216     m_factor2Button->setToolTip(i18n("Add prime factor 2."));
0217     m_factor3Button->setToolTip(i18n("Add prime factor 3."));
0218     m_factor5Button->setToolTip(i18n("Add prime factor 5."));
0219     m_factor7Button->setToolTip(i18n("Add prime factor 7."));
0220     m_factor11Button->setToolTip(i18n("Add prime factor 11."));
0221     m_factor13Button->setToolTip(i18n("Add prime factor 13."));
0222     m_factor17Button->setToolTip(i18n("Add prime factor 17."));
0223     m_factor19Button->setToolTip(i18n("Add prime factor 19."));
0224 
0225     // the remove last factor button
0226     m_removeLastFactorButton->setEnabled(false);
0227     QObject::connect(m_removeLastFactorButton, &QPushButton::clicked, this, &ExerciseFactorize::slotRemoveLastFactorButtonClicked);
0228     m_removeLastFactorButton->setToolTip(i18n("Removes the last entered prime factor."));
0229 
0230     m_factor2Button->setFocusPolicy(Qt::NoFocus);
0231     m_factor3Button->setFocusPolicy(Qt::NoFocus);
0232     m_factor5Button->setFocusPolicy(Qt::NoFocus);
0233     m_factor7Button->setFocusPolicy(Qt::NoFocus);
0234     m_factor11Button->setFocusPolicy(Qt::NoFocus);
0235     m_factor13Button->setFocusPolicy(Qt::NoFocus);
0236     m_factor17Button->setFocusPolicy(Qt::NoFocus);
0237     m_factor19Button->setFocusPolicy(Qt::NoFocus);
0238     m_removeLastFactorButton->setFocusPolicy(Qt::NoFocus);
0239 
0240     setLayout(baseGrid);
0241     taskWidget->setLayout(taskLayout);
0242     checkWidget->setLayout(checkLayout);
0243 
0244     // add tooltip and qwhatsthis help to the widget
0245     setToolTip(i18n("In this exercise you have to factorize a given number."));
0246     setWhatsThis(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. Click the 'Backspace' button to remove the last entered prime factor."));
0247 
0248     m_edit = true;
0249 }
0250 
0251 /* destructor */
0252 ExerciseFactorize::~ExerciseFactorize()
0253 {
0254 #ifdef DEBUG
0255     qDebug() << QStringLiteral("destructor ExerciseFactorize()");
0256 #endif
0257 
0258     /* no need to delete any child widgets, Qt does it by itself */
0259 }
0260 
0261 /** resets the current state, creates a new task and count the last task as
0262  * wrong, if it wasn't solved (in _NEXT_TASK state) yet
0263  * mainly used after changing the task parameters */
0264 void ExerciseFactorize::forceNewTask()
0265 {
0266 #ifdef DEBUG
0267     qDebug() << QStringLiteral("forceNewTask ExerciseFactorize()");
0268 #endif
0269 
0270     if (m_currentState == _CHECK_TASK) {
0271         // emit the signal for skipped
0272         Q_EMIT signalExerciseSkipped();
0273     }
0274     m_currentState = _CHECK_TASK;
0275     m_checkButton->setText(i18n("&Check"));
0276 
0277     // Maybe the skip button was clicked with while
0278     // wrong content was int the QLineEdit so...
0279     // Set the QLineEdit's background to white
0280     QPalette palette;
0281     palette.setColor(QPalette::Base, Qt::white);
0282     m_factorsEnteredEdit->setPalette(palette);
0283     // and enable all buttons that could be disabled.
0284     setButtonsEnabled(true);
0285 
0286     // generate next task
0287     (void) nextTask();
0288 }
0289 
0290 
0291 /* ------ public slots ------ */
0292 
0293 void ExerciseFactorize::update()
0294 {
0295     // now set the color for the task label
0296     QPalette pal;
0297     pal.setColor(m_taskLabel->foregroundRole(), SettingsClass::numberColor());
0298     m_taskLabel->setPalette(pal);
0299 
0300     // now set the color for the equal sign
0301     pal = QPalette();
0302     pal.setColor(m_equalSignLabel->foregroundRole(), SettingsClass::operationColor());
0303     m_equalSignLabel->setPalette(pal);
0304 
0305     // and the factors
0306     m_resultWidget->update();
0307 
0308     // update for itself
0309     ((QWidget *) this)->update();
0310 }
0311 
0312 
0313 /* ------ private member functions ------ */
0314 
0315 void ExerciseFactorize::createTask()
0316 {
0317     uint uint_number;
0318     PrimeNumber tmp_primenumber;
0319 
0320     // just pick one number out of the possible numbers to factorize
0321     m_taskNumber = possibleTasks[QRandomGenerator::global()->bounded(numberPossibleTasks)];
0322 
0323     // now get the primefactors of the taskNumber
0324     m_factorsResult.clear();
0325     uint_number = m_taskNumber;
0326     tmp_primenumber.move_first();
0327     do {
0328         // check if the current primenumber is a divisor
0329         if (uint_number % tmp_primenumber.get_current() != 0) {
0330             // no, it is not a divisor, go on with next primenumber
0331             tmp_primenumber.move_forward();
0332         } else {
0333             // current primenumber is a divisor
0334             m_factorsResult.append(tmp_primenumber.get_current());
0335             uint_number = uint(uint_number / tmp_primenumber.get_current());
0336         }
0337     } while (uint_number != 1);
0338 
0339     return;
0340 }
0341 
0342 /** - checks, if the user solved the task correctly
0343         - emits signals if task was solved correctly or wrong */
0344 void ExerciseFactorize::showResult()
0345 {
0346     uint uint_result = 0;
0347 
0348     // change the tooltip of the check button
0349     m_checkButton->setToolTip(i18n("Click on this button to get to the next question."));
0350 
0351     // disable prime factor buttons
0352     m_factor2Button->setEnabled(false);
0353     m_factor3Button->setEnabled(false);
0354     m_factor5Button->setEnabled(false);
0355     m_factor7Button->setEnabled(false);
0356     m_factor11Button->setEnabled(false);
0357     m_factor13Button->setEnabled(false);
0358     m_factor17Button->setEnabled(false);
0359     m_factor19Button->setEnabled(false);
0360     m_skipButton->setEnabled(false);
0361 
0362     // disable factor removal button as well
0363     m_removeLastFactorButton->setEnabled(false);
0364 
0365     // show the result
0366     m_resultWidget->setFactors(m_factorsResult);
0367 
0368     // now calculate the product of the prime factors entered by the user
0369     for (int tmp_uint = 0; tmp_uint < m_factorsEntered.count(); tmp_uint++) {
0370         if (tmp_uint == 0) {
0371             uint_result = m_factorsEntered[0];
0372         } else {
0373             uint_result *= m_factorsEntered[tmp_uint];
0374         }
0375     }
0376 
0377     if (uint_result == m_taskNumber) {
0378         // emit the signal for correct
0379         Q_EMIT signalExerciseSolvedCorrect();
0380 
0381         /* yes, the user entered the correct result */
0382         m_resultWidget->setResult(Ratio(), 1);
0383     } else {
0384         // emit the signal for wrong
0385         Q_EMIT signalExerciseSolvedWrong();
0386 
0387         /* no, the user entered the wrong result */
0388         m_resultWidget->setResult(Ratio(), 0);
0389     } /* if (entered_result == result) */
0390 
0391     m_edit = false;
0392 
0393     return;
0394 }
0395 
0396 /** generate the next task and show it to the user */
0397 void ExerciseFactorize::nextTask()
0398 {
0399     // change the tooltip of the check button
0400     m_checkButton->setToolTip(i18n("Click on this button to check your result. The button will not work if you have not entered a result yet."));
0401 
0402     // enable prime factor buttons
0403     m_factor2Button->setEnabled(true);
0404     m_factor3Button->setEnabled(true);
0405     m_factor5Button->setEnabled(true);
0406     m_factor7Button->setEnabled(true);
0407     m_factor11Button->setEnabled(true);
0408     m_factor13Button->setEnabled(true);
0409     m_factor17Button->setEnabled(true);
0410     m_factor19Button->setEnabled(true);
0411     m_skipButton->setEnabled(true);
0412 
0413     // disable the factor removal button, there are no factors to be removed yet
0414     m_removeLastFactorButton->setEnabled(false);
0415 
0416     m_resultWidget->setResult(Ratio(), -1);
0417 
0418     /* clear user input */
0419     m_factorsEntered.clear();
0420     m_factorsResult.clear();
0421     m_factorsEnteredEdit->clear();
0422 
0423     m_factorsEnteredEdit->setFocus();
0424 
0425     /* create a new task */
0426     QApplication::setOverrideCursor(Qt::WaitCursor);  /* show the sand clock */
0427     createTask();
0428     QApplication::restoreOverrideCursor(); /* show the normal cursor */
0429 
0430     // update the task widget
0431     QString tmp_str;
0432     tmp_str.setNum(m_taskNumber);
0433     m_taskLabel->setText(tmp_str);
0434 
0435     m_edit = true;
0436 
0437     return;
0438 }
0439 
0440 void ExerciseFactorize::addFactor(uint factor)
0441 {
0442     // add the new entered factor
0443     m_factorsEntered.append(factor);
0444 
0445     // a factor was added, so the user can can remove one again
0446     m_removeLastFactorButton->setEnabled(true);
0447 
0448     // update the line edit
0449     updateEnteredEdit();
0450 
0451     return;
0452 }
0453 
0454 void ExerciseFactorize::updateEnteredEdit()
0455 {
0456     // the string to be shown in the entered edit
0457     QString str_output;
0458     QString str_tmp;
0459 
0460     // find the end of the list
0461     uintList::iterator it;
0462 
0463 
0464     for (it = m_factorsEntered.begin(); it != m_factorsEntered.end(); ++it) {
0465         // convert the factor into a string
0466         str_tmp.setNum(*it);
0467 
0468         // add the factor with a *
0469         if (it == m_factorsEntered.begin()) {
0470             str_output = str_tmp;
0471         } else {
0472             str_output += QStringLiteral(" x ") + str_tmp;
0473         }
0474     }
0475 
0476     // set the text into the line edit
0477     m_factorsEnteredEdit->setText(str_output);
0478 
0479     return;
0480 }
0481 
0482 /* ------ private slots ------ */
0483 
0484 void ExerciseFactorize::slotFactorsEditReturnPressed()
0485 {
0486     if (m_checkButton->isEnabled()) {
0487         slotCheckButtonClicked();
0488     }
0489 }
0490 
0491 void ExerciseFactorize::slotCheckButtonClicked()
0492 {
0493     if (m_currentState == _CHECK_TASK) {
0494         // if nothing has been entered by the user, we don't check the result yet
0495         if (m_factorsEntered.count() == 0)
0496             return;
0497         m_currentState = _NEXT_TASK;
0498         m_checkButton->setText(i18n("N&ext"));
0499         (void) showResult();
0500     } else {
0501         m_currentState = _CHECK_TASK;
0502         m_checkButton->setText(i18n("&Check"));
0503         (void) nextTask();
0504     }
0505 
0506     // update the line edit
0507     updateEnteredEdit();
0508     return;
0509 }
0510 
0511 void ExerciseFactorize::slotSkipButtonClicked()
0512 {
0513     forceNewTask();
0514     // update the line edit
0515     updateEnteredEdit();
0516 
0517     return;
0518 }
0519 
0520 void ExerciseFactorize::slotFactor2ButtonClicked()
0521 {
0522     addFactor(2);
0523 
0524     return;
0525 }
0526 
0527 void ExerciseFactorize::slotFactor3ButtonClicked()
0528 {
0529     addFactor(3);
0530 
0531     return;
0532 }
0533 
0534 void ExerciseFactorize::slotFactor5ButtonClicked()
0535 {
0536     addFactor(5);
0537 
0538     return;
0539 }
0540 
0541 void ExerciseFactorize::slotFactor7ButtonClicked()
0542 {
0543     addFactor(7);
0544 
0545     return;
0546 }
0547 
0548 void ExerciseFactorize::slotFactor11ButtonClicked()
0549 {
0550     addFactor(11);
0551 
0552     return;
0553 }
0554 
0555 void ExerciseFactorize::slotFactor13ButtonClicked()
0556 {
0557     addFactor(13);
0558 
0559     return;
0560 }
0561 
0562 void ExerciseFactorize::slotFactor17ButtonClicked()
0563 {
0564     addFactor(17);
0565 
0566     return;
0567 }
0568 
0569 void ExerciseFactorize::slotFactor19ButtonClicked()
0570 {
0571     addFactor(19);
0572 
0573     return;
0574 }
0575 
0576 void ExerciseFactorize::slotRemoveLastFactorButtonClicked()
0577 {
0578     if (m_factorsEntered.count() > 0) {
0579         // find the end of the list
0580         uintList::iterator it = m_factorsEntered.end();
0581         --it;
0582 
0583         // remove last item
0584         m_factorsEntered.erase(it);
0585     }
0586 
0587     // if the list is empty, we have to disable the delete button
0588     if (m_factorsEntered.count() == 0)
0589         m_removeLastFactorButton->setEnabled(false);
0590 
0591     // update the line edit
0592     updateEnteredEdit();
0593 
0594     return;
0595 }
0596 
0597 void ExerciseFactorize::showEvent(QShowEvent *)
0598 {
0599 #ifdef DEBUG
0600     qDebug() << QStringLiteral("ExerciseFactorize::showEvent()");
0601 #endif
0602 
0603     if (isVisible())
0604         m_factorsEnteredEdit->setFocus();
0605 }
0606 
0607 void ExerciseFactorize::editContentChanged(bool correct)
0608 {
0609     if (correct) {
0610         const QStringList factors = m_factorsEnteredEdit->getFactors();
0611 
0612         m_factorsEntered.clear();
0613         for (const QString & auxStr : factors) {
0614             m_factorsEntered.append(auxStr.toUInt());
0615         }
0616     }
0617     setButtonsEnabled(correct);
0618 }
0619 
0620 void ExerciseFactorize::setButtonsEnabled(bool enabled)
0621 {
0622     // set the state of the buttons involved in factorization
0623     m_checkButton->setEnabled(enabled);
0624     m_factor2Button->setEnabled(enabled);
0625     m_factor3Button->setEnabled(enabled);
0626     m_factor5Button->setEnabled(enabled);
0627     m_factor7Button->setEnabled(enabled);
0628     m_factor11Button->setEnabled(enabled);
0629     m_factor13Button->setEnabled(enabled);
0630     m_factor17Button->setEnabled(enabled);
0631     m_factor19Button->setEnabled(enabled);
0632     m_removeLastFactorButton->setEnabled(enabled);
0633 }
0634 
0635 #include "moc_ExerciseFactorize.cpp"