Support button icons when present

Summary:
support button icons.
if there is no icon or is Qt 5.9, the iconItem will stay invisible

Test Plan: tested with ported mediacontroller to PlasmaComponents3

Reviewers: #plasma

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D15164
This commit is contained in:
Marco Martin 2018-09-06 14:06:34 +02:00
parent bedd597560
commit 85cab5772c
2 changed files with 36 additions and 16 deletions

View File

@ -18,6 +18,7 @@
*/
import QtQuick 2.6
import QtQuick.Layouts 1.2
import QtQuick.Templates @QQC2_VERSION@ as T
import org.kde.plasma.core 2.0 as PlasmaCore
import "private" as Private
@ -36,7 +37,15 @@ T.Button {
hoverEnabled: true //Qt.styleHints.useHoverEffects TODO: how to make this work in 5.7?
contentItem: Label {
contentItem: RowLayout {
PlasmaCore.IconItem {
Layout.fillWidth: true
Layout.fillHeight: true
visible: source.length > 0
source: control.icon ? (control.icon.name || control.icon.source) : ""
}
Label {
visible: text.length > 0
text: control.text
font: control.font
opacity: enabled || control.highlighted || control.checked ? 1 : 0.4
@ -45,6 +54,7 @@ T.Button {
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
}
background: Item {
//retrocompatibility with old controls

View File

@ -18,6 +18,7 @@
*/
import QtQuick 2.6
import QtQuick.Layouts 1.2
import QtQuick.Templates @QQC2_VERSION@ as T
import org.kde.plasma.core 2.0 as PlasmaCore
import "private" as Private
@ -38,7 +39,15 @@ T.ToolButton {
flat: true
contentItem: Label {
contentItem: RowLayout {
PlasmaCore.IconItem {
Layout.fillWidth: true
Layout.fillHeight: true
visible: source.length > 0
source: control.icon ? (control.icon.name || control.icon.source) : ""
}
Label {
visible: text.length > 0
text: control.text
font: control.font
opacity: enabled || control.highlighted || control.checked ? 1 : 0.4
@ -47,6 +56,7 @@ T.ToolButton {
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
}
background: Item {
visible: (!control.flat || control.hovered) && (!control.pressed || !control.checked)