Compare commits

..

No commits in common. "ee23554cb41c9294ced048d5a1241fa1abbb4ca7" and "1a21cd7b315d9ab664fc26fb2ed0ac0282791863" have entirely different histories.

10 changed files with 227 additions and 730 deletions

View File

@ -151,7 +151,7 @@ FluObject{
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }
} }
FluPaneItem{ FluPaneItem{
title:"ShortcutPicker" title:"ShortcutPicker(ToDo)"
menuDelegate: paneItemMenu menuDelegate: paneItemMenu
url:"qrc:/example/qml/page/T_ShortcutPicker.qml" url:"qrc:/example/qml/page/T_ShortcutPicker.qml"
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }

View File

@ -115,68 +115,4 @@ FluScrollablePage{
showSuccess("点击最小化按钮") showSuccess("点击最小化按钮")
} }
} }
FluArea{
Layout.fillWidth: true
height: 68
paddings: 10
Layout.topMargin: 20
FluButton{
anchors.verticalCenter: parent.verticalCenter
Layout.topMargin: 20
text:"Custom Content Dialog"
onClicked: {
custom_btn_dialog.open()
}
}
}
CodeExpander{
Layout.fillWidth: true
Layout.topMargin: -1
code:'FluContentDialog{
id:dialog
title:"友情提示"
message:"数据正在加载中,请稍等..."
negativeText:"取消加载"
contentDelegate: Component{
Item{
width: parent.width
height: 80
FluProgressRing{
anchors.centerIn: parent
}
}
}
onNegativeClicked:{
showSuccess("点击取消按钮")
}
positiveText:"确定"
onPositiveClicked:{
showSuccess("点击确定按钮")
}
dialog.open()'
}
FluContentDialog{
id:custom_btn_dialog
title:"友情提示"
message:"数据正在加载中,请稍等..."
negativeText:"取消加载"
contentDelegate: Component{
Item{
width: parent.width
height: 80
FluProgressRing{
anchors.centerIn: parent
}
}
}
onNegativeClicked:{
showSuccess("点击取消按钮")
}
positiveText:"确定"
onPositiveClicked:{
showSuccess("点击确定按钮")
}
}
} }

View File

@ -77,14 +77,6 @@ FluWindow {
} }
} }
Timer{
id:timer_window_hide_delay
interval: 150
onTriggered: {
window.hide()
}
}
FluContentDialog{ FluContentDialog{
id:dialog_close id:dialog_close
title:"退出" title:"退出"
@ -92,8 +84,8 @@ FluWindow {
negativeText:"最小化" negativeText:"最小化"
buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.NeutralButton | FluContentDialogType.PositiveButton buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.NeutralButton | FluContentDialogType.PositiveButton
onNegativeClicked:{ onNegativeClicked:{
window.hide()
system_tray.showMessage("友情提示","FluentUI已隐藏至托盘,点击托盘可再次激活窗口"); system_tray.showMessage("友情提示","FluentUI已隐藏至托盘,点击托盘可再次激活窗口");
timer_window_hide_delay.restart()
} }
positiveText:"退出" positiveText:"退出"
neutralText:"取消" neutralText:"取消"

View File

@ -151,7 +151,7 @@ FluObject{
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }
} }
FluPaneItem{ FluPaneItem{
title:"ShortcutPicker" title:"ShortcutPicker(ToDo)"
menuDelegate: paneItemMenu menuDelegate: paneItemMenu
url:"qrc:/example/qml/page/T_ShortcutPicker.qml" url:"qrc:/example/qml/page/T_ShortcutPicker.qml"
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }

View File

@ -116,68 +116,4 @@ FluScrollablePage{
showSuccess("点击最小化按钮") showSuccess("点击最小化按钮")
} }
} }
FluArea{
Layout.fillWidth: true
height: 68
paddings: 10
Layout.topMargin: 20
FluButton{
anchors.verticalCenter: parent.verticalCenter
Layout.topMargin: 20
text:"Custom Content Dialog"
onClicked: {
custom_btn_dialog.open()
}
}
}
CodeExpander{
Layout.fillWidth: true
Layout.topMargin: -1
code:'FluContentDialog{
id:dialog
title:"友情提示"
message:"数据正在加载中,请稍等..."
negativeText:"取消加载"
contentDelegate: Component{
Item{
width: parent.width
height: 80
FluProgressRing{
anchors.centerIn: parent
}
}
}
onNegativeClicked:{
showSuccess("点击取消按钮")
}
positiveText:"确定"
onPositiveClicked:{
showSuccess("点击确定按钮")
}
dialog.open()'
}
FluContentDialog{
id:custom_btn_dialog
title:"友情提示"
message:"数据正在加载中,请稍等..."
negativeText:"取消加载"
contentDelegate: Component{
Item{
width: parent.width
height: 80
FluProgressRing{
anchors.centerIn: parent
}
}
}
onNegativeClicked:{
showSuccess("点击取消按钮")
}
positiveText:"确定"
onPositiveClicked:{
showSuccess("点击确定按钮")
}
}
} }

View File

@ -80,14 +80,6 @@ FluWindow {
} }
} }
Timer{
id:timer_window_hide_delay
interval: 150
onTriggered: {
window.hide()
}
}
FluContentDialog{ FluContentDialog{
id:dialog_close id:dialog_close
title:"退出" title:"退出"
@ -95,8 +87,8 @@ FluWindow {
negativeText:"最小化" negativeText:"最小化"
buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.NeutralButton | FluContentDialogType.PositiveButton buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.NeutralButton | FluContentDialogType.PositiveButton
onNegativeClicked:{ onNegativeClicked:{
window.hide()
system_tray.showMessage("友情提示","FluentUI已隐藏至托盘,点击托盘可再次激活窗口"); system_tray.showMessage("友情提示","FluentUI已隐藏至托盘,点击托盘可再次激活窗口");
timer_window_hide_delay.restart()
} }
positiveText:"退出" positiveText:"退出"
neutralText:"取消" neutralText:"取消"

View File

@ -5,37 +5,51 @@ import QtQuick.Window 2.15
import FluentUI 1.0 import FluentUI 1.0
FluPopup { FluPopup {
id: control id: popup
property string title: "" property string title: "Title"
property string message: "" property string message: "Message"
property string neutralText: "Neutral" property string neutralText: "Neutral"
property string negativeText: "Negative" property string negativeText: "Negative"
property string positiveText: "Positive" property string positiveText: "Positive"
property int messageTextFormart: Text.AutoText property alias messageTextFormart: text_message.textFormat
property int delayTime: 100 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 neutralClicked
signal negativeClicked signal negativeClicked
signal positiveClicked signal positiveClicked
implicitWidth: 400 property int buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton
implicitHeight: layout_content.height
focus: true focus: true
Component{ implicitWidth: 400
id:com_message 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
}
}
Flickable{ Flickable{
id:sroll_message id:sroll_message
contentHeight: text_message.height
contentWidth: width contentWidth: width
clip: true clip: true
anchors{
top:text_title.bottom
left: parent.left
right: parent.right
}
boundsBehavior:Flickable.StopAtBounds boundsBehavior:Flickable.StopAtBounds
width: parent.width contentHeight: text_message.height
height: Math.min(text_message.height,300) height: Math.min(text_message.height,300)
ScrollBar.vertical: FluScrollBar {} ScrollBar.vertical: FluScrollBar {}
FluText{ FluText{
@ -44,47 +58,22 @@ FluPopup {
wrapMode: Text.WrapAnywhere wrapMode: Text.WrapAnywhere
text:message text:message
width: parent.width width: parent.width
topPadding: 4 topPadding: 14
leftPadding: 20 leftPadding: 20
rightPadding: 20 rightPadding: 20
bottomPadding: 4 bottomPadding: 14
} }
} }
}
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
}
FluLoader{
sourceComponent: com_message
Layout.fillWidth: true
Layout.preferredHeight: status===Loader.Ready ? item.height : 0
}
FluLoader{
sourceComponent: control.contentDelegate
Layout.fillWidth: true
Layout.preferredHeight: status===Loader.Ready ? item.height : 0
}
Rectangle{ Rectangle{
id:layout_actions id:layout_actions
Layout.fillWidth: true height: 60
Layout.preferredHeight: 60
radius: 5 radius: 5
color: FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1) 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{ RowLayout{
anchors anchors
{ {
@ -92,65 +81,56 @@ FluPopup {
margins: spacing margins: spacing
fill: parent fill: parent
} }
spacing: 10 spacing: 15
Item{
Layout.fillWidth: true
Layout.fillHeight: true
visible: control.buttonFlags&FluContentDialogType.NeutralButton
FluButton{ FluButton{
id:neutral_btn id:neutral_btn
text: neutralText
width: parent.width
anchors.centerIn: parent
onClicked: {
if(control.onNeutralClickListener){
control.onNeutralClickListener()
}else{
neutralClicked()
control.close()
}
}
}
}
Item{
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true visible: popup.buttonFlags&FluContentDialogType.NeutralButton
visible: control.buttonFlags&FluContentDialogType.NegativeButton text: neutralText
onClicked: {
popup.close()
timer_delay.targetFlags = FluContentDialogType.NeutralButton
timer_delay.restart()
}
}
FluButton{ FluButton{
id:negative_btn id:negative_btn
width: parent.width Layout.fillWidth: true
anchors.centerIn: parent visible: popup.buttonFlags&FluContentDialogType.NegativeButton
text: negativeText text: negativeText
onClicked: { onClicked: {
if(control.onNegativeClickListener){ popup.close()
control.onNegativeClickListener() timer_delay.targetFlags = FluContentDialogType.NegativeButton
}else{ timer_delay.restart()
negativeClicked()
control.close()
} }
} }
}
}
Item{
Layout.fillWidth: true
Layout.fillHeight: true
visible: control.buttonFlags&FluContentDialogType.PositiveButton
FluFilledButton{ FluFilledButton{
id:positive_btn id:positive_btn
Layout.fillWidth: true
visible: popup.buttonFlags&FluContentDialogType.PositiveButton
text: positiveText text: positiveText
width: parent.width
anchors.centerIn: parent
onClicked: { onClicked: {
if(control.onPositiveClickListener){ popup.close()
control.onPositiveClickListener() timer_delay.targetFlags = FluContentDialogType.PositiveButton
}else{ timer_delay.restart()
}
}
}
}
}
Timer{
property int targetFlags
id:timer_delay
interval: popup.delayTime
onTriggered: {
if(targetFlags === FluContentDialogType.NegativeButton){
negativeClicked()
}
if(targetFlags === FluContentDialogType.NeutralButton){
neutralClicked()
}
if(targetFlags === FluContentDialogType.PositiveButton){
positiveClicked() positiveClicked()
control.close()
}
}
}
}
}
} }
} }
} }

View File

@ -3,115 +3,9 @@ import QtQuick.Controls 2.15
import FluentUI 1.0 import FluentUI 1.0
FluIconButton { FluIconButton {
id:control 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{ background: Rectangle{
border.color: FluTheme.dark ? "#505050" : "#DFDFDF" border.color: FluTheme.dark ? "#505050" : "#DFDFDF"
border.width: 1 border.width: 1
@ -123,6 +17,7 @@ FluIconButton {
visible: control.activeFocus visible: control.activeFocus
} }
} }
component ItemKey:Rectangle{ component ItemKey:Rectangle{
id:item_key_control id:item_key_control
property string text : "" property string text : ""
@ -138,15 +33,16 @@ FluIconButton {
anchors.centerIn: parent anchors.centerIn: parent
} }
} }
Row{ Row{
id:layout_row id:layout_row
spacing: 5 spacing: 5
anchors.centerIn: parent anchors.centerIn: parent
Repeater{ ItemKey{
model: control.current text:"Ctrl"
delegate: ItemKey{
text: modelData
} }
ItemKey{
text:"A"
} }
Item{ Item{
width: 3 width: 3
@ -159,72 +55,16 @@ FluIconButton {
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
} }
} }
FluContentDialog{ FluContentDialog{
id:content_dialog 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: {
if(visible){
content_dialog.keysModel = control.current
}
}
onPositiveClicked: {
control.current = content_dialog.keysModel
control.accepted()
}
onNegativeClickListener: function(){
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: { onClicked: {
content_dialog.open() content_dialog.open()
} }
} }

View File

@ -5,37 +5,51 @@ import QtQuick.Window
import FluentUI import FluentUI
FluPopup { FluPopup {
id: control id: popup
property string title: "" property string title: "Title"
property string message: "" property string message: "Message"
property string neutralText: "Neutral" property string neutralText: "Neutral"
property string negativeText: "Negative" property string negativeText: "Negative"
property string positiveText: "Positive" property string positiveText: "Positive"
property int messageTextFormart: Text.AutoText property alias messageTextFormart: text_message.textFormat
property int delayTime: 100 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 neutralClicked
signal negativeClicked signal negativeClicked
signal positiveClicked signal positiveClicked
implicitWidth: 400 property int buttonFlags: FluContentDialogType.NegativeButton | FluContentDialogType.PositiveButton
implicitHeight: layout_content.height
focus: true focus: true
Component{ implicitWidth: 400
id:com_message 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
}
}
Flickable{ Flickable{
id:sroll_message id:sroll_message
contentHeight: text_message.height
contentWidth: width contentWidth: width
clip: true clip: true
anchors{
top:text_title.bottom
left: parent.left
right: parent.right
}
boundsBehavior:Flickable.StopAtBounds boundsBehavior:Flickable.StopAtBounds
width: parent.width contentHeight: text_message.height
height: Math.min(text_message.height,300) height: Math.min(text_message.height,300)
ScrollBar.vertical: FluScrollBar {} ScrollBar.vertical: FluScrollBar {}
FluText{ FluText{
@ -44,47 +58,22 @@ FluPopup {
wrapMode: Text.WrapAnywhere wrapMode: Text.WrapAnywhere
text:message text:message
width: parent.width width: parent.width
topPadding: 4 topPadding: 14
leftPadding: 20 leftPadding: 20
rightPadding: 20 rightPadding: 20
bottomPadding: 4 bottomPadding: 14
} }
} }
}
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
}
FluLoader{
sourceComponent: com_message
Layout.fillWidth: true
Layout.preferredHeight: status===Loader.Ready ? item.height : 0
}
FluLoader{
sourceComponent: control.contentDelegate
Layout.fillWidth: true
Layout.preferredHeight: status===Loader.Ready ? item.height : 0
}
Rectangle{ Rectangle{
id:layout_actions id:layout_actions
Layout.fillWidth: true height: 60
Layout.preferredHeight: 60
radius: 5 radius: 5
color: FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1) 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{ RowLayout{
anchors anchors
{ {
@ -92,65 +81,56 @@ FluPopup {
margins: spacing margins: spacing
fill: parent fill: parent
} }
spacing: 10 spacing: 15
Item{
Layout.fillWidth: true
Layout.fillHeight: true
visible: control.buttonFlags&FluContentDialogType.NeutralButton
FluButton{ FluButton{
id:neutral_btn id:neutral_btn
text: neutralText
width: parent.width
anchors.centerIn: parent
onClicked: {
if(control.onNeutralClickListener){
control.onNeutralClickListener()
}else{
neutralClicked()
control.close()
}
}
}
}
Item{
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true visible: popup.buttonFlags&FluContentDialogType.NeutralButton
visible: control.buttonFlags&FluContentDialogType.NegativeButton text: neutralText
onClicked: {
popup.close()
timer_delay.targetFlags = FluContentDialogType.NeutralButton
timer_delay.restart()
}
}
FluButton{ FluButton{
id:negative_btn id:negative_btn
width: parent.width Layout.fillWidth: true
anchors.centerIn: parent visible: popup.buttonFlags&FluContentDialogType.NegativeButton
text: negativeText text: negativeText
onClicked: { onClicked: {
if(control.onNegativeClickListener){ popup.close()
control.onNegativeClickListener() timer_delay.targetFlags = FluContentDialogType.NegativeButton
}else{ timer_delay.restart()
negativeClicked()
control.close()
} }
} }
}
}
Item{
Layout.fillWidth: true
Layout.fillHeight: true
visible: control.buttonFlags&FluContentDialogType.PositiveButton
FluFilledButton{ FluFilledButton{
id:positive_btn id:positive_btn
Layout.fillWidth: true
visible: popup.buttonFlags&FluContentDialogType.PositiveButton
text: positiveText text: positiveText
width: parent.width
anchors.centerIn: parent
onClicked: { onClicked: {
if(control.onPositiveClickListener){ popup.close()
control.onPositiveClickListener() timer_delay.targetFlags = FluContentDialogType.PositiveButton
}else{ timer_delay.restart()
}
}
}
}
}
Timer{
property int targetFlags
id:timer_delay
interval: popup.delayTime
onTriggered: {
if(targetFlags === FluContentDialogType.NegativeButton){
negativeClicked()
}
if(targetFlags === FluContentDialogType.NeutralButton){
neutralClicked()
}
if(targetFlags === FluContentDialogType.PositiveButton){
positiveClicked() positiveClicked()
control.close()
}
}
}
}
}
} }
} }
} }

View File

@ -3,115 +3,9 @@ import QtQuick.Controls
import FluentUI import FluentUI
FluIconButton { FluIconButton {
id:control 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{ background: Rectangle{
border.color: FluTheme.dark ? "#505050" : "#DFDFDF" border.color: FluTheme.dark ? "#505050" : "#DFDFDF"
border.width: 1 border.width: 1
@ -123,6 +17,7 @@ FluIconButton {
visible: control.activeFocus visible: control.activeFocus
} }
} }
component ItemKey:Rectangle{ component ItemKey:Rectangle{
id:item_key_control id:item_key_control
property string text : "" property string text : ""
@ -138,15 +33,16 @@ FluIconButton {
anchors.centerIn: parent anchors.centerIn: parent
} }
} }
Row{ Row{
id:layout_row id:layout_row
spacing: 5 spacing: 5
anchors.centerIn: parent anchors.centerIn: parent
Repeater{ ItemKey{
model: control.current text:"Ctrl"
delegate: ItemKey{
text: modelData
} }
ItemKey{
text:"A"
} }
Item{ Item{
width: 3 width: 3
@ -159,72 +55,17 @@ FluIconButton {
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
} }
} }
FluContentDialog{ FluContentDialog{
id:content_dialog 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: {
if(visible){
content_dialog.keysModel = control.current
}
}
onPositiveClicked: {
control.current = content_dialog.keysModel
control.accepted()
}
onNegativeClickListener: function(){
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: { onClicked: {
content_dialog.open() content_dialog.open()
} }
} }