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

0001 /*
0002     KBruch - exercise to convert mixed numbers in ratios and vice versa
0003     SPDX-FileCopyrightText: 2011 - Sebastian Stein <seb.kde@hpfsc.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef EXERCISEMIXEDNUMBERS_H
0009 #define EXERCISEMIXEDNUMBERS_H
0010 
0011 #include "ExerciseBase.h"
0012 #include "ResultWidget.h"
0013 #include "Task.h"
0014 #include "TaskWidget.h"
0015 
0016 
0017 class QLineEdit;
0018 class QFrame;
0019 class QGridLayout;
0020 class QPushButton;
0021 class QWidget;
0022 
0023 
0024 /**
0025  * exercise to convert mixed numbers in ordinary ratios and vice versa
0026  * \author Sebastian Stein
0027  */
0028 class ExerciseMixedNumbers: public ExerciseBase
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     /** constructor */
0034     explicit ExerciseMixedNumbers(QWidget* parent = nullptr);
0035 
0036     /** destructor */
0037     ~ExerciseMixedNumbers() override;
0038 
0039     /** resets the current state, creates a new task and counts the last task
0040      * as wrong, if it wasn't solved (in _NEXT_TASK state) yet mainly used
0041      * after changing the task parameters */
0042     void forceNewTask() override;
0043 
0044 Q_SIGNALS:
0045     /** signal emitted if task solved correctly */
0046     void signalExerciseSolvedCorrect();
0047 
0048     /** signal emitted if task skipped */
0049     void signalExerciseSkipped();
0050 
0051     /** signal emitted if task solved not correctly */
0052     void signalExerciseSolvedWrong();
0053 
0054 private:
0055     /** holds current state of this exercise */
0056     short m_currentState;
0057 
0058     /** true if task is a mixed number and user must enter ratio */
0059     bool m_isMixedTask;
0060 
0061     /** task currently to be solved */
0062     Task m_task;
0063 
0064     // components to enter result
0065     QLineEdit * m_integerEdit;
0066     QLineEdit * m_numerEdit;
0067     QFrame * m_editLine;
0068     QLineEdit * m_denoEdit;
0069 
0070     // check and skip buttons
0071     QPushButton * m_checkButton;
0072     QPushButton * m_skipButton;
0073 
0074     // base grid layout
0075     QGridLayout * m_baseGrid;
0076     QWidget * m_checkWidget;
0077     QWidget * m_tmpTaskWidget;
0078 
0079     // layout to show task and input fields
0080     QGridLayout * m_taskLayout;
0081     TaskWidget * m_taskWidget;
0082 
0083     // layout to show solution
0084     QGridLayout * m_checkLayout;
0085     ResultWidget * m_resultWidget;
0086 
0087     /** creates a new task */
0088     void createTask();
0089 
0090     /** shows next task; hides previous solution */
0091     void nextTask();
0092 
0093     /** checks result and shows solution */
0094     void showResult();
0095 
0096     /** handle check button click */
0097     void slotCheckButtonClicked();
0098 
0099     /** handle skip button click */
0100     void slotSkipButtonClicked();
0101 
0102     /** focus set to numerator edit if return pressed in integer edit */
0103     void integerReturnPressed();
0104 
0105     /** focus set to denominator edit if return pressed in numerator edit */
0106     void numerReturnPressed();
0107 
0108     /** invokes check button if return pressed in denominator edit */
0109     void denoReturnPressed();
0110 
0111     protected:
0112     /** sets focus to input fields */
0113     void showEvent(QShowEvent * event) override;
0114 };
0115 
0116 #endif // EXERCISEMIXEDNUMBERS_H