[PlasmaComponents3] Honor icon.[name|source] property

Since a checkbox is a subclass of AbstractButton, it can be given an
icon. QWidgets checkboxes will faithfully display this icon, but
PlasmaComponents3 ones will not. They should. :)

I will submit a similar change for the QQC2 checkbox style
to make them consistent.
This commit is contained in:
Nate Graham 2020-07-23 14:38:14 +00:00
parent ab125ac2d5
commit b7ee696250
2 changed files with 39 additions and 12 deletions

View File

@ -18,6 +18,7 @@
*/
import QtQuick 2.6
import QtQuick.Layouts 1.3
import QtQuick.Templates @QQC2_VERSION@ as T
import QtQuick.Controls @QQC2_VERSION@
import org.kde.plasma.core 2.0 as PlasmaCore
@ -32,8 +33,9 @@ T.CheckBox {
indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)
baselineOffset: contentItem.y + contentItem.baselineOffset
padding: 1
spacing: Math.round(units.gridUnit / 8)
leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0
rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0
spacing: units.smallSpacing
hoverEnabled: true
@ -47,10 +49,19 @@ T.CheckBox {
control: control
}
contentItem: Label {
leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0
rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0
contentItem: RowLayout {
opacity: control.enabled ? 1 : 0.6
spacing: units.smallSpacing
PlasmaCore.IconItem {
source: control.icon.name || control.icon.source
visible: source.length > 0
implicitWidth: units.iconSizes.smallMedium
implicitHeight: units.iconSizes.smallMedium
}
Label {
text: control.text
font: control.font
color: PlasmaCore.ColorScope.textColor
@ -59,4 +70,5 @@ T.CheckBox {
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
}
}
}

View File

@ -17,6 +17,21 @@ ComponentBase {
text: "Some awesome checkbox"
}
PlasmaComponents.Label {
text: "icon"
}
PlasmaComponents.CheckBox {
icon.name: "start-here-kde-plasma"
}
PlasmaComponents.Label {
text: "text plus icon"
}
PlasmaComponents.CheckBox {
text: "text"
icon.name: "start-here-kde-plasma"
}
PlasmaComponents.Label {
text: "focus"
}