Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/DialogButtonBox.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2017 The Qt Company Ltd. 0004 0005 SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later 0006 */ 0007 0008 0009 import QtQuick 0010 import QtQuick.Templates as T 0011 import org.kde.kirigami as Kirigami 0012 0013 T.DialogButtonBox { 0014 id: control 0015 0016 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, 0017 implicitContentWidth + leftPadding + rightPadding) 0018 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, 0019 implicitContentHeight + topPadding + bottomPadding) 0020 0021 contentWidth: (contentItem as ListView)?.contentWidth ?? 0 0022 0023 spacing: Kirigami.Units.mediumSpacing 0024 padding: Kirigami.Units.smallSpacing 0025 alignment: Qt.AlignRight 0026 0027 delegate: Button { 0028 // Round because fractional width values are possible. 0029 width: Math.floor(Math.min( 0030 implicitWidth, 0031 // Divide availableWidth (width - leftPadding - rightPadding) by the number of buttons, 0032 // then subtract the spacing between each button. 0033 ((control.availableWidth - (control.spacing * (control.count - 1))) / control.count) 0034 )) 0035 Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.DialogButton 0036 } 0037 0038 contentItem: ListView { 0039 implicitWidth: contentWidth 0040 implicitHeight: 32 0041 0042 model: control.contentModel 0043 spacing: control.spacing 0044 orientation: ListView.Horizontal 0045 boundsBehavior: Flickable.StopAtBounds 0046 snapMode: ListView.SnapToItem 0047 } 0048 0049 // Standard buttons are destroyed and then recreated every time 0050 // the `standardButtons` property changes, so it is necessary to 0051 // run this code every time standardButtonsChanged() is emitted. 0052 // See QQuickDialogButtonBox::setStandardButtons() 0053 onStandardButtonsChanged: { 0054 // standardButton() returns a pointer to an existing standard button. 0055 // If no such button exists, it returns nullptr. 0056 // Icon names are copied from KStyle::standardIcon() 0057 function setStandardIcon(buttonType, iconName) { 0058 const button = standardButton(buttonType) 0059 if (button && button.icon.name === "" && button.icon.source.toString() === "") { 0060 button.icon.name = iconName 0061 } 0062 } 0063 setStandardIcon(T.Dialog.Ok, "dialog-ok") 0064 setStandardIcon(T.Dialog.Save, "document-save") 0065 setStandardIcon(T.Dialog.SaveAll, "document-save-all") 0066 setStandardIcon(T.Dialog.Open, "document-open") 0067 setStandardIcon(T.Dialog.Yes, "dialog-ok-apply") 0068 setStandardIcon(T.Dialog.YesToAll, "dialog-ok") 0069 setStandardIcon(T.Dialog.No, "dialog-cancel") 0070 setStandardIcon(T.Dialog.NoToAll, "dialog-cancel") 0071 setStandardIcon(T.Dialog.Abort, "dialog-cancel") 0072 setStandardIcon(T.Dialog.Retry, "view-refresh") 0073 setStandardIcon(T.Dialog.Ignore, "dialog-cancel") 0074 setStandardIcon(T.Dialog.Close, "dialog-close") 0075 setStandardIcon(T.Dialog.Cancel, "dialog-cancel") 0076 setStandardIcon(T.Dialog.Discard, "edit-delete") 0077 setStandardIcon(T.Dialog.Help, "help-contents") 0078 setStandardIcon(T.Dialog.Apply, "dialog-ok-apply") 0079 setStandardIcon(T.Dialog.Reset, "edit-undo") 0080 setStandardIcon(T.Dialog.RestoreDefaults, "document-revert") 0081 } 0082 }