Commit c9a40618 authored by Boris Petrov's avatar Boris Petrov 💾 Committed by Devin Lin
Browse files

Add ability to loop timer

This reverts commit 71d7c4b1.
parent 71d7c4b1
Pipeline #71310 passed with stage
in 24 seconds
......@@ -148,7 +148,17 @@ Kirigami.ScrollablePage {
Row {
Layout.alignment: Qt.AlignRight
ToolButton {
icon.name: timerDelegate && timerDelegate.looping ? "media-repeat-all" : "media-repeat-none"
display: AbstractButton.IconOnly
text: i18n("Loop Timer")
checked: timerDelegate && timerDelegate.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
......
......@@ -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();
......@@ -50,6 +51,13 @@ Kirigami.Page {
pageStack.pop();
timerModel.remove(timerIndex);
}
},
Kirigami.Action {
icon.name: "media-repeat-all"
text: i18n("Loop Timer")
checkable: true
checked: looping
onTriggered: timer.toggleLooping()
}
]
}
......
......@@ -24,9 +24,11 @@ Timer::Timer(QString uuid, bool justCreated)
m_length = m_interface->length();
m_running = m_interface->running();
m_elapsed = m_interface->elapsed();
m_looping = m_interface->looping();
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 +39,11 @@ void Timer::toggleRunning()
m_interface->toggleRunning();
}
void Timer::toggleLooping()
{
m_interface->toggleLooping();
}
void Timer::reset()
{
m_interface->reset();
......@@ -75,6 +82,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) {
......
......@@ -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;
......
......@@ -38,6 +38,7 @@ Timer::Timer(const QJsonObject &obj)
m_length = obj[QStringLiteral("length")].toInt();
m_label = obj[QStringLiteral("label")].toString();
m_uuid = QUuid(obj[QStringLiteral("uuid")].toString());
m_looping = obj[QStringLiteral("looping")].toBool();
connect(&Utilities::instance(), &Utilities::wakeup, this, &Timer::timeUp);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Timers/") + this->m_uuid.toString(QUuid::Id128),
......@@ -61,6 +62,7 @@ QJsonObject Timer::serialize()
obj[QStringLiteral("length")] = m_length;
obj[QStringLiteral("label")] = m_label;
obj[QStringLiteral("uuid")] = m_uuid.toString();
obj[QStringLiteral("looping")] = m_looping;
return obj;
}
......@@ -69,6 +71,15 @@ void Timer::toggleRunning()
setRunning(!m_running);
}
void Timer::toggleLooping()
{
m_looping = !m_looping;
Q_EMIT loopingChanged();
TimerModel::instance()->save();
}
void Timer::reset()
{
setRunning(false);
......@@ -82,8 +93,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;
}
}
}
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment