Add private/ButtonContent.qml for PC3 Buttons and ToolButtons
This allows Buttons and ToolButtons to share almost all of the same code, which prevents unnecessary inconsistencies.
This commit is contained in:
parent
9e9136bddd
commit
7838a4ecc9
@ -35,55 +35,8 @@ T.Button {
|
||||
PlasmaCore.ColorScope.inherit: flat
|
||||
PlasmaCore.ColorScope.colorGroup: flat ? parent.PlasmaCore.ColorScope.colorGroup : PlasmaCore.Theme.ButtonColorGroup
|
||||
|
||||
contentItem: GridLayout {
|
||||
|
||||
/* Even though keyboardFocus is already defined as a property
|
||||
* in the background, it's null when it reaches the contentItem.
|
||||
* That means it has to be created here too unless a solution is found.
|
||||
*/
|
||||
property bool keyboardFocus: control.activeFocus &&
|
||||
(control.focusReason == Qt.TabFocusReason || control.focusReason == Qt.BacktabFocusReason)
|
||||
|
||||
columns: control.display == T.AbstractButton.TextBesideIcon ? 2 : 1
|
||||
|
||||
PlasmaCore.IconItem {
|
||||
id: icon
|
||||
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
Layout.minimumWidth: Math.min(parent.width, parent.height, implicitWidth)
|
||||
Layout.minimumHeight: Math.min(parent.width, parent.height, implicitHeight)
|
||||
|
||||
Layout.maximumWidth: control.icon.width > 0 ? control.icon.width : Number.POSITIVE_INFINITY
|
||||
Layout.maximumHeight: control.icon.height > 0 ? control.icon.height : Number.POSITIVE_INFINITY
|
||||
|
||||
implicitWidth: control.icon.width > 0 ? control.icon.width : units.iconSizes.small
|
||||
implicitHeight: control.icon.height > 0 ? control.icon.height : units.iconSizes.small
|
||||
|
||||
colorGroup: PlasmaCore.Theme.ButtonColorGroup
|
||||
visible: source.length > 0 && control.display !== T.Button.TextOnly
|
||||
source: control.icon ? (control.icon.name || control.icon.source) : ""
|
||||
status: !control.flat && buttonSvg.hasElement("hint-focus-highlighted-background") && contentItem.keyboardFocus && !control.pressed && !control.checked ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal
|
||||
}
|
||||
Label {
|
||||
id: label
|
||||
Layout.fillWidth: true
|
||||
visible: text.length > 0 && control.display !== T.Button.IconOnly
|
||||
text: control.Kirigami.MnemonicData.richTextLabel
|
||||
font: control.font
|
||||
opacity: enabled || control.highlighted || control.checked ? 1 : 0.4
|
||||
color: buttonSvg.hasElement("hint-focus-highlighted-background") && contentItem.keyboardFocus && !control.down ? PlasmaCore.Theme.highlightedTextColor : PlasmaCore.Theme.buttonTextColor
|
||||
horizontalAlignment: control.display !== T.Button.TextUnderIcon && icon.visible ? Text.AlignLeft : Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
PlasmaCore.Svg {
|
||||
id: buttonSvg
|
||||
imagePath: "widgets/button"
|
||||
}
|
||||
contentItem: Private.ButtonContent {
|
||||
labelText: control.Kirigami.MnemonicData.richTextLabel
|
||||
}
|
||||
|
||||
background: Private.ButtonBackground {}
|
||||
|
@ -37,63 +37,8 @@ T.ToolButton {
|
||||
PlasmaCore.ColorScope.inherit: flat
|
||||
PlasmaCore.ColorScope.colorGroup: flat ? parent.PlasmaCore.ColorScope.colorGroup : PlasmaCore.Theme.ButtonColorGroup
|
||||
|
||||
contentItem: GridLayout {
|
||||
|
||||
/* Even though keyboardFocus is already defined as a property
|
||||
* in the background, it's null when it reaches the contentItem.
|
||||
* That means it has to be created here too unless a solution is found.
|
||||
*/
|
||||
property bool keyboardFocus: control.activeFocus &&
|
||||
(control.focusReason == Qt.TabFocusReason || control.focusReason == Qt.BacktabFocusReason)
|
||||
|
||||
columns: control.display == T.AbstractButton.TextBesideIcon ? 2 : 1
|
||||
|
||||
PlasmaCore.IconItem {
|
||||
id: icon
|
||||
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
// The default icon size is smallMedium (22px) which means the
|
||||
// content item will be too large and undesirably increase the size
|
||||
// of the item itself, so we apply negative margins to make it take
|
||||
// up as little space as a small icon would
|
||||
Layout.margins: -((implicitHeight - units.iconSizes.small) / 2)
|
||||
|
||||
Layout.minimumWidth: Math.min(parent.width, parent.height, implicitWidth)
|
||||
Layout.minimumHeight: Math.min(parent.width, parent.height, implicitHeight)
|
||||
|
||||
Layout.maximumWidth: control.icon.width > 0 ? control.icon.width : Number.POSITIVE_INFINITY
|
||||
Layout.maximumHeight: control.icon.height > 0 ? control.icon.height : Number.POSITIVE_INFINITY
|
||||
|
||||
implicitWidth: control.icon.width > 0 ? control.icon.width : units.iconSizes.smallMedium
|
||||
implicitHeight: control.icon.height > 0 ? control.icon.height : units.iconSizes.smallMedium
|
||||
|
||||
colorGroup: PlasmaCore.ColorScope.colorGroup
|
||||
visible: source.length > 0 && control.display !== T.AbstractButton.TextOnly
|
||||
source: control.icon ? (control.icon.name || control.icon.source) : ""
|
||||
status: !control.flat && contentItem.keyboardFocus && !control.pressed && !control.checked ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal
|
||||
}
|
||||
|
||||
Label {
|
||||
id: label
|
||||
Layout.fillWidth: true
|
||||
visible: text.length > 0 && control.display !== T.AbstractButton.IconOnly
|
||||
text: control.Kirigami.MnemonicData.richTextLabel
|
||||
font: control.font
|
||||
opacity: width > 0 ? (enabled || control.highlighted || control.checked ? 1 : 0.4) : 0
|
||||
color: (control.hovered || !control.flat) && buttonsurfaceChecker.usedPrefix != "toolbutton-hover" ? theme.buttonTextColor : PlasmaCore.ColorScope.textColor
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
elide: Text.ElideRight
|
||||
PlasmaCore.FrameSvgItem {
|
||||
id: buttonsurfaceChecker
|
||||
visible: false
|
||||
imagePath: "widgets/button"
|
||||
prefix: control.flat ? ["toolbutton-hover", "normal"] : "normal"
|
||||
}
|
||||
}
|
||||
contentItem: Private.ButtonContent {
|
||||
labelText: control.Kirigami.MnemonicData.richTextLabel
|
||||
}
|
||||
|
||||
background: Private.ButtonBackground {}
|
||||
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
|
||||
* SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
|
||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import QtQuick.Templates @QQC2_VERSION@ as T
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import "../" as PlasmaComponents
|
||||
|
||||
GridLayout {
|
||||
id: root
|
||||
|
||||
property string labelText: ""
|
||||
|
||||
readonly property bool usingFocusBackground: !parent.flat && buttonSvg.hasElement("hint-focus-highlighted-background") && parent.visualFocus && !(parent.pressed || parent.checked)
|
||||
|
||||
PlasmaCore.ColorScope.inherit: true
|
||||
|
||||
columns: parent.display == T.Button.TextBesideIcon ? 2 : 1
|
||||
|
||||
PlasmaCore.IconItem {
|
||||
id: icon
|
||||
|
||||
readonly property int defaultIconSize: root.parent.flat ? PlasmaCore.Units.iconSizes.smallMedium : PlasmaCore.Units.iconSizes.small
|
||||
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
Layout.minimumWidth: Math.min(parent.width, parent.height, implicitWidth)
|
||||
Layout.minimumHeight: Math.min(parent.width, parent.height, implicitHeight)
|
||||
|
||||
Layout.maximumWidth: root.parent.icon.width > 0 ? root.parent.icon.width : Number.POSITIVE_INFINITY
|
||||
Layout.maximumHeight: root.parent.icon.height > 0 ? root.parent.icon.height : Number.POSITIVE_INFINITY
|
||||
|
||||
implicitWidth: root.parent.icon.width > 0 ? root.parent.icon.width : defaultIconSize
|
||||
implicitHeight: root.parent.icon.height > 0 ? root.parent.icon.height : defaultIconSize
|
||||
|
||||
visible: source.length > 0 && root.parent.display !== T.Button.TextOnly
|
||||
source: root.parent.icon ? (root.parent.icon.name || root.parent.icon.source) : ""
|
||||
status: usingFocusBackground ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal
|
||||
}
|
||||
PlasmaComponents.Label {
|
||||
id: label
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
visible: text.length > 0 && root.parent.display !== T.Button.IconOnly
|
||||
text: labelText
|
||||
font: root.parent.font
|
||||
color: usingFocusBackground ? PlasmaCore.ColorScope.highlightedTextColor : PlasmaCore.ColorScope.textColor
|
||||
horizontalAlignment: root.parent.display !== T.Button.TextUnderIcon && icon.visible ? Text.AlignLeft : Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
PlasmaCore.Svg {
|
||||
id: buttonSvg
|
||||
imagePath: "widgets/button"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user