diff --git a/lookandfeel/contents/logout/Logout.qml b/lookandfeel/contents/logout/Logout.qml --- a/lookandfeel/contents/logout/Logout.qml +++ b/lookandfeel/contents/logout/Logout.qml @@ -26,6 +26,7 @@ import org.kde.kcoreaddons 1.0 as KCoreAddons import "../components" +import "timer.js" as AutoTriggerTimer PlasmaCore.ColorScope { id: root @@ -81,6 +82,11 @@ repeat: true interval: 1000 onTriggered: remainingTime-- + Component.onCompleted: { + AutoTriggerTimer.addCancelAutoTriggerCallback(function() { + countDownTimer.running = false; + }); + } } function isLightColor(color) { diff --git a/lookandfeel/contents/logout/LogoutButton.qml b/lookandfeel/contents/logout/LogoutButton.qml --- a/lookandfeel/contents/logout/LogoutButton.qml +++ b/lookandfeel/contents/logout/LogoutButton.qml @@ -23,6 +23,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore import "../components" +import "timer.js" as AutoTriggerTimer ActionButton { property var action @@ -37,5 +38,5 @@ easing.type: Easing.InOutQuad } } - Keys.onPressed: countDownTimer.running = false + Keys.onPressed: AutoTriggerTimer.cancelAutoTrigger(); } diff --git a/lookandfeel/contents/logout/LogoutButton.qml b/lookandfeel/contents/logout/timer.js copy from lookandfeel/contents/logout/LogoutButton.qml copy to lookandfeel/contents/logout/timer.js --- a/lookandfeel/contents/logout/LogoutButton.qml +++ b/lookandfeel/contents/logout/timer.js @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2016 Marco Martin * + * Copyright (C) 2018 David Edmundson * * * * 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 * @@ -17,25 +17,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ -import QtQuick 2.2 -import QtQuick.Layouts 1.2 +.pragma library -import org.kde.plasma.core 2.0 as PlasmaCore +//written as a library to share knowledge of when a key was pressed +//between the multiple views, so pressing a key on one cancels all timers -import "../components" +var callbacks = []; -ActionButton { - property var action - onClicked: action() - Layout.alignment: Qt.AlignTop - iconSize: units.iconSizes.huge - opacity: activeFocus || containsMouse ? 1 : 0.5 - font.underline: false - Behavior on opacity { - OpacityAnimator { - duration: units.longDuration - easing.type: Easing.InOutQuad +function addCancelAutoTriggerCallback(callback) { + callbacks.push(callback); +} + +function cancelAutoTrigger() { + callbacks.forEach(function(c) { + if (!c) { + return; } - } - Keys.onPressed: countDownTimer.running = false + c(); + }); } +