Warning, /libraries/kirigami-addons/src/components/MessageDialogButton.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 import QtQuick 0005 import QtQuick.Controls as QQC2 0006 import QtQuick.Templates as T 0007 import QtQuick.Layouts 0008 import org.kde.kirigami as Kirigami 0009 import org.kde.kirigamiaddons.components as Components 0010 import org.kde.kirigamiaddons.delegates as Delegates 0011 0012 QQC2.AbstractButton { 0013 id: root 0014 0015 required property T.DialogButtonBox buttonBox 0016 0017 readonly property int index: { 0018 for (let i = 0; i < buttonBox.count; i++) { 0019 if (buttonBox.contentChildren[i] == root) { 0020 return i; 0021 } 0022 } 0023 return -1; 0024 } 0025 0026 padding: Kirigami.Units.mediumSpacing 0027 0028 implicitWidth: Math.floor(Math.max( 0029 contentItem.implicitWidth, 0030 ((buttonBox.availableWidth - (buttonBox.spacing * (buttonBox.count - 1))) / buttonBox.count) 0031 )) + (index === 0 ? 1 : 0) 0032 0033 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, 0034 implicitContentHeight + topPadding + bottomPadding) 0035 0036 contentItem: Delegates.DefaultContentItem { 0037 itemDelegate: root 0038 labelItem { 0039 horizontalAlignment: Text.AlignHCenter 0040 Accessible.ignored: true 0041 } 0042 } 0043 0044 background: Kirigami.ShadowedRectangle { 0045 corners { 0046 topLeftRadius: 0 0047 bottomLeftRadius: root.index === 0 ? Kirigami.Units.mediumSpacing : 0 0048 0049 bottomRightRadius: root.index === buttonBox.count - 1 ? Kirigami.Units.mediumSpacing : 0 0050 topRightRadius: 0 0051 } 0052 0053 color: { 0054 let backgroundColor; 0055 switch (root.QQC2.DialogButtonBox.buttonRole) { 0056 case QQC2.DialogButtonBox.AcceptRole: 0057 case QQC2.DialogButtonBox.ApplyRole: 0058 backgroundColor = Kirigami.Theme.positiveBackgroundColor; 0059 break; 0060 case QQC2.DialogButtonBox.DestructiveRole: 0061 backgroundColor = Kirigami.Theme.negativeBackgroundColor; 0062 break; 0063 default: 0064 backgroundColor = Kirigami.Theme.backgroundColor; 0065 break; 0066 } 0067 0068 if (root.highlighted || root.checked || (root.down && !root.checked) || root.visualFocus) { 0069 const highlight = Kirigami.ColorUtils.tintWithAlpha(backgroundColor, Kirigami.Theme.highlightColor, 0.3); 0070 if (root.hovered) { 0071 return Kirigami.ColorUtils.tintWithAlpha(highlight, Kirigami.Theme.textColor, 0.10); 0072 } else { 0073 return highlight; 0074 } 0075 } else if (root.hovered) { 0076 return Kirigami.ColorUtils.tintWithAlpha(backgroundColor, Kirigami.Theme.textColor, 0.10); 0077 } else { 0078 return backgroundColor; 0079 } 0080 } 0081 } 0082 }