File indexing completed on 2024-04-14 03:40:25

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 #ifndef EXERCISEFACTORIZE_H
0010 #define EXERCISEFACTORIZE_H
0011 
0012 #include <QList>
0013 #include <QWidget>
0014 
0015 #include "ExerciseBase.h"
0016 #include "ResultWidget.h"
0017 #include "Ratio.h"
0018 #include "PrimeFactorsLineEdit.h"
0019 
0020 class ResultWidget;
0021 class QGridLayout;
0022 class QLabel;
0023 class QPushButton;
0024 
0025 // a list containing uints
0026 typedef QList<uint> uintList;
0027 
0028 // set a macro how much numbers are given to factorize
0029 #define numberPossibleTasks 45
0030 
0031 // set all possible numbers to factorize
0032 const uint possibleTasks[numberPossibleTasks] = {4, 6, 8, 9, 10, 12, 14, 15, 16,
0033         18, 20, 21, 22, 24, 25, 26, 27, 30, 32, 33, 34, 35, 38, 39, 49, 50, 51, 54, 55,
0034         57, 60, 65, 70, 77, 75, 85, 95, 98, 121, 125, 169, 242, 250, 289, 361
0035                                                 };
0036 
0037 /*! Construct the exercise widget to factorize a given number
0038  *
0039  *  \author Sebastian Stein
0040  * */
0041 class ExerciseFactorize : public ExerciseBase
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     /** constructor */
0047     explicit ExerciseFactorize(QWidget * parent = nullptr);
0048 
0049     /** destructor */
0050     ~ExerciseFactorize() override;
0051 
0052     /** force the creation of a new task */
0053     void forceNewTask() override;
0054 
0055     void update();
0056 
0057 Q_SIGNALS:
0058     /** class emits this signal, if the task was solved correctly by the user */
0059     void signalExerciseSolvedCorrect();
0060 
0061     /** class emits this signal, if the task was skipped by the user */
0062     void signalExerciseSkipped();
0063 
0064     /** class emits this signal, if the task was solved not correctly by the user
0065      * */
0066     void signalExerciseSolvedWrong();
0067 
0068 private:
0069     short m_currentState;
0070 
0071     bool m_edit;
0072 
0073     // Get the last number typped by keyboard for keyboard handler
0074     uint m_buffer;
0075 
0076     uint m_taskNumber;
0077     uintList m_factorsEntered;
0078     uintList m_factorsResult;
0079 
0080     QLabel * m_taskLabel;
0081     QLabel * m_equalSignLabel;
0082     PrimeFactorsLineEdit * m_factorsEnteredEdit;
0083 
0084     // buttons for the different prime factors
0085     QPushButton * m_factor2Button;
0086     QPushButton * m_factor3Button;
0087     QPushButton * m_factor5Button;
0088     QPushButton * m_factor7Button;
0089     QPushButton * m_factor11Button;
0090     QPushButton * m_factor13Button;
0091     QPushButton * m_factor17Button;
0092     QPushButton * m_factor19Button;
0093 
0094     // button to remove the last entered factor
0095     QPushButton * m_removeLastFactorButton;
0096     QPushButton * m_checkButton;
0097     QPushButton * m_skipButton;
0098 
0099     QGridLayout * checkLayout;
0100     QGridLayout * taskLayout;
0101     QGridLayout * baseGrid;
0102 
0103     QWidget * checkWidget;
0104     QWidget * taskWidget;
0105 
0106     ResultWidget * m_resultWidget;
0107 
0108     void createTask();
0109     void showResult();
0110     void nextTask();
0111 
0112     void addFactor(uint factor);
0113     void updateEnteredEdit();
0114 
0115     void slotFactorsEditReturnPressed();
0116 
0117     void slotCheckButtonClicked();
0118     void slotSkipButtonClicked();
0119 
0120     void slotFactor2ButtonClicked();
0121     void slotFactor3ButtonClicked();
0122     void slotFactor5ButtonClicked();
0123     void slotFactor7ButtonClicked();
0124     void slotFactor11ButtonClicked();
0125     void slotFactor13ButtonClicked();
0126     void slotFactor17ButtonClicked();
0127     void slotFactor19ButtonClicked();
0128     void slotRemoveLastFactorButtonClicked();
0129 
0130     void editContentChanged(bool correct);
0131     void setButtonsEnabled(bool enabled);
0132 
0133     protected:
0134     void showEvent(QShowEvent * event) override;
0135 };
0136 
0137 #endif