diff --git a/applets/timer/package/contents/ui/TimerView.qml b/applets/timer/package/contents/ui/TimerView.qml index c1323e105..ef275dc43 100644 --- a/applets/timer/package/contents/ui/TimerView.qml +++ b/applets/timer/package/contents/ui/TimerView.qml @@ -1,194 +1,151 @@ /*************************************************************************** * Copyright 2008,2014 by Davide Bettio * * Copyright 2015 by Bernhard Friedreich * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 2.2 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 as QtExtra -import org.kde.plasma.private.timer 0.1 as TimerPlasmoid Item { id: main property date savedAt: plasmoid.configuration.savedAt; // display seconds in addition to hours and minutes (default: enabled) property bool showSeconds: plasmoid.configuration.showSeconds; - // show notification on timer completion (default: enabled) - property bool showNotification: plasmoid.configuration.showNotification; - - // run custom command on timer completion (default: disabled) - property bool runCommand: plasmoid.configuration.runCommand; - property string command: plasmoid.configuration.command; - property real digits: (showSeconds) ? 7 : 4.5; property int digitH: ((height / 2) * digits < width ? height : ((width - (digits - 1)) / digits) * 2); property int digitW: digitH / 2; PlasmaCore.Svg { id: timerSvg imagePath: "widgets/timer" } - Timer { - id: t; - interval: 1000; - onTriggered: { - if (root.seconds != 0) { - root.seconds--; - } - if (root.seconds == 0) { - root.running = false; - - if (showNotification) { - root.createNotification(); - } - if (runCommand) { - TimerPlasmoid.Timer.runCommand(command); - } - saveTimer(); - } - } - repeat: true; - running: root.running; - } - - Timer { - id: delayedSaveTimer; - interval: 3000; - onTriggered: saveTimer(); - } - Column { anchors.centerIn: parent; Text { id: titleLabel; text: root.title; visible: root.showTitle; horizontalAlignment: Text.AlignHCenter font.pixelSize: parent.parent.height - digitH; } Row { id: timerDigits; SequentialAnimation on opacity { running: root.suspended; loops: Animation.Infinite; NumberAnimation { duration: 800; from: 1.0; to: 0.2; easing.type: Easing.InOutQuad; } PauseAnimation { duration: 400; } NumberAnimation { duration: 800; from: 0.2; to: 1.0; easing.type: Easing.InOutQuad; } PauseAnimation { duration: 400; } } TimerDigit { meaning: 60*60*10; num: ~~((root.seconds / (60*60)) / 10); suffix: (root.running && root.seconds < 60) ? "_1" : ""; } TimerDigit { meaning: 60*60; num: ~~(~~(root.seconds / (60*60))) % 10; suffix: (root.running && root.seconds < 60) ? "_1" : ""; } PlasmaCore.SvgItem { svg: timerSvg; width: digitW / 2; height: digitH; elementId: "separator" + ((root.running && root.seconds < 60) ? "_1" : ""); } TimerDigit { meaning: 600; num: ~~(~~((root.seconds % (60*60)) / 60) / 10); suffix: (root.running && root.seconds < 60) ? "_1" : ""; } TimerDigit { meaning: 60; num: ~~((root.seconds % (60*60)) / 60) % 10; suffix: (root.running && root.seconds < 60) ? "_1" : ""; } PlasmaCore.SvgItem { svg: timerSvg; width: digitW / 2; height: digitH; elementId: "separator" + ((root.running && root.seconds < 60) ? "_1" : ""); visible: showSeconds; } TimerDigit { meaning: 10; num: ~~((root.seconds % 60) / 10); suffix: (root.running && root.seconds < 60) ? "_1" : ""; visible: showSeconds; } TimerDigit { meaning: 1; num: (root.seconds % 60) % 10; suffix: (root.running && root.seconds < 60) ? "_1" : ""; visible: showSeconds; } } } MouseArea { anchors.fill: parent; onClicked: { if (root.running) { root.stopTimer(); } else { root.startTimer(); } } PlasmaCore.ToolTipArea { anchors.fill: parent subText: root.running ? i18n("Timer is running") : i18n("Use mouse wheel to change digits or choose from predefined timers in the context menu"); } } - function digitChanged() { - delayedSaveTimer.stop(); - delayedSaveTimer.start(); - } - function resetOpacity() { timerDigits.opacity = 1.0; } Component.onCompleted: { root.opacityNeedsReset.connect(resetOpacity); - root.digitHasChanged.connect(digitChanged); } } diff --git a/applets/timer/package/contents/ui/main.qml b/applets/timer/package/contents/ui/main.qml index 44f8ec56f..e9a5b25ca 100644 --- a/applets/timer/package/contents/ui/main.qml +++ b/applets/timer/package/contents/ui/main.qml @@ -1,165 +1,206 @@ /*************************************************************************** * Copyright 2016 Michael Abrahams * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 2.2 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 as QtExtra +import org.kde.plasma.private.timer 0.1 as TimerPlasmoid Item { id: root; property variant predefinedTimers: plasmoid.configuration.predefinedTimers; property int seconds : restoreToSeconds(plasmoid.configuration.running, plasmoid.configuration.savedAt, plasmoid.configuration.seconds); + // show notification on timer completion (default: enabled) + property bool showNotification: plasmoid.configuration.showNotification; + // run custom command on timer completion (default: disabled) + property bool runCommand: plasmoid.configuration.runCommand; + property string command: plasmoid.configuration.command; + // show title (can be customized in the settings dialog, default: disabled) property bool showTitle: plasmoid.configuration.showTitle; property string title: plasmoid.configuration.title; property bool running: (plasmoid.configuration.running > 0) ? true : false; property bool suspended: false; property string notificationText: plasmoid.configuration.notificationText; Plasmoid.toolTipMainText: { var timerName = ""; if (showTitle && title != "") { timerName = title; } else { timerName = i18n("Timer"); } var toolTipText = ""; if (running) { toolTipText = i18n("%1 is running", timerName); } else { toolTipText = i18n("%1 not running", timerName); } return toolTipText; } Plasmoid.toolTipSubText: i18np("Remaining time left: %1 second", "Remaining time left: %1 seconds", seconds); Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation Plasmoid.compactRepresentation: TimerView { } Plasmoid.fullRepresentation: TimerView { } PlasmaCore.DataSource { id: notificationSource engine: "notifications" connectedSources: "org.freedesktop.Notifications" } + Timer { + id: t; + interval: 1000; + onTriggered: { + if (root.seconds != 0) { + root.seconds--; + } + if (root.seconds == 0) { + root.running = false; + + if (showNotification) { + root.createNotification(); + } + if (runCommand) { + TimerPlasmoid.Timer.runCommand(command); + } + saveTimer(); + } + } + repeat: true; + running: root.running; + } + + Timer { + id: delayedSaveTimer; + interval: 3000; + onTriggered: saveTimer(); + } + + function onDigitHasChanged() { + delayedSaveTimer.stop(); + delayedSaveTimer.start(); + } + function createNotification() { var service = notificationSource.serviceForSource("notification"); var operation = service.operationDescription("createNotification"); operation.appName = root.title || i18n("Timer"); operation["appIcon"] = "chronometer"; operation.summary = notificationText || i18n("Timer finished") operation["body"] = ""; operation["timeout"] = 2000; service.startOperationCall(operation); } Component.onCompleted: { plasmoid.setAction("timerStart", i18n("&Start")); plasmoid.setAction("timerStop", i18n("S&top")); plasmoid.setAction("timerReset", i18n("&Reset")); plasmoid.setActionSeparator("separator0"); for (var predefinedTimer in plasmoid.configuration.predefinedTimers) { plasmoid.setAction("predefined_timer_" + plasmoid.configuration.predefinedTimers[predefinedTimer], secondsToDisplayableString(plasmoid.configuration.predefinedTimers[predefinedTimer])); } plasmoid.setActionSeparator("separator1"); } function secondsToDisplayableString(sec) { return ~~((sec / (60*60)) / 10) + "" + (~~(~~(sec / (60*60))) % 10) + ":" + ~~(~~((sec % (60*60)) / 60) / 10) + "" + ~~((sec % (60*60)) / 60) % 10 + ":" + ~~((sec % 60) / 10) + "" + (sec % 60) % 10; } function startTimer() { running = true; suspended = false; // timerDigits.opacity = 1.0; saveTimer(); } function stopTimer() { running = false; suspended = true; saveTimer(); } function resetTimer() { running = false; suspended = false; seconds = 0; saveTimer(); } signal opacityNeedsReset() signal digitHasChanged() function saveTimer() { plasmoid.configuration.running = running ? seconds : 0; plasmoid.configuration.savedAt = new Date(); plasmoid.configuration.seconds = seconds } function actionTriggered(actionName) { if (actionName.indexOf("predefined_timer_") == 0) { seconds = actionName.replace("predefined_timer_", ""); startTimer(); } } function restoreToSeconds(cRunning, cSavedAt, cSeconds) { if (cRunning > 0) { var elapsedSeconds = cRunning - ~~(~~(((new Date()).getTime() - cSavedAt.getTime()) / 1000)); if (elapsedSeconds >= 0) { return elapsedSeconds; } else { return 0; } } else { return cSeconds; } } function action_timerStart() { startTimer(); } function action_timerStop() { stopTimer(); } function action_timerReset() { resetTimer(); } }