[plasma-mobile/kclock] src: Add ability to loop timer
Devin Lin
null at kde.org
Mon Jul 19 16:00:59 BST 2021
Git commit 836fe6313c161366647d8a6056f417148dbb7f28 by Devin Lin, on behalf of Boris Petrov.
Committed on 19/07/2021 at 14:59.
Pushed by devinlin into branch 'master'.
Add ability to loop timer
With this addition one can set timers to loop indefinitely
to do repetitive tasks for instance.
FEATURE: Ability to loop timer
GUI:
M +10 -1 src/kclock/qml/TimerListPage.qml
M +6 -0 src/kclock/qml/TimerPage.qml
M +12 -0 src/kclock/timer.cpp
M +8 -0 src/kclock/timer.h
M +14 -2 src/kclockd/timer.cpp
M +8 -0 src/kclockd/timer.h
https://invent.kde.org/plasma-mobile/kclock/commit/836fe6313c161366647d8a6056f417148dbb7f28
diff --git a/src/kclock/qml/TimerListPage.qml b/src/kclock/qml/TimerListPage.qml
index 905c447..8605df0 100644
--- a/src/kclock/qml/TimerListPage.qml
+++ b/src/kclock/qml/TimerListPage.qml
@@ -148,7 +148,16 @@ Kirigami.ScrollablePage {
Row {
Layout.alignment: Qt.AlignRight
-
+ ToolButton {
+ icon.name: timerDelegate && timerDelegate.looping ? "media-repeat-all" : "media-repeat-none"
+ display: AbstractButton.IconOnly
+ text: timerDelegate && timerDelegate.looping ? i18n("Timer is looping") : i18n("Timer in not looping")
+ onClicked: timerDelegate.toggleLooping()
+
+ ToolTip.visible: hovered && text.length > 0
+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
+ ToolTip.text: text
+ }
ToolButton {
icon.name: timerDelegate && timerDelegate.running ? "chronometer-pause" : "chronometer-start"
display: AbstractButton.IconOnly
diff --git a/src/kclock/qml/TimerPage.qml b/src/kclock/qml/TimerPage.qml
index 28ace9b..f5713b9 100644
--- a/src/kclock/qml/TimerPage.qml
+++ b/src/kclock/qml/TimerPage.qml
@@ -24,6 +24,7 @@ Kirigami.Page {
property int elapsed: timer == null ? 0 : timer.elapsed
property int duration: timer == null ? 0 : timer.length
property bool running: timer == null ? 0 : timer.running
+ property bool looping: timer == null ? 0 : timer.looping
// keyboard controls
Keys.onSpacePressed: timer.toggleRunning();
@@ -38,6 +39,11 @@ Kirigami.Page {
}
contextualActions: [
+ Kirigami.Action {
+ text: looping ? i18n("Timer is looping") : i18n("Timer is not looping")
+ iconName: looping ? "media-repeat-all" : "media-repeat-none"
+ onTriggered: timer.toggleLooping()
+ },
Kirigami.Action {
icon.name: "chronometer-reset"
text: i18n("Reset")
diff --git a/src/kclock/timer.cpp b/src/kclock/timer.cpp
index 479f28f..58e9fa4 100644
--- a/src/kclock/timer.cpp
+++ b/src/kclock/timer.cpp
@@ -27,6 +27,7 @@ Timer::Timer(QString uuid, bool justCreated)
connect(m_interface, &OrgKdeKclockTimerInterface::lengthChanged, this, &Timer::updateLength);
connect(m_interface, &OrgKdeKclockTimerInterface::labelChanged, this, &Timer::updateLabel);
connect(m_interface, &OrgKdeKclockTimerInterface::runningChanged, this, &Timer::updateRunning);
+ connect(m_interface, &OrgKdeKclockTimerInterface::loopingChanged, this, &Timer::updateLooping);
updateRunning(); // start animation
}
@@ -37,6 +38,11 @@ void Timer::toggleRunning()
m_interface->toggleRunning();
}
+void Timer::toggleLooping()
+{
+ m_interface->toggleLooping();
+}
+
void Timer::reset()
{
m_interface->reset();
@@ -75,6 +81,12 @@ void Timer::updateRunning()
Q_EMIT elapsedChanged();
}
+void Timer::updateLooping()
+{
+ m_looping = m_interface->looping();
+ Q_EMIT propertyChanged();
+}
+
void Timer::animation(bool start)
{
if (!m_timer) {
diff --git a/src/kclock/timer.h b/src/kclock/timer.h
index a14e5f7..fe83246 100644
--- a/src/kclock/timer.h
+++ b/src/kclock/timer.h
@@ -23,6 +23,7 @@ class Timer : public QObject
Q_PROPERTY(QString elapsedPretty READ elapsedPretty NOTIFY elapsedChanged)
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY propertyChanged)
Q_PROPERTY(bool running READ running NOTIFY propertyChanged)
+ Q_PROPERTY(bool looping READ looping NOTIFY propertyChanged)
Q_PROPERTY(bool justCreated MEMBER m_justCreated NOTIFY propertyChanged)
public:
@@ -33,6 +34,7 @@ public:
return m_uuid;
};
Q_INVOKABLE void toggleRunning();
+ Q_INVOKABLE void toggleLooping();
Q_INVOKABLE void reset();
Q_INVOKABLE void addMinute();
@@ -70,6 +72,10 @@ public:
{
return m_running;
}
+ const bool &looping() const
+ {
+ return m_looping;
+ }
signals:
void propertyChanged();
@@ -78,6 +84,7 @@ private slots:
void updateLength();
void updateLabel();
void updateRunning();
+ void updateLooping();
private:
void animation(bool start);
@@ -85,6 +92,7 @@ private:
int m_length, m_elapsed; // seconds
QString m_label;
bool m_running;
+ bool m_looping;
bool m_justCreated;
QUuid m_uuid;
diff --git a/src/kclockd/timer.cpp b/src/kclockd/timer.cpp
index 5b31f7b..7320507 100644
--- a/src/kclockd/timer.cpp
+++ b/src/kclockd/timer.cpp
@@ -69,6 +69,13 @@ void Timer::toggleRunning()
setRunning(!m_running);
}
+void Timer::toggleLooping()
+{
+ m_looping = !m_looping;
+
+ Q_EMIT loopingChanged();
+}
+
void Timer::reset()
{
setRunning(false);
@@ -82,8 +89,13 @@ void Timer::timeUp(int cookie)
if (cookie == m_cookie) {
this->sendNotification();
this->m_cookie = -1;
- this->setRunning(false);
- this->m_hasElapsed = m_length;
+ if (m_looping) {
+ this->reset();
+ this->setRunning(true);
+ } else {
+ this->setRunning(false);
+ this->m_hasElapsed = m_length;
+ }
}
}
diff --git a/src/kclockd/timer.h b/src/kclockd/timer.h
index 71fc4cf..23eed5e 100644
--- a/src/kclockd/timer.h
+++ b/src/kclockd/timer.h
@@ -20,6 +20,7 @@ class Timer : public QObject
Q_PROPERTY(int length READ length WRITE setLength NOTIFY lengthChanged)
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
Q_PROPERTY(bool running READ running NOTIFY runningChanged)
+ Q_PROPERTY(bool looping READ looping NOTIFY loopingChanged)
public:
explicit Timer(int length = 0, QString label = QStringLiteral(), bool running = false);
@@ -29,6 +30,7 @@ public:
QJsonObject serialize();
Q_SCRIPTABLE void toggleRunning();
+ Q_SCRIPTABLE void toggleLooping();
Q_SCRIPTABLE void reset();
Q_SCRIPTABLE int elapsed() const
{
@@ -69,11 +71,16 @@ public:
{
return m_running;
}
+ const bool &looping() const
+ {
+ return m_looping;
+ }
Q_SIGNALS:
Q_SCRIPTABLE void lengthChanged();
Q_SCRIPTABLE void labelChanged();
Q_SCRIPTABLE void runningChanged();
+ Q_SCRIPTABLE void loopingChanged();
private Q_SLOTS:
void timeUp(int cookie);
void reschedule();
@@ -88,6 +95,7 @@ private:
int m_cookie = -1;
QString m_label;
bool m_running = false;
+ bool m_looping = false;
};
#endif // KCLOCKD_TIMER_H
More information about the kde-doc-english
mailing list