Add MnemonicLabel and MnemonicAction components

Looks like i am going to do many Labels and Actions that require
mnemonics, and i do not want to setup the properties everytime.
This commit is contained in:
jordi fita mas 2024-12-21 05:13:46 +01:00
parent 268f4329c0
commit 392d993c8a
5 changed files with 45 additions and 34 deletions

View File

@ -15,6 +15,8 @@ qt_add_qml_module(${PROJECT_NAME}
ErrorNotification.qml ErrorNotification.qml
LoginPage.qml LoginPage.qml
Main.qml Main.qml
MnemonicAction.qml
MnemonicLabel.qml
ReservationsPage.qml ReservationsPage.qml
SelectableLabel.qml SelectableLabel.qml
) )

View File

@ -9,19 +9,9 @@ Page {
title: qsTr("Login") title: qsTr("Login")
ColumnLayout { ColumnLayout {
Label { MnemonicLabel {
id: userLabel buddy: user
mnemonic: qsTr("&User:")
Mnemonic.label: qsTr("&User:")
text: Mnemonic.richTextLabel
Shortcut {
sequence: userLabel.Mnemonic.sequence
onActivated: function () {
user.forceActiveFocus();
}
}
} }
TextField { TextField {
@ -30,19 +20,9 @@ Page {
focus: true focus: true
} }
Label { MnemonicLabel {
id: passwordLabel buddy: password
mnemonic: qsTr("&Password:")
Mnemonic.label: qsTr("&Password:")
text: Mnemonic.richTextLabel
Shortcut {
sequence: passwordLabel.Mnemonic.sequence
onActivated: function () {
password.forceActiveFocus();
}
}
} }
TextField { TextField {
@ -56,12 +36,10 @@ Page {
} }
} }
Action { MnemonicAction {
id: loginAction id: loginAction
Mnemonic.label: qsTr("Log &in") mnemonic: qsTr("Log &in")
shortcut: Mnemonic.sequence
text: Mnemonic.richTextLabel
onTriggered: function () { onTriggered: function () {
Database.open(user.text, password.text); Database.open(user.text, password.text);

12
src/MnemonicAction.qml Normal file
View File

@ -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
}

21
src/MnemonicLabel.qml Normal file
View File

@ -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();
}
}
}

View File

@ -15,13 +15,11 @@ Page {
} }
} }
Action { MnemonicAction {
id: logoutAction id: logoutAction
Mnemonic.label: qsTr("Log &out")
icon.name: "system-log-out" icon.name: "system-log-out"
shortcut: Mnemonic.sequence mnemonic: qsTr("Log &out")
text: Mnemonic.richTextLabel
onTriggered: function () { onTriggered: function () {
Database.close(); Database.close();