From 2428a38194e915eefa95d3ff16b1d0230203bf6b Mon Sep 17 00:00:00 2001 From: zhuzichu Date: Mon, 4 Dec 2023 17:10:08 +0800 Subject: [PATCH] update FluContentDialog and FluShortcutPicker --- example/qml-Qt6/global/ItemsOriginal.qml | 2 +- example/qml-Qt6/window/MainWindow.qml | 12 +- example/qml/global/ItemsOriginal.qml | 2 +- example/qml/window/MainWindow.qml | 12 +- .../FluentUI/Controls/FluContentDialog.qml | 201 +++++++++--------- .../FluentUI/Controls/FluShortcutPicker.qml | 186 ++++++++++++++-- .../FluentUI/Controls/FluContentDialog.qml | 201 +++++++++--------- .../FluentUI/Controls/FluShortcutPicker.qml | 187 ++++++++++++++-- 8 files changed, 572 insertions(+), 231 deletions(-) diff --git a/example/qml-Qt6/global/ItemsOriginal.qml b/example/qml-Qt6/global/ItemsOriginal.qml index efd16574..5abadcec 100644 --- a/example/qml-Qt6/global/ItemsOriginal.qml +++ b/example/qml-Qt6/global/ItemsOriginal.qml @@ -151,7 +151,7 @@ FluObject{ onTap:{ navigationView.push(url) } } FluPaneItem{ - title:"ShortcutPicker(ToDo)" + title:"ShortcutPicker" menuDelegate: paneItemMenu url:"qrc:/example/qml/page/T_ShortcutPicker.qml" onTap:{ navigationView.push(url) } diff --git a/example/qml-Qt6/window/MainWindow.qml b/example/qml-Qt6/window/MainWindow.qml index 55222ef7..9fffb2f4 100644 --- a/example/qml-Qt6/window/MainWindow.qml +++ b/example/qml-Qt6/window/MainWindow.qml @@ -77,15 +77,23 @@ FluWindow { } } + Timer{ + id:timer_window_hide_delay + interval: 150 + onTriggered: { + window.hide() + } + } + FluContentDialog{ id:dialog_close title:"退出" message:"确定要退出程序吗?" negativeText:"最小化" buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.NeutralButton | FluContentDialogType.PositiveButton - onNegativeClicked:{ - window.hide() + onNegativeClicked: { system_tray.showMessage("友情提示","FluentUI已隐藏至托盘,点击托盘可再次激活窗口"); + timer_window_hide_delay.restart() } positiveText:"退出" neutralText:"取消" diff --git a/example/qml/global/ItemsOriginal.qml b/example/qml/global/ItemsOriginal.qml index e78144bb..6cbe3a73 100644 --- a/example/qml/global/ItemsOriginal.qml +++ b/example/qml/global/ItemsOriginal.qml @@ -151,7 +151,7 @@ FluObject{ onTap:{ navigationView.push(url) } } FluPaneItem{ - title:"ShortcutPicker(ToDo)" + title:"ShortcutPicker" menuDelegate: paneItemMenu url:"qrc:/example/qml/page/T_ShortcutPicker.qml" onTap:{ navigationView.push(url) } diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index 34d63cfd..8efac1b2 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -80,15 +80,23 @@ FluWindow { } } + Timer{ + id:timer_window_hide_delay + interval: 150 + onTriggered: { + window.hide() + } + } + FluContentDialog{ id:dialog_close title:"退出" message:"确定要退出程序吗?" negativeText:"最小化" buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.NeutralButton | FluContentDialogType.PositiveButton - onNegativeClicked:{ - window.hide() + onNegativeClicked: { system_tray.showMessage("友情提示","FluentUI已隐藏至托盘,点击托盘可再次激活窗口"); + timer_window_hide_delay.restart() } positiveText:"退出" neutralText:"取消" diff --git a/src/Qt5/imports/FluentUI/Controls/FluContentDialog.qml b/src/Qt5/imports/FluentUI/Controls/FluContentDialog.qml index 021cc115..0c03c384 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluContentDialog.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluContentDialog.qml @@ -5,51 +5,37 @@ import QtQuick.Window 2.15 import FluentUI 1.0 FluPopup { - id: popup - property string title: "Title" - property string message: "Message" + id: control + property string title: "" + property string message: "" property string neutralText: "Neutral" property string negativeText: "Negative" property string positiveText: "Positive" - property alias messageTextFormart: text_message.textFormat + property int messageTextFormart: Text.AutoText property int delayTime: 100 + property int buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton + property var contentDelegate: Component{ + Item{ + } + } + property var onNeutralClickListener + property var onNegativeClickListener + property var onPositiveClickListener signal neutralClicked signal negativeClicked signal positiveClicked - property int buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton - focus: true implicitWidth: 400 - implicitHeight: text_title.height + sroll_message.height + layout_actions.height - Rectangle { - id:layout_content - anchors.fill: parent - color: 'transparent' - radius:5 - FluText{ - id:text_title - font: FluTextStyle.TitleLarge - text:title - topPadding: 20 - leftPadding: 20 - rightPadding: 20 - wrapMode: Text.WrapAnywhere - anchors{ - top:parent.top - left: parent.left - right: parent.right - } - } + implicitHeight: layout_content.height + focus: true + Component{ + id:com_message Flickable{ id:sroll_message + contentHeight: text_message.height contentWidth: width clip: true - anchors{ - top:text_title.bottom - left: parent.left - right: parent.right - } boundsBehavior:Flickable.StopAtBounds - contentHeight: text_message.height + width: parent.width height: Math.min(text_message.height,300) ScrollBar.vertical: FluScrollBar {} FluText{ @@ -58,79 +44,98 @@ FluPopup { wrapMode: Text.WrapAnywhere text:message width: parent.width - topPadding: 14 + topPadding: 4 leftPadding: 20 rightPadding: 20 - bottomPadding: 14 - } - } - Rectangle{ - id:layout_actions - height: 60 - radius: 5 - color: FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1) - anchors{ - top:sroll_message.bottom - left: parent.left - right: parent.right - } - RowLayout{ - anchors - { - centerIn: parent - margins: spacing - fill: parent - } - spacing: 15 - FluButton{ - id:neutral_btn - Layout.fillWidth: true - visible: popup.buttonFlags&FluContentDialogType.NeutralButton - text: neutralText - onClicked: { - popup.close() - timer_delay.targetFlags = FluContentDialogType.NeutralButton - timer_delay.restart() - } - } - FluButton{ - id:negative_btn - Layout.fillWidth: true - visible: popup.buttonFlags&FluContentDialogType.NegativeButton - text: negativeText - onClicked: { - popup.close() - timer_delay.targetFlags = FluContentDialogType.NegativeButton - timer_delay.restart() - } - } - FluFilledButton{ - id:positive_btn - Layout.fillWidth: true - visible: popup.buttonFlags&FluContentDialogType.PositiveButton - text: positiveText - onClicked: { - popup.close() - timer_delay.targetFlags = FluContentDialogType.PositiveButton - timer_delay.restart() - } - } + bottomPadding: 4 } } } - Timer{ - property int targetFlags - id:timer_delay - interval: popup.delayTime - onTriggered: { - if(targetFlags === FluContentDialogType.NegativeButton){ - negativeClicked() + Rectangle { + id:layout_content + width: parent.width + height: layout_column.childrenRect.height + color: 'transparent' + radius:5 + ColumnLayout{ + id:layout_column + width: parent.width + FluText{ + id:text_title + font: FluTextStyle.Title + text:title + topPadding: 20 + leftPadding: 20 + rightPadding: 20 + wrapMode: Text.WrapAnywhere } - if(targetFlags === FluContentDialogType.NeutralButton){ - neutralClicked() + FluLoader{ + sourceComponent: com_message + Layout.fillWidth: true + Layout.preferredHeight: status===Loader.Ready ? item.height : 0 } - if(targetFlags === FluContentDialogType.PositiveButton){ - positiveClicked() + FluLoader{ + sourceComponent: control.contentDelegate + Layout.fillWidth: true + Layout.preferredHeight: status===Loader.Ready ? item.height : 0 + } + Rectangle{ + id:layout_actions + Layout.fillWidth: true + Layout.preferredHeight: 60 + radius: 5 + color: FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1) + RowLayout{ + anchors + { + centerIn: parent + margins: spacing + fill: parent + } + spacing: 15 + FluButton{ + id:neutral_btn + Layout.fillWidth: true + visible: control.buttonFlags&FluContentDialogType.NeutralButton + text: neutralText + onClicked: { + if(control.onNeutralClickListener){ + control.onNeutralClickListener() + }else{ + neutralClicked() + control.close() + } + } + } + FluButton{ + id:negative_btn + Layout.fillWidth: true + visible: control.buttonFlags&FluContentDialogType.NegativeButton + text: negativeText + onClicked: { + if(control.onNegativeClickListener){ + control.onNegativeClickListener() + }else{ + negativeClicked() + control.close() + } + } + } + FluFilledButton{ + id:positive_btn + Layout.fillWidth: true + visible: control.buttonFlags&FluContentDialogType.PositiveButton + text: positiveText + onClicked: { + if(control.onPositiveClickListener){ + control.onPositiveClickListener() + }else{ + positiveClicked() + control.close() + } + } + } + } } } } diff --git a/src/Qt5/imports/FluentUI/Controls/FluShortcutPicker.qml b/src/Qt5/imports/FluentUI/Controls/FluShortcutPicker.qml index 26bb6885..e70a125c 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluShortcutPicker.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluShortcutPicker.qml @@ -3,9 +3,115 @@ import QtQuick.Controls 2.15 import FluentUI 1.0 FluIconButton { - id:control - + property var current : ["Ctrl","Shift","A"] + property string title: "激活快捷键" + property string message: "按下组合键以更改此快捷键" + property string positiveText: "保存" + property string neutralText: "取消" + property string negativeText: "重置" + signal accepted() + QtObject{ + id: d + function keyToString(key_code,shift = true) + { + switch(key_code) + { + case Qt.Key_Period: return "."; + case Qt.Key_Greater: return shift ? ">" : "."; + case Qt.Key_Comma: return ","; + case Qt.Key_Less: return shift ? "<" : ","; + case Qt.Key_Slash: return "/"; + case Qt.Key_Question: return shift ? "?" : "/"; + case Qt.Key_Semicolon: return ";"; + case Qt.Key_Colon: return shift ? ":" : ";"; + case Qt.Key_Apostrophe: return "'"; + case Qt.Key_QuoteDbl: return shift ? "'" : "\""; + case Qt.Key_QuoteLeft: return "`"; + case Qt.Key_AsciiTilde: return shift ? "~" : "`"; + case Qt.Key_Minus: return "-"; + case Qt.Key_Underscore: return shift ? "_" : "-"; + case Qt.Key_Equal: return "="; + case Qt.Key_Plus: return shift ? "+" : "="; + case Qt.Key_BracketLeft: return "["; + case Qt.Key_BraceLeft: return shift ? "{" : "["; + case Qt.Key_BracketRight: return "]"; + case Qt.Key_BraceRight: return shift ? "}" : "]"; + case Qt.Key_Backslash: return "\\"; + case Qt.Key_Bar: return shift ? "|" : "\\"; + case Qt.Key_Up: return "Up"; + case Qt.Key_Down: return "Down"; + case Qt.Key_Right: return "Right"; + case Qt.Key_Left: return "Left"; + case Qt.Key_Space: return "Space"; + case Qt.Key_PageDown: return "PgDown"; + case Qt.Key_PageUp: return "PgUp"; + case Qt.Key_0: return "0"; + case Qt.Key_1: return "1"; + case Qt.Key_2: return "2"; + case Qt.Key_3: return "3"; + case Qt.Key_4: return "4"; + case Qt.Key_5: return "5"; + case Qt.Key_6: return "6"; + case Qt.Key_7: return "7"; + case Qt.Key_8: return "8"; + case Qt.Key_9: return "9"; + case Qt.Key_Exclam: return shift ? "!" : "1"; + case Qt.Key_At: return shift ? "@" : "2"; + case Qt.Key_NumberSign: return shift ? "#" : "3"; + case Qt.Key_Dollar: return shift ? "$" : "4"; + case Qt.Key_Percent: return shift ? "%" : "5"; + case Qt.Key_AsciiCircum: return shift ? "^" : "6"; + case Qt.Key_Ampersand: return shift ? "&" : "7"; + case Qt.Key_Asterisk: return shift ? "*" : "8"; + case Qt.Key_ParenLeft: return shift ? "(" : "9"; + case Qt.Key_ParenRight: return shift ? ")" : "0"; + case Qt.Key_A: return "A"; + case Qt.Key_B: return "B"; + case Qt.Key_C: return "C"; + case Qt.Key_D: return "D"; + case Qt.Key_E: return "E"; + case Qt.Key_F: return "F"; + case Qt.Key_G: return "G"; + case Qt.Key_H: return "H"; + case Qt.Key_I: return "I"; + case Qt.Key_J: return "J"; + case Qt.Key_K: return "K"; + case Qt.Key_L: return "L"; + case Qt.Key_M: return "M"; + case Qt.Key_N: return "N"; + case Qt.Key_O: return "O"; + case Qt.Key_P: return "P"; + case Qt.Key_Q: return "Q"; + case Qt.Key_R: return "R"; + case Qt.Key_S: return "S"; + case Qt.Key_T: return "T"; + case Qt.Key_U: return "U"; + case Qt.Key_V: return "V"; + case Qt.Key_W: return "W"; + case Qt.Key_X: return "X"; + case Qt.Key_Y: return "Y"; + case Qt.Key_Z: return "Z"; + case Qt.Key_F1: return "F1"; + case Qt.Key_F2: return "F2"; + case Qt.Key_F3: return "F3"; + case Qt.Key_F4: return "F4"; + case Qt.Key_F5: return "F5"; + case Qt.Key_F6: return "F6"; + case Qt.Key_F7: return "F7"; + case Qt.Key_F8: return "F8"; + case Qt.Key_F9: return "F9"; + case Qt.Key_F10: return "F10"; + case Qt.Key_F11: return "F11"; + case Qt.Key_F12: return "F12"; + case Qt.Key_Home: return "Home"; + case Qt.Key_End: return "End"; + case Qt.Key_Insert: return "Insert"; + case Qt.Key_Delete: return "Delete"; + } + return ""; + } + } background: Rectangle{ border.color: FluTheme.dark ? "#505050" : "#DFDFDF" border.width: 1 @@ -17,7 +123,6 @@ FluIconButton { visible: control.activeFocus } } - component ItemKey:Rectangle{ id:item_key_control property string text : "" @@ -33,16 +138,15 @@ FluIconButton { anchors.centerIn: parent } } - Row{ id:layout_row spacing: 5 anchors.centerIn: parent - ItemKey{ - text:"Ctrl" - } - ItemKey{ - text:"A" + Repeater{ + model: control.current + delegate: ItemKey{ + text: modelData + } } Item{ width: 3 @@ -55,16 +159,70 @@ FluIconButton { verticalCenter: parent.verticalCenter } } - } - FluContentDialog{ id:content_dialog - + property var keysModel: [] + title: control.title + message: control.message + buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton | FluContentDialogType.NeutralButton + positiveText: control.positiveText + neutralText: control.neutralText + negativeText: control.negativeText + onVisibleChanged: { + content_dialog.keysModel = control.current + } + onPositiveClicked: { + control.current = content_dialog.keysModel + control.accepted() + } + onNegativeClicked: { + content_dialog.keysModel = control.current + } + contentDelegate: Component{ + Item{ + width: parent.width + height: 100 + Component.onCompleted: { + forceActiveFocus() + } + Keys.enabled: true + Keys.onPressed: { + var keyNames = [] + if (event.modifiers & Qt.AltModifier) { + keyNames.push("Alt") + } + if (event.modifiers & Qt.ControlModifier) { + keyNames.push("Ctrl") + } + if (event.modifiers & Qt.ShiftModifier) { + keyNames.push("Shift") + } + var keyName = d.keyToString(event.key,false) + if(keyName!==""){ + keyNames.push(keyName) + content_dialog.keysModel = keyNames + } + event.accepted = true + } + Keys.onTabPressed: + (event)=>{ + event.accepted = true + } + Row{ + spacing: 5 + anchors.centerIn: parent + Repeater{ + model: content_dialog.keysModel + delegate: ItemKey{ + text: modelData + } + } + } + } + } } - onClicked: { content_dialog.open() } - } diff --git a/src/Qt6/imports/FluentUI/Controls/FluContentDialog.qml b/src/Qt6/imports/FluentUI/Controls/FluContentDialog.qml index 846f957e..74f360ef 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluContentDialog.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluContentDialog.qml @@ -5,51 +5,37 @@ import QtQuick.Window import FluentUI FluPopup { - id: popup - property string title: "Title" - property string message: "Message" + id: control + property string title: "" + property string message: "" property string neutralText: "Neutral" property string negativeText: "Negative" property string positiveText: "Positive" - property alias messageTextFormart: text_message.textFormat + property int messageTextFormart: Text.AutoText property int delayTime: 100 + property int buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton + property var contentDelegate: Component{ + Item{ + } + } + property var onNeutralClickListener + property var onNegativeClickListener + property var onPositiveClickListener signal neutralClicked signal negativeClicked signal positiveClicked - property int buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton - focus: true implicitWidth: 400 - implicitHeight: text_title.height + sroll_message.height + layout_actions.height - Rectangle { - id:layout_content - anchors.fill: parent - color: 'transparent' - radius:5 - FluText{ - id:text_title - font: FluTextStyle.TitleLarge - text:title - topPadding: 20 - leftPadding: 20 - rightPadding: 20 - wrapMode: Text.WrapAnywhere - anchors{ - top:parent.top - left: parent.left - right: parent.right - } - } + implicitHeight: layout_content.height + focus: true + Component{ + id:com_message Flickable{ id:sroll_message + contentHeight: text_message.height contentWidth: width clip: true - anchors{ - top:text_title.bottom - left: parent.left - right: parent.right - } boundsBehavior:Flickable.StopAtBounds - contentHeight: text_message.height + width: parent.width height: Math.min(text_message.height,300) ScrollBar.vertical: FluScrollBar {} FluText{ @@ -58,79 +44,98 @@ FluPopup { wrapMode: Text.WrapAnywhere text:message width: parent.width - topPadding: 14 + topPadding: 4 leftPadding: 20 rightPadding: 20 - bottomPadding: 14 - } - } - Rectangle{ - id:layout_actions - height: 60 - radius: 5 - color: FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1) - anchors{ - top:sroll_message.bottom - left: parent.left - right: parent.right - } - RowLayout{ - anchors - { - centerIn: parent - margins: spacing - fill: parent - } - spacing: 15 - FluButton{ - id:neutral_btn - Layout.fillWidth: true - visible: popup.buttonFlags&FluContentDialogType.NeutralButton - text: neutralText - onClicked: { - popup.close() - timer_delay.targetFlags = FluContentDialogType.NeutralButton - timer_delay.restart() - } - } - FluButton{ - id:negative_btn - Layout.fillWidth: true - visible: popup.buttonFlags&FluContentDialogType.NegativeButton - text: negativeText - onClicked: { - popup.close() - timer_delay.targetFlags = FluContentDialogType.NegativeButton - timer_delay.restart() - } - } - FluFilledButton{ - id:positive_btn - Layout.fillWidth: true - visible: popup.buttonFlags&FluContentDialogType.PositiveButton - text: positiveText - onClicked: { - popup.close() - timer_delay.targetFlags = FluContentDialogType.PositiveButton - timer_delay.restart() - } - } + bottomPadding: 4 } } } - Timer{ - property int targetFlags - id:timer_delay - interval: popup.delayTime - onTriggered: { - if(targetFlags === FluContentDialogType.NegativeButton){ - negativeClicked() + Rectangle { + id:layout_content + width: parent.width + height: layout_column.childrenRect.height + color: 'transparent' + radius:5 + ColumnLayout{ + id:layout_column + width: parent.width + FluText{ + id:text_title + font: FluTextStyle.Title + text:title + topPadding: 20 + leftPadding: 20 + rightPadding: 20 + wrapMode: Text.WrapAnywhere } - if(targetFlags === FluContentDialogType.NeutralButton){ - neutralClicked() + FluLoader{ + sourceComponent: com_message + Layout.fillWidth: true + Layout.preferredHeight: status===Loader.Ready ? item.height : 0 } - if(targetFlags === FluContentDialogType.PositiveButton){ - positiveClicked() + FluLoader{ + sourceComponent: control.contentDelegate + Layout.fillWidth: true + Layout.preferredHeight: status===Loader.Ready ? item.height : 0 + } + Rectangle{ + id:layout_actions + Layout.fillWidth: true + Layout.preferredHeight: 60 + radius: 5 + color: FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1) + RowLayout{ + anchors + { + centerIn: parent + margins: spacing + fill: parent + } + spacing: 15 + FluButton{ + id:neutral_btn + Layout.fillWidth: true + visible: control.buttonFlags&FluContentDialogType.NeutralButton + text: neutralText + onClicked: { + if(control.onNeutralClickListener){ + control.onNeutralClickListener() + }else{ + neutralClicked() + control.close() + } + } + } + FluButton{ + id:negative_btn + Layout.fillWidth: true + visible: control.buttonFlags&FluContentDialogType.NegativeButton + text: negativeText + onClicked: { + if(control.onNegativeClickListener){ + control.onNegativeClickListener() + }else{ + negativeClicked() + control.close() + } + } + } + FluFilledButton{ + id:positive_btn + Layout.fillWidth: true + visible: control.buttonFlags&FluContentDialogType.PositiveButton + text: positiveText + onClicked: { + if(control.onPositiveClickListener){ + control.onPositiveClickListener() + }else{ + positiveClicked() + control.close() + } + } + } + } } } } diff --git a/src/Qt6/imports/FluentUI/Controls/FluShortcutPicker.qml b/src/Qt6/imports/FluentUI/Controls/FluShortcutPicker.qml index c88af3e3..47f89493 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluShortcutPicker.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluShortcutPicker.qml @@ -3,9 +3,115 @@ import QtQuick.Controls import FluentUI FluIconButton { - id:control - + property var current : ["Ctrl","Shift","A"] + property string title: "激活快捷键" + property string message: "按下组合键以更改此快捷键" + property string positiveText: "保存" + property string neutralText: "取消" + property string negativeText: "重置" + signal accepted() + QtObject{ + id: d + function keyToString(key_code,shift = true) + { + switch(key_code) + { + case Qt.Key_Period: return "."; + case Qt.Key_Greater: return shift ? ">" : "."; + case Qt.Key_Comma: return ","; + case Qt.Key_Less: return shift ? "<" : ","; + case Qt.Key_Slash: return "/"; + case Qt.Key_Question: return shift ? "?" : "/"; + case Qt.Key_Semicolon: return ";"; + case Qt.Key_Colon: return shift ? ":" : ";"; + case Qt.Key_Apostrophe: return "'"; + case Qt.Key_QuoteDbl: return shift ? "'" : "\""; + case Qt.Key_QuoteLeft: return "`"; + case Qt.Key_AsciiTilde: return shift ? "~" : "`"; + case Qt.Key_Minus: return "-"; + case Qt.Key_Underscore: return shift ? "_" : "-"; + case Qt.Key_Equal: return "="; + case Qt.Key_Plus: return shift ? "+" : "="; + case Qt.Key_BracketLeft: return "["; + case Qt.Key_BraceLeft: return shift ? "{" : "["; + case Qt.Key_BracketRight: return "]"; + case Qt.Key_BraceRight: return shift ? "}" : "]"; + case Qt.Key_Backslash: return "\\"; + case Qt.Key_Bar: return shift ? "|" : "\\"; + case Qt.Key_Up: return "Up"; + case Qt.Key_Down: return "Down"; + case Qt.Key_Right: return "Right"; + case Qt.Key_Left: return "Left"; + case Qt.Key_Space: return "Space"; + case Qt.Key_PageDown: return "PgDown"; + case Qt.Key_PageUp: return "PgUp"; + case Qt.Key_0: return "0"; + case Qt.Key_1: return "1"; + case Qt.Key_2: return "2"; + case Qt.Key_3: return "3"; + case Qt.Key_4: return "4"; + case Qt.Key_5: return "5"; + case Qt.Key_6: return "6"; + case Qt.Key_7: return "7"; + case Qt.Key_8: return "8"; + case Qt.Key_9: return "9"; + case Qt.Key_Exclam: return shift ? "!" : "1"; + case Qt.Key_At: return shift ? "@" : "2"; + case Qt.Key_NumberSign: return shift ? "#" : "3"; + case Qt.Key_Dollar: return shift ? "$" : "4"; + case Qt.Key_Percent: return shift ? "%" : "5"; + case Qt.Key_AsciiCircum: return shift ? "^" : "6"; + case Qt.Key_Ampersand: return shift ? "&" : "7"; + case Qt.Key_Asterisk: return shift ? "*" : "8"; + case Qt.Key_ParenLeft: return shift ? "(" : "9"; + case Qt.Key_ParenRight: return shift ? ")" : "0"; + case Qt.Key_A: return "A"; + case Qt.Key_B: return "B"; + case Qt.Key_C: return "C"; + case Qt.Key_D: return "D"; + case Qt.Key_E: return "E"; + case Qt.Key_F: return "F"; + case Qt.Key_G: return "G"; + case Qt.Key_H: return "H"; + case Qt.Key_I: return "I"; + case Qt.Key_J: return "J"; + case Qt.Key_K: return "K"; + case Qt.Key_L: return "L"; + case Qt.Key_M: return "M"; + case Qt.Key_N: return "N"; + case Qt.Key_O: return "O"; + case Qt.Key_P: return "P"; + case Qt.Key_Q: return "Q"; + case Qt.Key_R: return "R"; + case Qt.Key_S: return "S"; + case Qt.Key_T: return "T"; + case Qt.Key_U: return "U"; + case Qt.Key_V: return "V"; + case Qt.Key_W: return "W"; + case Qt.Key_X: return "X"; + case Qt.Key_Y: return "Y"; + case Qt.Key_Z: return "Z"; + case Qt.Key_F1: return "F1"; + case Qt.Key_F2: return "F2"; + case Qt.Key_F3: return "F3"; + case Qt.Key_F4: return "F4"; + case Qt.Key_F5: return "F5"; + case Qt.Key_F6: return "F6"; + case Qt.Key_F7: return "F7"; + case Qt.Key_F8: return "F8"; + case Qt.Key_F9: return "F9"; + case Qt.Key_F10: return "F10"; + case Qt.Key_F11: return "F11"; + case Qt.Key_F12: return "F12"; + case Qt.Key_Home: return "Home"; + case Qt.Key_End: return "End"; + case Qt.Key_Insert: return "Insert"; + case Qt.Key_Delete: return "Delete"; + } + return ""; + } + } background: Rectangle{ border.color: FluTheme.dark ? "#505050" : "#DFDFDF" border.width: 1 @@ -17,7 +123,6 @@ FluIconButton { visible: control.activeFocus } } - component ItemKey:Rectangle{ id:item_key_control property string text : "" @@ -33,16 +138,15 @@ FluIconButton { anchors.centerIn: parent } } - Row{ id:layout_row spacing: 5 anchors.centerIn: parent - ItemKey{ - text:"Ctrl" - } - ItemKey{ - text:"A" + Repeater{ + model: control.current + delegate: ItemKey{ + text: modelData + } } Item{ width: 3 @@ -55,17 +159,70 @@ FluIconButton { verticalCenter: parent.verticalCenter } } - } - FluContentDialog{ id:content_dialog - + property var keysModel: [] + title: control.title + message: control.message + buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton | FluContentDialogType.NeutralButton + positiveText: control.positiveText + neutralText: control.neutralText + negativeText: control.negativeText + onVisibleChanged: { + content_dialog.keysModel = control.current + } + onPositiveClicked: { + control.current = content_dialog.keysModel + control.accepted() + } + onNegativeClicked: { + content_dialog.keysModel = control.current + } + contentDelegate: Component{ + Item{ + width: parent.width + height: 100 + Component.onCompleted: { + forceActiveFocus() + } + Keys.enabled: true + Keys.onPressed: { + var keyNames = [] + if (event.modifiers & Qt.AltModifier) { + keyNames.push("Alt") + } + if (event.modifiers & Qt.ControlModifier) { + keyNames.push("Ctrl") + } + if (event.modifiers & Qt.ShiftModifier) { + keyNames.push("Shift") + } + var keyName = d.keyToString(event.key,false) + if(keyName!==""){ + keyNames.push(keyName) + content_dialog.keysModel = keyNames + } + event.accepted = true + } + Keys.onTabPressed: + (event)=>{ + event.accepted = true + } + Row{ + spacing: 5 + anchors.centerIn: parent + Repeater{ + model: content_dialog.keysModel + delegate: ItemKey{ + text: modelData + } + } + } + } + } } - onClicked: { content_dialog.open() } - } -