From 85cab5772c560ea248c490d9d58db87296dec06b Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 6 Sep 2018 14:06:34 +0200 Subject: [PATCH] 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 --- .../plasmacomponents3/Button.qml | 26 +++++++++++++------ .../plasmacomponents3/ToolButton.qml | 26 +++++++++++++------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/declarativeimports/plasmacomponents3/Button.qml b/src/declarativeimports/plasmacomponents3/Button.qml index c30648887..3bf58cdde 100644 --- a/src/declarativeimports/plasmacomponents3/Button.qml +++ b/src/declarativeimports/plasmacomponents3/Button.qml @@ -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,14 +37,23 @@ T.Button { hoverEnabled: true //Qt.styleHints.useHoverEffects TODO: how to make this work in 5.7? - contentItem: Label { - text: control.text - font: control.font - opacity: enabled || control.highlighted || control.checked ? 1 : 0.4 - color: theme.buttonTextColor - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight + 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 + color: theme.buttonTextColor + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } } background: Item { diff --git a/src/declarativeimports/plasmacomponents3/ToolButton.qml b/src/declarativeimports/plasmacomponents3/ToolButton.qml index 6a1399e89..2ecf09a03 100644 --- a/src/declarativeimports/plasmacomponents3/ToolButton.qml +++ b/src/declarativeimports/plasmacomponents3/ToolButton.qml @@ -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,14 +39,23 @@ T.ToolButton { flat: true - contentItem: Label { - text: control.text - font: control.font - opacity: enabled || control.highlighted || control.checked ? 1 : 0.4 - color: theme.buttonTextColor - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight + 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 + color: theme.buttonTextColor + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } } background: Item {