File indexing completed on 2024-04-21 03:41:49

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 #ifndef MAINQTWIDGET_H
0012 #define MAINQTWIDGET_H
0013 
0014 #include <KXmlGuiWindow>
0015 #include <QRadioButton>
0016 
0017 class QAction;
0018 class QWidgetAction;
0019 class QComboBox;
0020 
0021 class QLabel;
0022 class QCheckBox;
0023 class QGroupBox;
0024 class QGridLayout;
0025 class QFrame;
0026 class QToolButton;
0027 
0028 class ExerciseCompare;
0029 class ExerciseConvert;
0030 class ExerciseFactorize;
0031 class ExerciseMixedNumbers;
0032 class ExercisePercentage;
0033 class StatisticsView;
0034 class TaskView;
0035 class AppMenuWidget;
0036 class ExerciseMixedNumbers;
0037 
0038 
0039 class QGridLayout;
0040 
0041 
0042 enum ExerciseType {
0043     Arithmetic,
0044     Comparison,
0045     Conversion,
0046     MixedNumbers,
0047     Factorization,
0048     Percentage
0049 };
0050 
0051 /** Constructs the main window and presents the user interface.
0052  *  The window is separated into 2 sections. In the left section is the
0053  *  statistic view and in the right section the task view.
0054  *  \author Sebastian Stein
0055  *  \author Eva Brucherseifer
0056  **/
0057 class MainQtWidget : public KXmlGuiWindow
0058 {
0059     Q_OBJECT
0060 
0061 public:
0062 
0063     /** constructor */
0064     MainQtWidget();
0065 
0066     /** destructor */
0067     ~MainQtWidget() override;
0068 
0069     static QFont DefaultFont();
0070 
0071 private:
0072 
0073     /** read the config file */
0074     void readOptions();
0075 
0076     /** read the config file */
0077     void writeOptions();
0078 
0079     /** pointing to the statistics view */
0080     StatisticsView * m_statview;
0081 
0082     /** pointing to the exercise solving a task with fractions */
0083     TaskView * m_taskview;
0084 
0085     /** pointing to the exercise comparing ratios */
0086     ExerciseCompare * m_exerciseCompare;
0087 
0088     /** pointing to the exercise convert rational number */
0089     ExerciseConvert * m_exerciseConvert;
0090 
0091     /** pointing to the exercise for converting mixed numbers to ratios */
0092     ExerciseMixedNumbers * m_exerciseMixedNumbers;
0093 
0094     /** pointing to the exercise factorize a given number */
0095     ExerciseFactorize * m_exerciseFactorize;
0096 
0097     /** pointing to the exercise percentage */
0098     ExercisePercentage * m_exercisePercentage;
0099 
0100     ExerciseType selectedTask;
0101     bool m_addSub;
0102     bool m_addAdd;
0103     bool m_addMult;
0104     bool m_addDiv;
0105     unsigned int m_nrRatios;
0106     unsigned int m_maxMainDenominator;
0107     bool m_questionMixed;
0108     bool m_answerMixed;
0109     bool m_reducedForm;
0110     QFont defaultFont;
0111 
0112     // Visible Components
0113     QLabel * m_OptionsLabel;
0114     QLabel * m_TitleLabel;
0115 
0116 
0117     QGroupBox * m_QuestionGroup;
0118     QGroupBox * m_AnswerGroup;
0119     QGroupBox * m_OperationsGroup;
0120 
0121     QToolButton * m_ArithmeticButton;
0122     QToolButton * m_ComparisonButton;
0123     QToolButton * m_ConversionButton;
0124     QToolButton * m_MixedNumbersButton;
0125     QToolButton * m_FactorizationButton;
0126     QToolButton * m_NewTaskButton;
0127     QToolButton * m_BackTaskButton;
0128     QToolButton * m_PercentageButton;
0129 
0130     // Question Group
0131     QComboBox * m_NrOfTermsBox;
0132     QLabel * m_NrOfTermsLabel;
0133 
0134     QComboBox * m_MaxMainDenominatorBox;
0135     QLabel * m_MaxMainDenominatorLabel;
0136 
0137     QCheckBox * m_QuestionMixedCheck;
0138     QLabel * m_QuestionMixedLabel;
0139 
0140 
0141     // Answer group
0142     QRadioButton * m_AnswerMixedCheck;
0143     QLabel * m_AnswerMixedLabel;
0144 
0145     QRadioButton * m_ReducedCheck;
0146     QLabel * m_ReducedLabel;
0147 
0148 
0149     // Operations group
0150     QCheckBox * m_AdditionCheck;
0151     QLabel * m_AdditionLabel;
0152 
0153     QCheckBox * m_SubtractionCheck;
0154     QLabel * m_SubtractionLabel;
0155 
0156     QCheckBox * m_MultiplicationCheck;
0157     QLabel * m_MultiplicationLabel;
0158 
0159     QCheckBox * m_DivisionCheck;
0160     QLabel * m_DivisionLabel;
0161 
0162     // Menu exercise actions
0163     QWidgetAction * m_ArithmeticAction;
0164     QWidgetAction * m_ComparisonAction;
0165     QWidgetAction * m_ConversionAction;
0166     QWidgetAction * m_MixedNumbersAction;
0167     QWidgetAction * m_FactorizationAction;
0168     QWidgetAction * m_NewTaskActionMenu;
0169     QWidgetAction * m_NewTaskActionTool;
0170     QWidgetAction * m_BackActionTool;
0171     QWidgetAction * m_BackActionMenu;
0172     QAction * m_HintAction;
0173     QWidgetAction * m_PercentageAction;
0174 
0175     QFrame * m_footerline;
0176     QFrame * m_headerline;
0177 
0178     AppMenuWidget * kbruchApp;
0179 
0180     void setupActions();
0181 
0182 private Q_SLOTS:
0183     bool OperationsCheck();
0184 
0185     /**
0186      * Tasks selection
0187      */
0188     void SelectArithmetic();
0189     void SelectComparison();
0190     void SelectConversion();
0191     void SelectMixedNumbers();
0192     void SelectFactorization();
0193     void SelectPercentage();
0194 
0195     /**
0196      * Options Slot changes
0197      */
0198     // called, when the user changes the state of reduced form checkbox
0199     void ReducedFormCheckSlot();
0200     // called, when the user changes the state of mixed number checkbox of question group
0201     void QuestionMixedCheckSlot();
0202     // called, when the user changes the state of mixed number checkbox of answer group
0203     void AnswerMixedCheckSlot();
0204     // called, when the user changes the state of addition task operation
0205     void AdditionCheckSlot();
0206     // called, when the user changes the state of subtraction task operation
0207     void SubtractionCheckSlot();
0208     // called, when the user changes the state of multiplication task operation
0209     void MultiplicationCheckSlot();
0210     // called, when the user changes the state of division task operation
0211     void DivisionCheckSlot();
0212     // called when the user changes the number of terms in the ComboBox
0213     void NrOfTermsBoxSlot();
0214     // called, when the user changes the max. size of the main denominator in the ComboBox
0215     void MaxMainDenominatorBoxSlot();
0216 
0217 
0218     /**
0219      * called to force generation of a new task
0220      */
0221     void newTask();
0222 
0223 
0224     /**
0225      * calls the settings dialog
0226      */
0227     void slotPrefs();
0228 
0229 
0230     /**
0231      * makes sure, all parts of the UI update to new settings
0232      */
0233     void slotApplySettings();
0234 
0235 
0236     /**
0237      * called just before another page is shown
0238      */
0239     void slotAboutToShowPage();
0240 
0241 
0242     /**
0243      * called to go back to the main screen and choose another mode
0244      */
0245     void goBack();
0246 
0247 protected:
0248     /** Function is called when user closes the window.
0249      *  Used to save the current statistics and settings before exiting.
0250      */
0251     void closeEvent(QCloseEvent *event) override;
0252 };
0253 
0254 #endif // MainQtWidget