Skip to content

Commit c3ec490

Browse files
committed
Add CustomDialogButtonBox component
1 parent a6fa69a commit c3ec490

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/uicomponents/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(MODULE_QML_FILES
99
CustomMenu.qml
1010
CustomMenuItem.qml
1111
CustomMenuSeparator.qml
12+
internal/CustomDialogButtonBox.qml
1213
)
1314
set(MODULE_SRC
1415
uicomponentsmodule.cpp
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
import QtQuick
4+
import QtQuick.Controls
5+
import ScratchCPP.Ui
6+
7+
DialogButtonBox {
8+
property color bgColor: /*ThemeEngine.bgColor*/ Material.background
9+
property int radius: 10
10+
signal focusOut()
11+
id: dialogButtonBox
12+
font.capitalization: Font.MixedCase
13+
background: Rectangle {
14+
color: bgColor
15+
radius: radius
16+
}
17+
18+
QtObject {
19+
id: priv
20+
readonly property var standardButtons: [
21+
Dialog.Ok, Dialog.Open, Dialog.Save,
22+
Dialog.Cancel, Dialog.Close, Dialog.Discard,
23+
Dialog.Apply, Dialog.Reset, Dialog.RestoreDefaults,
24+
Dialog.Help, Dialog.SaveAll, Dialog.Yes,
25+
Dialog.YesToAll, Dialog.No, Dialog.NoToAll,
26+
Dialog.Abort, Dialog.Retry, Dialog.Ignore
27+
]
28+
}
29+
30+
function retranslateButtons() {
31+
for (let i = 0; i < priv.standardButtons.length; i++) {
32+
let standardBtn = priv.standardButtons[i];
33+
let button = standardButton(standardBtn);
34+
35+
if (button)
36+
button.text = UiEngine.standardButtonText(standardBtn);
37+
}
38+
}
39+
40+
Connections {
41+
readonly property Item firstButton: dialogButtonBox.contentChildren[0]
42+
target: firstButton
43+
44+
function onActiveFocusChanged() {
45+
if (!firstButton.activeFocus)
46+
focusOut();
47+
}
48+
}
49+
50+
Component.onCompleted: retranslateButtons()
51+
onStandardButtonsChanged: retranslateButtons()
52+
}

0 commit comments

Comments
 (0)