File indexing completed on 2024-05-19 09:44:38
0001 // SPDX-FileCopyrightText: 2022 Felipe Kinoshita <kinofhek@gmail.com> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 #pragma once 0005 0006 #include "config.h" 0007 #include <QObject> 0008 0009 class QTimer; 0010 0011 class Controller : public QObject 0012 { 0013 Q_OBJECT 0014 Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged) 0015 Q_PROPERTY(float percentage MEMBER m_percentage NOTIFY percentageChanged) 0016 Q_PROPERTY(int pomodoros MEMBER m_pomodoros NOTIFY pomodorosChanged) 0017 Q_PROPERTY(bool running MEMBER m_running NOTIFY runningChanged) 0018 Q_PROPERTY(bool hasStarted MEMBER m_hasStarted NOTIFY hasStartedChanged) 0019 Q_PROPERTY(bool onBreak MEMBER m_onBreak NOTIFY breakChanged) 0020 0021 public: 0022 explicit Controller(QObject *parent = nullptr); 0023 ~Controller() override; 0024 0025 QString text() const; 0026 Q_SIGNAL void textChanged(); 0027 0028 int pomodoros() const; 0029 Q_SIGNAL void pomodorosChanged(); 0030 0031 float percentage(); 0032 Q_SIGNAL void percentageChanged(); 0033 0034 bool running() const; 0035 Q_SIGNAL void runningChanged(); 0036 0037 bool hasStarted() const; 0038 Q_SIGNAL void hasStartedChanged(); 0039 0040 bool onBreak() const; 0041 Q_SIGNAL void breakChanged(); 0042 0043 Q_INVOKABLE void start(); 0044 Q_INVOKABLE void toggle(); 0045 Q_INVOKABLE void reset(); 0046 0047 void update(); 0048 0049 void generateText(); 0050 0051 /// Only useful for unit testing 0052 void setMinuteDuration(int duration); 0053 0054 private: 0055 QTimer *m_timer; 0056 QString m_text; 0057 float m_percentage; 0058 0059 int m_minuteDuration = 60; 0060 int m_pomodoros{0}; 0061 int m_changes{0}; 0062 int m_seconds{Config::self()->intervalTime() * 60}; 0063 bool m_running{false}; 0064 bool m_hasStarted{false}; 0065 bool m_onBreak{false}; 0066 };