diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e054d32..82ede0f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,8 @@ qt_add_qml_module(${PROJECT_NAME} ErrorNotification.qml LoginPage.qml Main.qml + MnemonicAction.qml + MnemonicLabel.qml ReservationsPage.qml SelectableLabel.qml ) diff --git a/src/LoginPage.qml b/src/LoginPage.qml index 443b7e3..9f420b9 100644 --- a/src/LoginPage.qml +++ b/src/LoginPage.qml @@ -9,19 +9,9 @@ Page { title: qsTr("Login") ColumnLayout { - Label { - id: userLabel - - Mnemonic.label: qsTr("&User:") - text: Mnemonic.richTextLabel - - Shortcut { - sequence: userLabel.Mnemonic.sequence - - onActivated: function () { - user.forceActiveFocus(); - } - } + MnemonicLabel { + buddy: user + mnemonic: qsTr("&User:") } TextField { @@ -30,19 +20,9 @@ Page { focus: true } - Label { - id: passwordLabel - - Mnemonic.label: qsTr("&Password:") - text: Mnemonic.richTextLabel - - Shortcut { - sequence: passwordLabel.Mnemonic.sequence - - onActivated: function () { - password.forceActiveFocus(); - } - } + MnemonicLabel { + buddy: password + mnemonic: qsTr("&Password:") } TextField { @@ -56,12 +36,10 @@ Page { } } - Action { + MnemonicAction { id: loginAction - Mnemonic.label: qsTr("Log &in") - shortcut: Mnemonic.sequence - text: Mnemonic.richTextLabel + mnemonic: qsTr("Log &in") onTriggered: function () { Database.open(user.text, password.text); diff --git a/src/MnemonicAction.qml b/src/MnemonicAction.qml new file mode 100644 index 0000000..cdf90aa --- /dev/null +++ b/src/MnemonicAction.qml @@ -0,0 +1,12 @@ +import QtQuick +import QtQuick.Controls + +Action { + id: control + + required property string mnemonic + + Mnemonic.label: mnemonic + shortcut: Mnemonic.sequence + text: Mnemonic.richTextLabel +} diff --git a/src/MnemonicLabel.qml b/src/MnemonicLabel.qml new file mode 100644 index 0000000..c1d66f5 --- /dev/null +++ b/src/MnemonicLabel.qml @@ -0,0 +1,21 @@ +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Controls + +Label { + id: control + + required property Item buddy + required property string mnemonic + + Mnemonic.label: control.mnemonic + text: Mnemonic.richTextLabel + + Shortcut { + sequence: control.Mnemonic.sequence + + onActivated: function () { + control.buddy.forceActiveFocus(); + } + } +} diff --git a/src/ReservationsPage.qml b/src/ReservationsPage.qml index 1a063aa..86350d3 100644 --- a/src/ReservationsPage.qml +++ b/src/ReservationsPage.qml @@ -15,13 +15,11 @@ Page { } } - Action { + MnemonicAction { id: logoutAction - Mnemonic.label: qsTr("Log &out") icon.name: "system-log-out" - shortcut: Mnemonic.sequence - text: Mnemonic.richTextLabel + mnemonic: qsTr("Log &out") onTriggered: function () { Database.close();