diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2021-08-27 19:45:41 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-11-23 21:50:58 +0100 |
commit | cd1d46a26b923260b6c87cc93a0723b8166c609e (patch) | |
tree | 81d0fafeaeda6f5d72ec03f589cf8560cea32ed8 /gui/components/VPNButtonBase.qml | |
parent | 76585f828a36c08614df84f43d64e20fb0e7a425 (diff) |
[ui] refactor ui
Diffstat (limited to 'gui/components/VPNButtonBase.qml')
-rw-r--r-- | gui/components/VPNButtonBase.qml | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/gui/components/VPNButtonBase.qml b/gui/components/VPNButtonBase.qml new file mode 100644 index 0000000..6f67710 --- /dev/null +++ b/gui/components/VPNButtonBase.qml @@ -0,0 +1,56 @@ + + +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +import QtQuick 2.0 +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.14 +import "../themes/themes.js" as Theme + +RoundButton { + id: root + + property var visualStateItem: root + property var uiState: Theme.uiState + property var loaderVisible: false + property var handleKeyClick: function () { + clicked() + } + + focusPolicy: Qt.StrongFocus + Keys.onPressed: { + if (loaderVisible) { + return + } + + if (event.key === Qt.Key_Return || event.key === Qt.Key_Space) + visualStateItem.state = uiState.statePressed + } + Keys.onReleased: { + if (loaderVisible) { + return + } + if (event.key === Qt.Key_Return || event.key === Qt.Key_Space) { + visualStateItem.state = uiState.stateDefault + } + if (event.key === Qt.Key_Return) + handleKeyClick() + } + + Accessible.role: Accessible.Button + Accessible.onPressAction: handleKeyClick() + Accessible.focusable: true + + onActiveFocusChanged: { + if (!activeFocus) + return visualStateItem.state = uiState.stateDefault + + if (vpnFlickable && typeof (vpnFlickable.ensureVisible) !== "undefined") + return vpnFlickable.ensureVisible(visualStateItem) + } + + background: Rectangle { + color: "transparent" + } +} |