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