File indexing completed on 2024-04-28 13:43:44
0001 /* This file is part of Kairo Timer 0002 0003 SPDX-FileCopyrightText: 2016 (c) Kevin Ottens <ervin@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 0007 */ 0008 0009 #ifndef TIMERCONTROL_H 0010 #define TIMERCONTROL_H 0011 0012 #include <QObject> 0013 0014 #include "timermodel.h" 0015 0016 class QTimer; 0017 0018 class TimerControl : public QObject 0019 { 0020 Q_OBJECT 0021 Q_PROPERTY(TimerModel model READ model WRITE setModel NOTIFY modelChanged) 0022 Q_PROPERTY(QString text READ text NOTIFY textChanged) 0023 Q_PROPERTY(int value READ value NOTIFY valueChanged) 0024 Q_PROPERTY(QString formattedValue READ formattedValue NOTIFY formattedValueChanged) 0025 Q_PROPERTY(int duration READ duration NOTIFY durationChanged) 0026 Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) 0027 public: 0028 explicit TimerControl(QObject *parent = nullptr); 0029 0030 Q_INVOKABLE TimerModel createModel() const; 0031 Q_INVOKABLE TimerModel createModel(const QString &text, int duration = 0) const; 0032 0033 TimerModel model() const; 0034 void setModel(const TimerModel &model); 0035 void setModel(TimerModel &&model); 0036 0037 QString text() const; 0038 int value() const; 0039 QString formattedValue() const; 0040 int duration() const; 0041 bool isRunning() const; 0042 0043 public slots: 0044 void setRunning(bool running); 0045 0046 signals: 0047 void modelChanged(const TimerModel &model); 0048 void textChanged(const QString &text); 0049 void valueChanged(int value); 0050 void durationChanged(int duration); 0051 void runningChanged(bool running); 0052 void formattedValueChanged(const QString &formattedValue); 0053 0054 void timerFinished(); 0055 void timerSkipped(); 0056 0057 private slots: 0058 void onTimerTimeout(); 0059 0060 private: 0061 TimerModel m_model; 0062 QTimer *m_timer; 0063 bool m_running = false; 0064 int m_value = 0; 0065 }; 0066 0067 #endif