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,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 {

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,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 {