-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHintConfirmDialog.qml
More file actions
159 lines (140 loc) · 5.18 KB
/
Copy pathHintConfirmDialog.qml
File metadata and controls
159 lines (140 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import QtQuick
import qs.Commons
import qs.Ui
// Confirm dialog with hotkey hints stacked under button labels
// (avoids wide single-line buttons overflowing the card).
Item {
id: root
property bool opened: false
property string message: ""
property string cancelText: "Cancel"
property string confirmText: "Confirm"
property string cancelHint: "Esc"
property string confirmHint: "Ctrl+Enter"
property int selectedIndex: 1
property color background: Color.background
property color foreground: Color.foreground
property color scrim: Util.alpha(Color.background, 0.7)
property color selectedBackground: Util.alpha(Color.foreground, 0.08)
property color selectedText: Color.accent
property string fontFamily: Style.font.family
property int cornerRadius: Style.cornerRadius
signal canceled()
signal confirmed()
function handleKey(event) {
if (!root.opened) return false
if (event.key === Qt.Key_Escape) {
root.canceled()
return true
}
if (event.key === Qt.Key_Left || event.key === Qt.Key_Right
|| event.key === Qt.Key_Tab || event.key === Qt.Key_Backtab) {
root.selectedIndex = root.selectedIndex === 0 ? 1 : 0
return true
}
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
if (root.selectedIndex === 0) root.canceled()
else root.confirmed()
return true
}
return false
}
visible: opened
z: 20
Rectangle {
anchors.fill: parent
color: root.scrim
MouseArea { anchors.fill: parent; onClicked: root.canceled() }
BorderSurface {
id: card
width: Math.min(parent.width - Style.space(32), Style.space(370))
height: card.contentTopInset + card.contentBottomInset
+ messageText.implicitHeight + Style.space(20)
+ Math.max(Style.space(44), Style.space(44))
anchors.centerIn: parent
color: root.background
borderSpec: Border.flat(root.selectedText, Style.normalBorderWidth)
padding: Style.space(18)
radius: root.cornerRadius
MouseArea { anchors.fill: parent; onClicked: {} }
Item {
anchors.fill: parent
anchors.topMargin: card.contentTopInset
anchors.rightMargin: card.contentRightInset
anchors.bottomMargin: card.contentBottomInset
anchors.leftMargin: card.contentLeftInset
Text {
id: messageText
textFormat: Text.PlainText
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
text: root.message
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.title
wrapMode: Text.WordWrap
}
Row {
anchors.right: parent.right
anchors.bottom: parent.bottom
spacing: Style.space(10)
Repeater {
model: [
{ label: root.cancelText, hint: root.cancelHint, action: "cancel" },
{ label: root.confirmText, hint: root.confirmHint, action: "confirm" }
]
BorderSurface {
required property int index
required property var modelData
readonly property bool selected: root.selectedIndex === index
readonly property bool destructive: index === 1
width: Math.max(Style.space(88), btnCol.implicitWidth + Style.space(20))
height: Math.max(Style.space(44), btnCol.implicitHeight + Style.space(10))
color: selected
? (destructive ? Util.alpha(Color.urgent, 0.22) : root.selectedBackground)
: "transparent"
borderSpec: Border.flat(destructive
? (selected ? Color.urgent : Util.alpha(Color.urgent, 0.56))
: (selected ? root.selectedText : Util.alpha(root.foreground, 0.38)), Style.normalBorderWidth)
radius: 0
Column {
id: btnCol
anchors.centerIn: parent
spacing: Style.space(1)
Text {
textFormat: Text.PlainText
anchors.horizontalCenter: parent.horizontalCenter
text: modelData.label
color: destructive
? (selected ? Color.urgent : root.foreground)
: (selected ? root.selectedText : root.foreground)
font.family: root.fontFamily
font.pixelSize: Style.font.caption
}
Text {
textFormat: Text.PlainText
anchors.horizontalCenter: parent.horizontalCenter
text: modelData.hint
color: Qt.darker(root.foreground, 1.45)
font.family: root.fontFamily
font.pixelSize: Style.font.caption * 0.85
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: root.selectedIndex = index
onClicked: {
if (index === 0) root.canceled()
else root.confirmed()
}
}
}
}
}
}
}
}
}