File indexing completed on 2022-12-06 18:52:32

0001 /*
0002     MainQtWidget.cpp  -  The main Qt/KDE window
0003     SPDX-FileCopyrightText: 2003-2004 Sebastian Stein <seb.kde@hpfsc.de>
0004     SPDX-FileCopyrightText: 2008 Tiago Porangaba <tiago.porangaba@ltia.fc.unesp.br>
0005     SPDX-FileCopyrightText: 2008 Tadeu Araujo <tadeu.araujo@ltia.fc.unesp.br>
0006     SPDX-FileCopyrightText: 2008 Danilo Balzaque <danilo.balzaque@ltia.fc.unesp.br>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #include "MainQtWidget.h"
0012 
0013 /* these includes are needed for KDE support */
0014 #include <KConfigDialog>
0015 #include <KLocalizedString>
0016 #include <KStandardShortcut>
0017 #include <KActionCollection>
0018 
0019 /* these includes are needed for Qt support */
0020 #include <QAction>
0021 #include <QCheckBox>
0022 #include <QComboBox>
0023 #include <QFontDatabase>
0024 #include <QFrame>
0025 #include <QIcon>
0026 #include <QLabel>
0027 #include <QSplitter>
0028 #include <QPushButton>
0029 #include <QToolButton>
0030 #include <QWidget>
0031 #include <QWidgetAction>
0032 
0033 #ifdef DEBUG
0034 #include <QDebug>
0035 #endif
0036 
0037 #include <cmath>
0038 
0039 #include "ExerciseCompare.h"
0040 #include "ExerciseConvert.h"
0041 #include "ExerciseFactorize.h"
0042 #include "ExercisePercentage.h"
0043 #include "ExerciseMixedNumbers.h"
0044 #include "TaskView.h"
0045 #include "ui_taskfontsbase.h"
0046 #include "StatisticsView.h"
0047 #include "AppMenuWidget.h"
0048 #include "TaskColors.h"
0049 
0050 #include "settingsclass.h"
0051 #include <QStandardPaths>
0052 
0053 class TaskFonts : public QWidget, public Ui::TaskFontsBase
0054 {
0055 public:
0056     TaskFonts(QWidget * parent) : QWidget(parent) {
0057         setupUi(this);
0058     }
0059 };
0060 
0061 /* ------ public member functions ------ */
0062 
0063 MainQtWidget::MainQtWidget()
0064 {
0065 #ifdef DEBUG
0066     qDebug() << QStringLiteral("constructor MainQtWidget");
0067 #endif
0068 
0069     // get the settings
0070     readOptions();
0071 
0072     // creating KActions, used by the kbruchui.rc file
0073     setupActions();
0074 
0075     setCaption(i18n("Exercise"));
0076 
0077     // Create layout
0078     QGridLayout * layoutExercises = new QGridLayout();
0079     layoutExercises->setObjectName(QStringLiteral("layoutExercises"));
0080     layoutExercises->setRowStretch(2, 1);
0081     QGridLayout * layoutOptions = new QGridLayout();
0082     layoutOptions->setObjectName(QStringLiteral("layoutOptions"));
0083     layoutOptions->setRowStretch(0, 1);
0084     layoutOptions->setRowStretch(6, 1);
0085     QGridLayout * layoutQuestion = new QGridLayout();
0086     layoutQuestion->setObjectName(QStringLiteral("layoutQuestion"));
0087     layoutQuestion->setColumnMinimumWidth(0, 110);
0088     layoutQuestion->setColumnStretch(1, 1);
0089     QGridLayout * layoutAnswer = new QGridLayout();
0090     layoutAnswer->setObjectName(QStringLiteral("layoutAnswer"));
0091     layoutAnswer->setColumnMinimumWidth(0, 110);
0092     layoutAnswer->setColumnStretch(1, 1);
0093     QGridLayout * layoutOperations = new QGridLayout();
0094     layoutOperations->setObjectName(QStringLiteral("layoutOperations"));
0095     layoutOperations->setColumnMinimumWidth(0, 110);
0096     layoutOperations->setColumnStretch(1, 1);
0097 
0098     QSplitter* splitter = new QSplitter(Qt::Horizontal, this);
0099     splitter->setObjectName(QStringLiteral("QSplitter"));
0100     setCentralWidget(splitter);
0101 
0102     QWidget * pageExercises = new QWidget();
0103     QWidget * pageOptions = new QWidget();
0104 
0105     // Create visible components
0106     m_QuestionGroup = new QGroupBox(i18n("Question:"), pageOptions);
0107     m_AnswerGroup = new QGroupBox(i18n("Answer:"), pageOptions);
0108     m_OperationsGroup = new QGroupBox(i18n("Operations:"), pageOptions);
0109 
0110     defaultFont = SettingsClass::taskFont();
0111     defaultFont.setBold(true);
0112     defaultFont.setPointSize(14);
0113 
0114     m_TitleLabel = new QLabel(i18n("Arithmetic"), pageExercises);
0115     m_TitleLabel->setAlignment(Qt::AlignLeft);
0116     m_TitleLabel->setFont(defaultFont);
0117     m_TitleLabel->setFixedHeight(35);
0118     m_TitleLabel->setAlignment(Qt::AlignVCenter);
0119 
0120     m_statview = new StatisticsView;
0121     m_statview->setObjectName(QStringLiteral("StatisticsView"));
0122     m_statview->setFixedHeight(120);
0123 
0124     m_footerline = new QFrame(pageExercises);
0125     m_footerline->setGeometry(QRect(pageExercises->width(), 100, 20, 20));
0126     m_footerline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
0127 
0128     m_headerline = new QFrame(pageExercises);
0129     m_headerline->setGeometry(QRect(pageExercises->width(), 100, 20, 20));
0130     m_headerline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
0131 
0132     m_taskview = new TaskView(pageExercises, m_addAdd, m_addDiv, m_addMult, m_addSub, m_nrRatios, m_maxMainDenominator);
0133     m_taskview->setObjectName(QStringLiteral("TaskView"));
0134     m_taskview->hide();
0135 
0136     m_exerciseCompare = new ExerciseCompare(pageExercises);
0137     m_exerciseCompare->setObjectName(QStringLiteral("ExerciseCompare"));
0138     m_exerciseCompare->hide();
0139 
0140     m_exerciseConvert = new ExerciseConvert(pageExercises);
0141     m_exerciseConvert->setObjectName(QStringLiteral("ExerciseConvert"));
0142     m_exerciseConvert->hide();
0143 
0144     m_exerciseMixedNumbers = new ExerciseMixedNumbers(pageExercises);
0145     m_exerciseMixedNumbers->setObjectName(QStringLiteral("ExerciseMixedNumbers"));
0146     m_exerciseMixedNumbers->hide();
0147 
0148     m_exerciseFactorize = new ExerciseFactorize(pageExercises);
0149     m_exerciseFactorize->setObjectName(QStringLiteral("ExerciseFactorize"));
0150     m_exerciseFactorize->hide();
0151 
0152     m_exercisePercentage = new ExercisePercentage(pageExercises);
0153     m_exercisePercentage->setObjectName(QStringLiteral("ExercisePercentage"));
0154     m_exercisePercentage->hide();
0155 
0156     m_OptionsLabel = new QLabel(i18n("Options:"), pageOptions);
0157     m_OptionsLabel->setToolTip(i18n("Set the options to solve the exercises."));
0158     m_OptionsLabel->setWhatsThis(i18n("This part of the window shows the options to solve the exercises. Use the handle between the options and main window to change the size of this window part or to hide it by moving the handle to the left border of the main window."));
0159     m_OptionsLabel->setObjectName(QStringLiteral("OptionsLabel"));
0160     m_OptionsLabel->setFont(defaultFont);
0161 
0162     m_QuestionMixedLabel = new QLabel(i18n("Mixed number:"), pageOptions);
0163     m_QuestionMixedLabel->setToolTip(i18n("Set if the fractions will appear as mixed numbers or not in the question expression (mixed number example: 1 4/5 = 9/5 )."));
0164     m_QuestionMixedLabel->setObjectName(QStringLiteral("QuestionMixedLabel"));
0165     m_QuestionMixedLabel->setAlignment(Qt::AlignRight);
0166 
0167     m_QuestionMixedCheck = new QCheckBox(pageOptions);
0168     m_QuestionMixedCheck->setObjectName(QStringLiteral("QuestionMixedCheck"));
0169     m_QuestionMixedCheck->setChecked(m_questionMixed);
0170     m_taskview->setQuestionMixed(m_questionMixed);
0171     QObject::connect(m_QuestionMixedCheck, &QCheckBox::stateChanged, this, &MainQtWidget::QuestionMixedCheckSlot);
0172 
0173     m_AnswerMixedLabel = new QLabel(i18n("Mixed number:"), pageOptions);
0174     m_AnswerMixedLabel->setToolTip(i18n("Set if the fractions will appear as mixed numbers or not in the answer (mixed number example: 1 4/5 = 9/5 )."));
0175     m_AnswerMixedLabel->setObjectName(QStringLiteral("AnswerMixedLabel"));
0176     m_AnswerMixedLabel->setAlignment(Qt::AlignRight);
0177 
0178     m_AnswerMixedCheck = new QRadioButton(pageOptions);
0179     m_AnswerMixedCheck->setObjectName(QStringLiteral("AnswerMixedCheck"));
0180     m_AnswerMixedCheck->setChecked(m_answerMixed);
0181     m_taskview->setAnswerMixed(m_answerMixed);
0182     QObject::connect(m_AnswerMixedCheck, &QRadioButton::toggled, this, &MainQtWidget::AnswerMixedCheckSlot);
0183 
0184     m_AdditionLabel = new QLabel(i18n("Addition:"), pageOptions);
0185     m_AdditionLabel->setToolTip(i18n("Check this to use addition operator."));
0186     m_AdditionLabel->setObjectName(QStringLiteral("AdditionLabel"));
0187     m_AdditionLabel->setAlignment(Qt::AlignRight);
0188 
0189     m_AdditionCheck = new QCheckBox(pageOptions);
0190     m_AdditionCheck->setObjectName(QStringLiteral("AdditionCheck"));
0191     m_AdditionCheck->setChecked(m_addAdd);
0192     QObject::connect(m_AdditionCheck, &QCheckBox::stateChanged, this, &MainQtWidget::AdditionCheckSlot);
0193 
0194     m_SubtractionLabel = new QLabel(i18n("Subtraction:"), pageOptions);
0195     m_SubtractionLabel->setToolTip(i18n("Check this to use subtraction operator."));
0196     m_SubtractionLabel->setObjectName(QStringLiteral("SubtractionLabel"));
0197     m_SubtractionLabel->setAlignment(Qt::AlignRight);
0198 
0199     m_SubtractionCheck = new QCheckBox(pageOptions);
0200     m_SubtractionCheck->setObjectName(QStringLiteral("SubtractionCheck"));
0201     m_SubtractionCheck->setChecked(m_addSub);
0202     QObject::connect(m_SubtractionCheck, &QCheckBox::stateChanged, this, &MainQtWidget::SubtractionCheckSlot);
0203 
0204     m_MultiplicationLabel = new QLabel(i18n("Multiplication:"), pageOptions);
0205     m_MultiplicationLabel->setToolTip(i18n("Check this to use multiplication operator."));
0206     m_MultiplicationLabel->setObjectName(QStringLiteral("MultiplicationLabel"));
0207     m_MultiplicationLabel->setAlignment(Qt::AlignRight);
0208 
0209     m_MultiplicationCheck = new QCheckBox(pageOptions);
0210     m_MultiplicationCheck->setObjectName(QStringLiteral("MultiplicationCheck"));
0211     m_MultiplicationCheck->setChecked(m_addMult);
0212     QObject::connect(m_MultiplicationCheck, &QCheckBox::stateChanged, this, &MainQtWidget::MultiplicationCheckSlot);
0213 
0214     m_DivisionLabel = new QLabel(i18n("Division:"), pageOptions);
0215     m_DivisionLabel->setToolTip(i18n("Check this to use division operator."));
0216     m_DivisionLabel->setObjectName(QStringLiteral("DivisionLabel"));
0217     m_DivisionLabel->setAlignment(Qt::AlignRight);
0218 
0219     m_DivisionCheck = new QCheckBox(pageOptions);
0220     m_DivisionCheck->setObjectName(QStringLiteral("DivisionCheck"));
0221     m_DivisionCheck->setChecked(m_addDiv);
0222     QObject::connect(m_DivisionCheck, &QCheckBox::stateChanged, this, &MainQtWidget::DivisionCheckSlot);
0223 
0224     m_ReducedLabel = new QLabel(i18n("Reduced form:"), pageOptions);
0225     m_ReducedLabel->setToolTip(i18n("Check this to force the use of the reduced form."));
0226     m_ReducedLabel->setObjectName(QStringLiteral("ReducedLabel"));
0227     m_ReducedLabel->setAlignment(Qt::AlignRight);
0228 
0229     m_ReducedCheck = new QRadioButton(pageOptions);
0230     m_ReducedCheck->setObjectName(QStringLiteral("ReducedCheck"));
0231     m_ReducedCheck->setChecked(m_reducedForm);
0232     m_taskview->setReducedForm(m_reducedForm);
0233     QObject::connect(m_ReducedCheck, &QRadioButton::toggled, this, &MainQtWidget::ReducedFormCheckSlot);
0234 
0235     m_NrOfTermsLabel = new QLabel(i18n("Number of terms:"), pageOptions);
0236     m_NrOfTermsLabel->setToolTip(i18n("The number of \nterms you want"));
0237     m_NrOfTermsLabel->setObjectName(QStringLiteral("NrOfTermsLabel"));
0238     m_NrOfTermsLabel->setAlignment(Qt::AlignRight);
0239 
0240     m_NrOfTermsBox = new QComboBox(pageOptions);
0241     m_NrOfTermsBox->addItem(QStringLiteral("2"));
0242     m_NrOfTermsBox->addItem(QStringLiteral("3"));
0243     m_NrOfTermsBox->addItem(QStringLiteral("4"));
0244     m_NrOfTermsBox->addItem(QStringLiteral("5"));
0245     m_NrOfTermsBox->setCurrentIndex(m_nrRatios - 2);
0246     m_NrOfTermsBox->setToolTip(i18n("The number of \nterms you want"));
0247     m_NrOfTermsBox->setWhatsThis(i18n("Choose the number of terms (2, 3, 4 or 5) you \nwant for calculating fractions."));
0248     QObject::connect(m_NrOfTermsBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &MainQtWidget::NrOfTermsBoxSlot);
0249 
0250     m_MaxMainDenominatorLabel = new QLabel(i18n("Maximum denominator:"), pageOptions);
0251     m_MaxMainDenominatorLabel->setObjectName(QStringLiteral("MaxMainDenominatorLabel"));
0252     m_MaxMainDenominatorLabel->setAlignment(Qt::AlignRight);
0253     m_MaxMainDenominatorLabel->setWordWrap(true);
0254 
0255     m_MaxMainDenominatorBox = new QComboBox(pageOptions);
0256     m_MaxMainDenominatorBox->addItem(QStringLiteral("10"));
0257     m_MaxMainDenominatorBox->addItem(QStringLiteral("20"));
0258     m_MaxMainDenominatorBox->addItem(QStringLiteral("30"));
0259     m_MaxMainDenominatorBox->addItem(QStringLiteral("50"));
0260     m_MaxMainDenominatorBox->setToolTip(i18n("The maximum number you can have as main denominator"));
0261     m_MaxMainDenominatorBox->setWhatsThis(i18n("Choose the number which will be the maximum for the main denominator: 10, 20, 30, 40 or 50."));
0262     switch (m_maxMainDenominator) {
0263     case 10 :
0264         m_MaxMainDenominatorBox->setCurrentIndex(0);
0265         break;
0266     case 20 :
0267         m_MaxMainDenominatorBox->setCurrentIndex(1);
0268         break;
0269     case 30 :
0270         m_MaxMainDenominatorBox->setCurrentIndex(2);
0271         break;
0272     case 50 :
0273         m_MaxMainDenominatorBox->setCurrentIndex(3);
0274         break;
0275     }
0276     QObject::connect(m_MaxMainDenominatorBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &MainQtWidget::MaxMainDenominatorBoxSlot);
0277 
0278 
0279     layoutExercises->addWidget(m_TitleLabel, 0, 0);
0280     layoutExercises->addWidget(m_headerline, 1, 0);
0281     layoutExercises->addWidget(m_taskview, 2, 0);
0282     layoutExercises->addWidget(m_exerciseCompare, 2, 0);
0283     layoutExercises->addWidget(m_exerciseConvert, 2, 0);
0284     layoutExercises->addWidget(m_exerciseMixedNumbers, 2, 0);
0285     layoutExercises->addWidget(m_exerciseFactorize, 2, 0);
0286     layoutExercises->addWidget(m_exercisePercentage, 2, 0);
0287     layoutExercises->addWidget(m_footerline, 3, 0);
0288     layoutExercises->addWidget(m_statview, 4, 0);
0289 
0290     layoutOptions->addWidget(m_OptionsLabel, 1, 0);
0291     layoutOptions->addWidget(m_QuestionGroup, 2, 0);
0292     layoutOptions->addWidget(m_AnswerGroup, 3, 0);
0293     layoutOptions->addWidget(m_OperationsGroup, 5, 0);
0294 
0295     layoutQuestion->addWidget(m_QuestionMixedLabel, 0, 0);
0296     layoutQuestion->addWidget(m_QuestionMixedCheck, 0, 1);
0297     layoutQuestion->addWidget(m_NrOfTermsLabel, 1, 0);
0298     layoutQuestion->addWidget(m_NrOfTermsBox, 1, 1);
0299     layoutQuestion->addWidget(m_MaxMainDenominatorLabel, 2, 0);
0300     layoutQuestion->addWidget(m_MaxMainDenominatorBox, 2, 1);
0301 
0302     layoutAnswer->addWidget(m_AnswerMixedLabel, 0, 0);
0303     layoutAnswer->addWidget(m_AnswerMixedCheck, 0, 1);
0304     layoutAnswer->addWidget(m_ReducedLabel, 1, 0);
0305     layoutAnswer->addWidget(m_ReducedCheck, 1, 1);
0306 
0307     layoutOperations->addWidget(m_AdditionLabel, 0, 0);
0308     layoutOperations->addWidget(m_AdditionCheck, 0, 1);
0309     layoutOperations->addWidget(m_SubtractionLabel, 1, 0);
0310     layoutOperations->addWidget(m_SubtractionCheck, 1, 1);
0311     layoutOperations->addWidget(m_MultiplicationLabel, 2, 0);
0312     layoutOperations->addWidget(m_MultiplicationCheck, 2, 1);
0313     layoutOperations->addWidget(m_DivisionLabel, 3, 0);
0314     layoutOperations->addWidget(m_DivisionCheck, 3, 1);
0315 
0316     m_QuestionGroup->setLayout(layoutQuestion);
0317     m_AnswerGroup->setLayout(layoutAnswer);
0318     m_OperationsGroup->setLayout(layoutOperations);
0319 
0320     // set layouts to both parts
0321     pageOptions->setLayout(layoutOptions);
0322     pageExercises->setLayout(layoutExercises);
0323 
0324     // preventing resizing of left sidebar
0325     pageOptions->setFixedWidth(pageOptions->sizeHint().width());
0326 
0327     // add left and right part to the splitter
0328     splitter->addWidget(pageOptions);
0329     splitter->addWidget(pageExercises);
0330 
0331     // connect signals of the exercises and StatisticView, so that StatisticView
0332     // gets informed about how the user solved a given task (wrong or correct)
0333     QObject::connect(m_taskview, &TaskView::signalTaskSolvedCorrect, m_statview, &StatisticsView::addCorrect);
0334     QObject::connect(m_taskview, &TaskView::signalTaskSkipped, m_statview, &StatisticsView::addSkipped);
0335     QObject::connect(m_taskview, &TaskView::signalTaskSolvedWrong, m_statview, &StatisticsView::addWrong);
0336     QObject::connect(m_exerciseCompare, &ExerciseCompare::signalExerciseSolvedCorrect, m_statview, &StatisticsView::addCorrect);
0337     QObject::connect(m_exerciseCompare, &ExerciseCompare::signalExerciseSkipped, m_statview, &StatisticsView::addSkipped);
0338     QObject::connect(m_exerciseCompare, &ExerciseCompare::signalExerciseSolvedWrong, m_statview, &StatisticsView::addWrong);
0339     QObject::connect(m_exerciseConvert, &ExerciseConvert::signalExerciseSolvedCorrect, m_statview, &StatisticsView::addCorrect);
0340     QObject::connect(m_exerciseConvert, &ExerciseConvert::signalExerciseSkipped, m_statview, &StatisticsView::addSkipped);
0341     QObject::connect(m_exerciseConvert, &ExerciseConvert::signalExerciseSolvedWrong, m_statview, &StatisticsView::addWrong);
0342     QObject::connect(m_exerciseMixedNumbers, &ExerciseMixedNumbers::signalExerciseSolvedCorrect, m_statview, &StatisticsView::addCorrect);
0343     QObject::connect(m_exerciseMixedNumbers, &ExerciseMixedNumbers::signalExerciseSkipped, m_statview, &StatisticsView::addSkipped);
0344     QObject::connect(m_exerciseMixedNumbers, &ExerciseMixedNumbers::signalExerciseSolvedWrong, m_statview, &StatisticsView::addWrong);
0345     QObject::connect(m_exerciseFactorize, &ExerciseFactorize::signalExerciseSolvedCorrect, m_statview, &StatisticsView::addCorrect);
0346     QObject::connect(m_exerciseFactorize, &ExerciseFactorize::signalExerciseSkipped, m_statview, &StatisticsView::addSkipped);
0347     QObject::connect(m_exerciseFactorize, &ExerciseFactorize::signalExerciseSolvedWrong, m_statview, &StatisticsView::addWrong);
0348     QObject::connect(m_exercisePercentage, &ExercisePercentage::signalExerciseSolvedCorrect, m_statview, &StatisticsView::addCorrect);
0349     QObject::connect(m_exercisePercentage, &ExercisePercentage::signalExerciseSkipped, m_statview, &StatisticsView::addSkipped);
0350     QObject::connect(m_exercisePercentage, &ExercisePercentage::signalExerciseSolvedWrong, m_statview, &StatisticsView::addWrong);
0351 
0352     // Get and set the page of last exercise
0353     selectedTask = (ExerciseType) SettingsClass::activeExercise();
0354     switch (selectedTask) {
0355     case Arithmetic:
0356         SelectArithmetic();
0357         break;
0358     case Comparison:
0359         SelectComparison();
0360         break;
0361     case Conversion:
0362         SelectConversion();
0363         break;
0364     case Factorization:
0365         SelectFactorization();
0366         break;
0367     case Percentage:
0368         SelectPercentage();
0369         break;
0370     default:
0371         SelectArithmetic();
0372         break;
0373     }
0374     move(50, 50);
0375     qDebug() << " MainQtWidget::MainQtWidget()"<<this;
0376 }
0377 
0378 MainQtWidget::~MainQtWidget()
0379 {
0380     qDebug() << " MainQtWidget::~MainQtWidget()"<<this;
0381 }
0382 
0383 QFont MainQtWidget::DefaultFont()
0384 {
0385     QFont defaultFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
0386     defaultFont.setPointSize(24);
0387     defaultFont.setBold(true);
0388     return defaultFont;
0389 }
0390 
0391 /* ------ private member functions ------ */
0392 
0393 void MainQtWidget::readOptions()
0394 {
0395 #ifdef DEBUG
0396     qDebug() << QStringLiteral("readOptions MainQtWidget");
0397 #endif
0398 
0399     m_addSub = SettingsClass::addsub();
0400     m_addAdd = SettingsClass::addadd();
0401     m_addDiv = SettingsClass::adddiv();
0402     m_addMult = SettingsClass::addmult();
0403 
0404     m_nrRatios = SettingsClass::number_ratios();
0405     m_maxMainDenominator = SettingsClass::max_main_denominator();
0406 
0407     m_reducedForm = SettingsClass::reduceForm();
0408     m_answerMixed = SettingsClass::answerMixed();
0409     m_questionMixed = SettingsClass::questionMixed();
0410 
0411     /* make sure that we can load config files with corrupted values */
0412     if ((m_addMult == true && m_addDiv == true) && pow(2.0, (double) m_nrRatios) > m_maxMainDenominator) {
0413         m_nrRatios = 2;
0414         m_maxMainDenominator = 10;
0415     }
0416 }
0417 
0418 void MainQtWidget::writeOptions()
0419 {
0420     SettingsClass::setActiveExercise(selectedTask);
0421 
0422     // save settings for exercise solve task with fractions
0423     SettingsClass::setAddsub(m_addSub);
0424     SettingsClass::setAddadd(m_addAdd);
0425     SettingsClass::setAdddiv(m_addDiv);
0426     SettingsClass::setAddmult(m_addMult);
0427     SettingsClass::setNumber_ratios(m_nrRatios);
0428     SettingsClass::setMax_main_denominator(m_maxMainDenominator);
0429     SettingsClass::setReduceForm(m_reducedForm);
0430     SettingsClass::setAnswerMixed(m_answerMixed);
0431     SettingsClass::setQuestionMixed(m_questionMixed);
0432     SettingsClass::self()->save();
0433 }
0434 
0435 void MainQtWidget::setupActions()
0436 {
0437 #ifdef DEBUG
0438     qDebug() << QStringLiteral("setupActions MainQtWidget");
0439 #endif
0440 
0441     QString css =
0442         QStringLiteral("QToolButton {"
0443         "background-position: top center;"
0444         "background-repeat: none;"
0445         "}"
0446         "QToolButton#ArithmeticButton {"
0447         "background-image: url(") +
0448         QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kbruch/pics/exercise_arithmetics.png")) +
0449         QStringLiteral(");"
0450         "}"
0451         "QToolButton#ComparisonButton {"
0452         "background-image: url(") +
0453         QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kbruch/pics/exercise_compare.png")) +
0454         QStringLiteral(");"
0455         "}"
0456         "QToolButton#ConversionButton {"
0457         "background-image: url(") +
0458         QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kbruch/pics/exercise_conversion.png")) +
0459         QStringLiteral(");"
0460         "}"
0461         "QToolButton#MixedNumbersButton {"
0462         "background-image: url(") +
0463         QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kbruch/pics/exercise_mixed.png")) +
0464         QStringLiteral(");"
0465         "}"
0466         "QToolButton#Factorization {"
0467         "background-image: url(") +
0468         QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kbruch/pics/exercise_factorization.png")) +
0469         QStringLiteral(");"
0470         "}"
0471         "QToolButton#Percentage {"
0472         "background-image: url(") +
0473         QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kbruch/pics/exercise_percentage.png")) +
0474         QStringLiteral(");"
0475         "}");
0476 
0477     setStyleSheet(css);
0478 
0479     m_NewTaskButton = new QToolButton(this);
0480     m_NewTaskButton->setObjectName(QStringLiteral("NewTaskButton"));
0481     m_NewTaskButton->setText(i18n("New"));
0482     m_NewTaskButton->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
0483     m_NewTaskButton->setToolTip(i18n("Reset statistics and set a new task."));
0484     m_NewTaskButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0485 
0486     m_BackTaskButton = new QToolButton(this);
0487     m_BackTaskButton->setObjectName(QStringLiteral("BackTaskButton"));
0488     m_BackTaskButton->setText(i18n("Back"));
0489     m_BackTaskButton->setIcon(QIcon::fromTheme(QStringLiteral("go-previous")));
0490     m_BackTaskButton->setToolTip(i18n("Go back to Modes screen."));
0491     m_BackTaskButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0492 
0493     m_ArithmeticButton = new QToolButton(this);
0494     m_ArithmeticButton->setObjectName(QStringLiteral("ArithmeticButton"));
0495     m_ArithmeticButton->setText(i18n("\n\nArithmetic"));
0496     m_ArithmeticButton->setToolTip(i18n("In this exercise you have to solve a given question with fractions."));
0497     m_ArithmeticButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0498 
0499     m_ComparisonButton = new QToolButton(this);
0500     m_ComparisonButton->setObjectName(QStringLiteral("ComparisonButton"));
0501     m_ComparisonButton->setText(i18n("\n\nComparison"));
0502     m_ComparisonButton->setToolTip(i18n("In this exercise you have to compare two given fractions."));
0503     m_ComparisonButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0504 
0505     m_ConversionButton = new QToolButton(this);
0506     m_ConversionButton->setObjectName(QStringLiteral("ConversionButton"));
0507     m_ConversionButton->setText(i18n("\n\nConversion"));
0508     m_ConversionButton->setToolTip(i18n("In this exercise you have to convert a number into a fraction."));
0509     m_ConversionButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0510 
0511     m_MixedNumbersButton = new QToolButton(this);
0512     m_MixedNumbersButton->setObjectName(QStringLiteral("MixedNumbersButton"));
0513     m_MixedNumbersButton->setText(i18n("\n\nMixed Numbers"));
0514     m_MixedNumbersButton->setToolTip(i18n("In this exercise you have to convert a mixed number into a ratio and vice versa."));
0515     m_MixedNumbersButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0516 
0517     m_FactorizationButton = new QToolButton(this);
0518     m_FactorizationButton->setObjectName(QStringLiteral("Factorization"));
0519     m_FactorizationButton->setText(i18n("\n\nFactorization"));
0520     m_FactorizationButton->setToolTip(i18n("In this exercise you have to factorize a given number."));
0521     m_FactorizationButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0522 
0523     m_PercentageButton = new QToolButton(this);
0524     m_PercentageButton->setObjectName(QStringLiteral("Percentage"));
0525     m_PercentageButton->setText(i18n("\n\nPercentage"));
0526     m_PercentageButton->setToolTip(i18n("In this exercise you have to work with percentage questions."));
0527     m_PercentageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0528 
0529 
0530     m_NewTaskActionMenu  = new QWidgetAction(this);
0531     m_NewTaskActionMenu->setText(i18nc("@action opens a new question", "&New"));
0532     m_NewTaskActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
0533     actionCollection()->addAction(QStringLiteral("NewTaskMenu"), m_NewTaskActionMenu);
0534     actionCollection()->setDefaultShortcuts(m_NewTaskActionMenu, KStandardShortcut::shortcut(KStandardShortcut::New));
0535     connect(m_NewTaskActionMenu, &QAction::triggered, this, &MainQtWidget::newTask);
0536 
0537     m_NewTaskActionTool  = new QWidgetAction(this);
0538     m_NewTaskActionTool->setText(i18nc("@action opens a new question", "New"));
0539     m_NewTaskActionTool->setDefaultWidget(m_NewTaskButton);
0540     actionCollection()->addAction(QStringLiteral("NewTaskTool"), m_NewTaskActionTool);
0541     connect(m_NewTaskButton, &QToolButton::clicked, this, &MainQtWidget::newTask);
0542 
0543     m_BackActionMenu  = new QWidgetAction(this);
0544     m_BackActionMenu->setText(i18nc("@action go to the main screen", "&Back"));
0545     m_BackActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("go-previous")));
0546     actionCollection()->addAction(QStringLiteral("BackMenu"), m_BackActionMenu);
0547     actionCollection()->setDefaultShortcuts(m_BackActionMenu, KStandardShortcut::shortcut(KStandardShortcut::Back));
0548     connect(m_BackActionMenu, &QAction::triggered, this, &MainQtWidget::goBack);
0549 
0550     m_BackActionTool  = new QWidgetAction(this);
0551     m_BackActionTool->setText(i18nc("@action go to the main screen", "Back"));
0552     m_BackActionTool->setDefaultWidget(m_BackTaskButton);
0553     actionCollection()->addAction(QStringLiteral("BackTool"), m_BackActionTool);
0554     connect(m_BackTaskButton, &QToolButton::clicked, this, &MainQtWidget::goBack);
0555 
0556     m_ArithmeticAction  = new QWidgetAction(this);
0557     m_ArithmeticAction->setText(i18nc("Arithmetic Exercise", "Arithmetic"));
0558     m_ArithmeticAction->setDefaultWidget(m_ArithmeticButton);
0559     actionCollection()->addAction(QStringLiteral("Arithmetic"), m_ArithmeticAction);
0560     connect(m_ArithmeticButton, &QToolButton::clicked, this, &MainQtWidget::SelectArithmetic);
0561 
0562     m_ComparisonAction  = new QWidgetAction(this);
0563     m_ComparisonAction->setText(i18nc("Comparison Exercise", "Comparison"));
0564     m_ComparisonAction->setDefaultWidget(m_ComparisonButton);
0565     actionCollection()->addAction(QStringLiteral("Comparison"), m_ComparisonAction);
0566     connect(m_ComparisonButton, &QToolButton::clicked, this, &MainQtWidget::SelectComparison);
0567 
0568     m_ConversionAction  = new QWidgetAction(this);
0569     m_ConversionAction->setText(i18nc("Conversion Exercise", "Conversion"));
0570     m_ConversionAction->setDefaultWidget(m_ConversionButton);
0571     actionCollection()->addAction(QStringLiteral("Conversion"), m_ConversionAction);
0572     connect(m_ConversionButton, &QToolButton::clicked, this, &MainQtWidget::SelectConversion);
0573 
0574     m_MixedNumbersAction  = new QWidgetAction(this);
0575     m_MixedNumbersAction->setText(i18nc("Mixed Numbers Exercise", "MixedNumbers"));
0576     m_MixedNumbersAction->setDefaultWidget(m_MixedNumbersButton);
0577     actionCollection()->addAction(QStringLiteral("MixedNumbers"), m_MixedNumbersAction);
0578     connect(m_MixedNumbersButton, &QToolButton::clicked, this, &MainQtWidget::SelectMixedNumbers);
0579 
0580     m_FactorizationAction  = new QWidgetAction(this);
0581     m_MixedNumbersAction->setText(i18nc("Factorization Exercise", "Factorization"));
0582     m_FactorizationAction->setDefaultWidget(m_FactorizationButton);
0583     actionCollection()->addAction(QStringLiteral("Factorization"), m_FactorizationAction);
0584     connect(m_FactorizationButton, &QToolButton::clicked, this, &MainQtWidget::SelectFactorization);
0585 
0586     m_PercentageAction  = new QWidgetAction(this);
0587     m_PercentageAction->setText(i18nc("Percentage Exercise", "Percentage"));
0588     m_PercentageAction->setDefaultWidget(m_PercentageButton);
0589     actionCollection()->addAction(QStringLiteral("Percentage"), m_PercentageAction);
0590     connect(m_PercentageButton, &QToolButton::clicked, this, &MainQtWidget::SelectPercentage);
0591 
0592     // quit action
0593     KStandardAction::quit(this, SLOT(close()), actionCollection());
0594 
0595     KStandardAction::preferences(this,  SLOT(slotPrefs()), actionCollection());
0596 
0597     resize(QSize(742, 520).expandedTo(minimumSizeHint()));
0598 
0599     setupGUI(ToolBar | Keys | Create);
0600     setAutoSaveSettings();
0601 }
0602 
0603 
0604 /* ------ private slots ------ */
0605 
0606 void MainQtWidget::newTask()
0607 {
0608 #ifdef DEBUG
0609     qDebug() << QStringLiteral("NewTask MainQtWidget");
0610 #endif
0611     // check which page should generate a new task
0612     switch (selectedTask) {
0613     case Arithmetic:
0614         m_taskview->forceNewTask();
0615         break;
0616     case Comparison:
0617         m_exerciseCompare->forceNewTask();
0618         break;
0619     case Conversion:
0620         m_exerciseConvert->forceNewTask();
0621         break;
0622     case MixedNumbers:
0623         m_exerciseMixedNumbers->forceNewTask();
0624         break;
0625     case Factorization:
0626         m_exerciseFactorize->forceNewTask();
0627         break;
0628     case Percentage:
0629         m_exercisePercentage->forceNewTask();
0630         break;
0631     }
0632     m_statview->resetStatistics();
0633     return;
0634 }
0635 
0636 void MainQtWidget::NrOfTermsBoxSlot()
0637 {
0638 #ifdef DEBUG
0639     qDebug() << QStringLiteral("MainQtWidget::NrOfTermsBoxSlot()");
0640 #endif
0641     int currentMaxDenom = m_MaxMainDenominatorBox->currentText().toInt();
0642     QString curr_nr = m_NrOfTermsBox->currentText();
0643     m_MaxMainDenominatorBox->clear();
0644 
0645     if (m_addDiv == true || m_addMult == true) {
0646         if (curr_nr == QStringLiteral("2")) {
0647             m_MaxMainDenominatorBox->addItem(QStringLiteral("10"));
0648             m_MaxMainDenominatorBox->addItem(QStringLiteral("20"));
0649             m_MaxMainDenominatorBox->addItem(QStringLiteral("30"));
0650             m_MaxMainDenominatorBox->addItem(QStringLiteral("50"));
0651         } else if (curr_nr == QStringLiteral("3")) {
0652             m_MaxMainDenominatorBox->addItem(QStringLiteral("20"));
0653             m_MaxMainDenominatorBox->addItem(QStringLiteral("30"));
0654             m_MaxMainDenominatorBox->addItem(QStringLiteral("50"));
0655         } else if (curr_nr == QStringLiteral("4")) {
0656             m_MaxMainDenominatorBox->addItem(QStringLiteral("20"));
0657             m_MaxMainDenominatorBox->addItem(QStringLiteral("30"));
0658             m_MaxMainDenominatorBox->addItem(QStringLiteral("50"));
0659         } else {
0660             m_MaxMainDenominatorBox->addItem(QStringLiteral("50"));
0661         }
0662         m_nrRatios = curr_nr.toInt();
0663         int index = m_MaxMainDenominatorBox->findText(QString::number(currentMaxDenom));
0664         m_MaxMainDenominatorBox->setCurrentIndex(index > -1 ? index : 0);
0665         m_maxMainDenominator = m_MaxMainDenominatorBox->currentText().toInt();
0666     } else {
0667         /* no multiplication or division allowed, so we add the default values */
0668         m_MaxMainDenominatorBox->addItem(QStringLiteral("10"));
0669         m_MaxMainDenominatorBox->addItem(QStringLiteral("20"));
0670         m_MaxMainDenominatorBox->addItem(QStringLiteral("30"));
0671         m_MaxMainDenominatorBox->addItem(QStringLiteral("50"));
0672         int index = m_MaxMainDenominatorBox->findText(QString::number(currentMaxDenom));
0673         m_MaxMainDenominatorBox->setCurrentIndex(index > -1 ? index : 0);
0674         m_nrRatios = curr_nr.toInt();
0675     }
0676 
0677     // set the new task parameters
0678     (void) m_taskview->setTaskParameters(m_addAdd, m_addDiv, m_addMult, m_addSub, m_nrRatios, m_maxMainDenominator);
0679 }
0680 
0681 void MainQtWidget::MaxMainDenominatorBoxSlot()
0682 {
0683 #ifdef DEBUG
0684     qDebug() << QStringLiteral("MainQtWidget::MaxMainDenominatorBoxSlot()");
0685 #endif
0686     // get the max. size from the ComboBox, convert it to a number and store
0687     // it in the private member
0688     QString curr_md = m_MaxMainDenominatorBox->currentText();
0689     m_maxMainDenominator = curr_md.toUInt();
0690 
0691     // set the new task parameters
0692     (void) m_taskview->setTaskParameters(m_addAdd, m_addDiv, m_addMult, m_addSub, m_nrRatios, m_maxMainDenominator);
0693 }
0694 
0695 void MainQtWidget::AnswerMixedCheckSlot()
0696 {
0697 #ifdef DEBUG
0698     qDebug() << QStringLiteral("MainQtWidget::AnswerMixedCheckSlot()");
0699 #endif
0700     m_answerMixed = m_AnswerMixedCheck->isChecked();
0701     m_taskview->setAnswerMixed(m_answerMixed);
0702 }
0703 
0704 void MainQtWidget::QuestionMixedCheckSlot()
0705 {
0706 #ifdef DEBUG
0707     qDebug() << QStringLiteral("MainQtWidget::QuestionMixedCheckSlot()");
0708 #endif
0709     m_questionMixed = m_QuestionMixedCheck->isChecked();
0710     if (selectedTask == Arithmetic)
0711         m_taskview->setQuestionMixed(m_questionMixed);
0712     else if (selectedTask == Comparison)
0713         m_exerciseCompare->setQuestionMixed(m_questionMixed);
0714 }
0715 
0716 void MainQtWidget::ReducedFormCheckSlot()
0717 {
0718 #ifdef DEBUG
0719     qDebug() << QStringLiteral("MainQtWidget::ChkReducedFormSlot()");
0720 #endif
0721     m_reducedForm = m_ReducedCheck->isChecked();
0722     m_taskview->setReducedForm(m_reducedForm);
0723 }
0724 
0725 void MainQtWidget::AdditionCheckSlot()
0726 {
0727 #ifdef DEBUG
0728     qDebug() << QStringLiteral("MainQtWidget::AdditionCheckSlot()");
0729 #endif
0730     if (OperationsCheck() == true) {
0731         if (m_AdditionCheck->checkState() == Qt::Checked)
0732             m_addAdd = true;
0733         else
0734             m_addAdd = false;
0735     } else {
0736         m_addAdd = true;
0737         m_AdditionCheck->setCheckState(Qt::Checked);
0738     }
0739     (void) m_taskview->setTaskParameters(m_addAdd, m_addDiv, m_addMult, m_addSub, m_nrRatios, m_maxMainDenominator);
0740 }
0741 
0742 void MainQtWidget::SubtractionCheckSlot()
0743 {
0744 #ifdef DEBUG
0745     qDebug() << QStringLiteral("MainQtWidget::SubtractionCheckSlot()");
0746 #endif
0747     if (OperationsCheck() == true) {
0748         if (m_SubtractionCheck->checkState() == Qt::Checked)
0749             m_addSub = true;
0750         else
0751             m_addSub = false;
0752     } else {
0753         m_addSub = true;
0754         m_SubtractionCheck->setCheckState(Qt::Checked);
0755     }
0756     (void) m_taskview->setTaskParameters(m_addAdd, m_addDiv, m_addMult, m_addSub, m_nrRatios, m_maxMainDenominator);
0757 }
0758 
0759 void MainQtWidget::MultiplicationCheckSlot()
0760 {
0761 #ifdef DEBUG
0762     qDebug() << QStringLiteral("MainQtWidget::MultiplicationCheckSlot()");
0763 #endif
0764     if (OperationsCheck() == true) {
0765         if (m_MultiplicationCheck->checkState() == Qt::Checked)
0766             m_addMult = true;
0767         else
0768             m_addMult = false;
0769     } else {
0770         m_addMult = true;
0771         m_MultiplicationCheck->setCheckState(Qt::Checked);
0772     }
0773     (void) m_taskview->setTaskParameters(m_addAdd, m_addDiv, m_addMult, m_addSub, m_nrRatios, m_maxMainDenominator);
0774 }
0775 
0776 void MainQtWidget::DivisionCheckSlot()
0777 {
0778 #ifdef DEBUG
0779     qDebug() << QStringLiteral("MainQtWidget::DivisionCheckSlot()");
0780 #endif
0781     if (OperationsCheck() == true) {
0782         if (m_DivisionCheck->checkState() == Qt::Checked)
0783             m_addDiv = true;
0784         else
0785             m_addDiv = false;
0786     } else {
0787         m_addDiv = true;
0788         m_DivisionCheck->setCheckState(Qt::Checked);
0789     }
0790     (void) m_taskview->setTaskParameters(m_addAdd, m_addDiv, m_addMult, m_addSub, m_nrRatios, m_maxMainDenominator);
0791 }
0792 
0793 void MainQtWidget::slotPrefs()
0794 {
0795 #ifdef DEBUG
0796     qDebug() << QStringLiteral("slotPrefs MainQtWidget");
0797 #endif
0798     // do not show dialog twice
0799     if (KConfigDialog::showDialog(QStringLiteral("settings")))
0800         return;
0801 
0802     //KConfigDialog didn't find an instance of this dialog, so lets create it :
0803     KConfigDialog* configDialog = new KConfigDialog(this, QStringLiteral("settings"), SettingsClass::self());
0804 
0805     TaskColors * taskColors = new TaskColors(nullptr);
0806     configDialog->addPage(taskColors, i18n("Colors"), QStringLiteral("preferences-desktop-color"));
0807 
0808     TaskFonts * taskFonts = new TaskFonts(nullptr);
0809     configDialog->addPage(taskFonts, i18n("Fonts"), QStringLiteral("preferences-desktop-font"));
0810     // User edited the configuration - update your local copies of the
0811     // configuration data
0812     connect(configDialog, &KConfigDialog::settingsChanged, this, &MainQtWidget::slotApplySettings);
0813     configDialog->show();
0814 
0815     return;
0816 }
0817 
0818 void MainQtWidget::slotApplySettings()
0819 {
0820 #ifdef DEBUG
0821     qDebug() << QStringLiteral("slotApplySettings MainQtWidget");
0822 #endif
0823     // update the task view
0824     m_taskview->update();
0825     m_exerciseCompare->update();
0826     m_exerciseConvert->update();
0827     m_exerciseFactorize->update();
0828 
0829     return;
0830 }
0831 
0832 void MainQtWidget::slotAboutToShowPage()
0833 {
0834 #ifdef DEBUG
0835     qDebug() << QStringLiteral("slotAboutToShowPage MainQtWidget");
0836 #endif
0837     // check which page to show
0838 
0839     switch (selectedTask) {
0840     case Arithmetic:
0841         m_QuestionMixedCheck->setEnabled(true);
0842         m_NrOfTermsBox->setEnabled(true);
0843         m_MaxMainDenominatorBox->setEnabled(true);
0844         m_AnswerMixedCheck->setEnabled(true);
0845         m_ReducedCheck->setEnabled(true);
0846         m_SubtractionCheck->setEnabled(true);
0847         m_DivisionCheck->setEnabled(true);
0848         m_MultiplicationCheck->setEnabled(true);
0849         m_AdditionCheck->setEnabled(true);
0850         break;
0851     case Percentage:
0852     case Factorization:
0853     case Conversion:
0854     case MixedNumbers:
0855         m_QuestionMixedCheck->setEnabled(false);
0856         m_NrOfTermsBox->setEnabled(false);
0857         m_MaxMainDenominatorBox->setEnabled(false);
0858         m_AnswerMixedCheck->setEnabled(false);
0859         m_ReducedCheck->setEnabled(false);
0860         m_SubtractionCheck->setEnabled(false);
0861         m_DivisionCheck->setEnabled(false);
0862         m_MultiplicationCheck->setEnabled(false);
0863         m_AdditionCheck->setEnabled(false);
0864         break;
0865     case Comparison:
0866         m_QuestionMixedCheck->setEnabled(true);
0867         m_NrOfTermsBox->setEnabled(false);
0868         m_MaxMainDenominatorBox->setEnabled(false);
0869         m_AnswerMixedCheck->setEnabled(false);
0870         m_ReducedCheck->setEnabled(false);
0871         m_SubtractionCheck->setEnabled(false);
0872         m_DivisionCheck->setEnabled(false);
0873         m_MultiplicationCheck->setEnabled(false);
0874         m_AdditionCheck->setEnabled(false);
0875         break;
0876     }
0877     return;
0878 }
0879 
0880 void MainQtWidget::closeEvent(QCloseEvent *event)
0881 {
0882     writeOptions();
0883     KXmlGuiWindow::closeEvent(event);
0884 }
0885 
0886 void MainQtWidget::SelectPercentage()
0887 {
0888 #ifdef DEBUG
0889     qDebug() << QStringLiteral("SelectPercentage MainQtWidget");
0890 #endif
0891     m_TitleLabel->setText(i18n("Percentage"));
0892     selectedTask = Percentage;
0893     m_taskview->hide();
0894     m_exerciseCompare->hide();
0895     m_exerciseConvert->hide();
0896     m_exerciseMixedNumbers->hide();
0897     m_exerciseFactorize->hide();
0898     m_exercisePercentage->show();
0899     slotAboutToShowPage();
0900 }
0901 
0902 void MainQtWidget::SelectArithmetic()
0903 {
0904 #ifdef DEBUG
0905     qDebug() << QStringLiteral("SelectArithmetic MainQtWidget");
0906 #endif
0907     m_TitleLabel->setText(i18n("Arithmetic"));
0908     selectedTask = Arithmetic;
0909     m_taskview->show();
0910     m_exerciseCompare->hide();
0911     m_exerciseConvert->hide();
0912     m_exerciseMixedNumbers->hide();
0913     m_exerciseFactorize->hide();
0914     m_exercisePercentage->hide();
0915     slotAboutToShowPage();
0916 }
0917 
0918 void MainQtWidget::SelectComparison()
0919 {
0920 #ifdef DEBUG
0921     qDebug() << QStringLiteral("SelectComparison MainQtWidget");
0922 #endif
0923     m_TitleLabel->setText(i18n("Comparison"));
0924     selectedTask = Comparison;
0925     m_taskview->hide();
0926     m_exerciseCompare->show();
0927     m_exerciseConvert->hide();
0928     m_exerciseMixedNumbers->hide();
0929     m_exerciseFactorize->hide();
0930     m_exercisePercentage->hide();
0931     slotAboutToShowPage();
0932 }
0933 
0934 void MainQtWidget::SelectConversion()
0935 {
0936 #ifdef DEBUG
0937     qDebug() << QStringLiteral("SelectConversion MainQtWidget");
0938 #endif
0939     m_TitleLabel->setText(i18n("Conversion"));
0940     selectedTask = Conversion;
0941     m_taskview->hide();
0942     m_exerciseCompare->hide();
0943     m_exerciseConvert->show();
0944     m_exerciseMixedNumbers->hide();
0945     m_exerciseFactorize->hide();
0946     m_exercisePercentage->hide();
0947     slotAboutToShowPage();
0948 }
0949 
0950 void MainQtWidget::SelectMixedNumbers()
0951 {
0952 #ifdef DEBUG
0953     qDebug() << QStringLiteral("SelectMixedNumbers MainQtWidget");
0954 #endif
0955     m_TitleLabel->setText(i18n("Mixed Numbers"));
0956     selectedTask = MixedNumbers;
0957     m_taskview->hide();
0958     m_exerciseCompare->hide();
0959     m_exerciseConvert->hide();
0960     m_exerciseMixedNumbers->show();
0961     m_exerciseFactorize->hide();
0962     m_exercisePercentage->hide();
0963     slotAboutToShowPage();
0964 }
0965 
0966 void MainQtWidget::SelectFactorization()
0967 {
0968 #ifdef DEBUG
0969     qDebug() << QStringLiteral("SelectFactorization MainQtWidget");
0970 #endif
0971     m_TitleLabel->setText(i18n("Factorization"));
0972     selectedTask = Factorization;
0973     m_taskview->hide();
0974     m_exerciseCompare->hide();
0975     m_exerciseConvert->hide();
0976     m_exerciseMixedNumbers->hide();
0977     m_exercisePercentage->hide();
0978     m_exerciseFactorize->show();
0979     slotAboutToShowPage();
0980 }
0981 
0982 bool MainQtWidget::OperationsCheck()
0983 {
0984 #ifdef DEBUG
0985     qDebug() << QStringLiteral("MainQtWidget::OperationsCheck()");
0986 #endif
0987 
0988     if (m_AdditionCheck->checkState() == Qt::Unchecked &&
0989             m_SubtractionCheck->checkState() == Qt::Unchecked &&
0990             m_DivisionCheck->checkState() == Qt::Unchecked &&
0991             m_MultiplicationCheck->checkState() == Qt::Unchecked)
0992         return false;
0993     else
0994         return true;
0995 }
0996 
0997 void MainQtWidget::goBack()
0998 {
0999     kbruchApp = new AppMenuWidget();
1000     kbruchApp->show();
1001     close();
1002 }