| 1 | #pragma once |
| 2 | |
| 3 | #include <QFrame> |
| 4 | #include <QTime> |
| 5 | |
| 6 | class QToolButton; |
| 7 | class QLabel; |
| 8 | class QAction; |
| 9 | class QTimer; |
| 10 | class GitBase; |
| 11 | |
| 12 | class PomodoroButton : public QFrame |
| 13 | { |
| 14 | Q_OBJECT |
| 15 | |
| 16 | signals: |
| 17 | /** |
| 18 | * @brief Signal when the link has been clicked |
| 19 | * |
| 20 | */ |
| 21 | void clicked(); |
| 22 | |
| 23 | public: |
| 24 | /** |
| 25 | * @brief PomodoroButton Overloaded constructor. |
| 26 | * @param parent The parent widget. |
| 27 | */ |
| 28 | explicit PomodoroButton(const QSharedPointer<GitBase> &git, QWidget *parent = nullptr); |
| 29 | |
| 30 | /** |
| 31 | * @brief setText Sets the text to the button. |
| 32 | * @param text The new text. |
| 33 | */ |
| 34 | void setText(const QString &text); |
| 35 | |
| 36 | protected: |
| 37 | /** |
| 38 | * |
| 39 | *@brief Event that processes whether the user presses or not the mouse |
| 40 | * |
| 41 | * @param e The event |
| 42 | */ |
| 43 | void mousePressEvent(QMouseEvent *e) override; |
| 44 | |
| 45 | /** |
| 46 | * @brief Event that processes whether the user releases the mouse button or not |
| 47 | * |
| 48 | * @param event The event |
| 49 | */ |
| 50 | void mouseReleaseEvent(QMouseEvent *e) override; |
| 51 | |
| 52 | /** |
| 53 | * @brief eventFilter Event filter method to position the menu of the tool button in a custom position. |
| 54 | * @param obj The object to filter, in this case QMenu. |
| 55 | * @param event The event to filter, in this case QEvent::Show. |
| 56 | * @return Returns true if filtered. |
| 57 | */ |
| 58 | bool eventFilter(QObject *obj, QEvent *event) override; |
| 59 | |
| 60 | private: |
| 61 | enum class State |
| 62 | { |
| 63 | OnHold, |
| 64 | Running, |
| 65 | InBreak, |
| 66 | InBreakRunning, |
| 67 | InLongBreak, |
| 68 | InLongBreakRunning, |
| 69 | Finished |
| 70 | }; |
| 71 | QTime mDurationTime; |
| 72 | QTime mBreakTime; |
| 73 | QTime mLongBreakTime; |
| 74 | bool mPressed = false; |
| 75 | int mBigBreakCount = 0; |
| 76 | int mBigBreakOriginalValue = 0; |
| 77 | bool mStopResets = true; |
| 78 | State mState = State::OnHold; |
| 79 | QSharedPointer<GitBase> mGit; |
| 80 | QToolButton *mButton = nullptr; |
| 81 | QToolButton *mArrow = nullptr; |
| 82 | QLabel *mCounter = nullptr; |
| 83 | QTimer *mTimer = nullptr; |
| 84 | QAction *mConfigAction = nullptr; |
| 85 | |
| 86 | void onTimeout(); |
| 87 | void onClick(); |
| 88 | void onRunningMode(); |
| 89 | void onBreakingMode(); |
| 90 | void onLongBreakingMode(); |
| 91 | void showConfig(); |
| 92 | /** |
| 93 | * @brief updateCounters Notify the widget to update the counters because the configuration changed. This resets all |
| 94 | * counters and puts the pomodoro back on hold if it was running. |
| 95 | * |
| 96 | * The number of pomodoros until the long break is |
| 97 | * reset but the class takes into account to discount them from the new value. |
| 98 | * |
| 99 | * If the new value is lower than the value stored, the counter will start again in a new cycle. |
| 100 | */ |
| 101 | void updateCounters(); |
| 102 | void setRunningMode(); |
| 103 | }; |
| 104 | |