create arrow on demand, layout it correctly

This commit is contained in:
Marco Martin 2014-07-24 18:29:48 +02:00
parent 9b06cbc392
commit 2e06bb3214
2 changed files with 28 additions and 16 deletions

View File

@ -18,6 +18,7 @@
*/
import QtQuick 2.0
import QtQuick.Controls 1.2 as QtControls
import org.kde.plasma.components 2.0 as PlasmaComponents
PlasmaComponents.Page {
@ -105,6 +106,11 @@ PlasmaComponents.Page {
iconSource: "konqueror"
Keys.onTabPressed: bt5.forceActiveFocus();
menu: QtControls.Menu {
QtControls.MenuItem { text: "This Button" }
QtControls.MenuItem { text: "Happens To Have" }
QtControls.MenuItem { text: "A Menu Assigned" }
}
}
PlasmaComponents.Button {

View File

@ -22,6 +22,7 @@ import QtQuick 2.0
import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.components 2.0 as PlasmaComponents
import "../private" as Private
@ -34,9 +35,9 @@ QtQuickControlStyle.ButtonStyle {
label: Row {
id: buttonContent
spacing: icon.valid ? units.smallSpacing : 0
spacing: units.smallSpacing
property real minimumWidth: icon.width + label.implicitWidth + style.padding.left + style.padding.right + ((icon.valid) ? style.padding.left : 0)
property real minimumWidth: icon.width + label.implicitWidth + style.padding.left + style.padding.right + ((icon.valid) ? style.padding.left : 0) + (arrow.visible ? arrow.width : 0)
onMinimumWidthChanged: {
if (control.minimumWidth !== undefined) {
style.minimumWidth = minimumWidth;
@ -73,7 +74,7 @@ QtQuickControlStyle.ButtonStyle {
id: label
text: control.text
font: control.font
width: parent.width - icon.width - parent.spacing
width: parent.width - icon.width - parent.spacing - (arrow.visible ? arrow.width + parent.spacing : 0)
height: parent.height
color: theme.buttonTextColor
horizontalAlignment: icon.valid ? Text.AlignLeft : Text.AlignHCenter
@ -82,6 +83,24 @@ QtQuickControlStyle.ButtonStyle {
onImplicitHeightChanged: style.labelImplicitHeight = implicitHeight
onImplicitWidthChanged: style.labelImplicitWidth = implicitWidth
}
PlasmaExtras.ConditionalLoader {
id: arrow
when: control.menu !== null
visible: when
width: units.iconSizes.small
height: width
anchors.verticalCenter: parent.verticalCenter
source: Component {
PlasmaCore.SvgItem {
visible: control.menu !== null
anchors.fill: parent
svg: PlasmaCore.Svg { imagePath: "widgets/arrows" }
elementId: "down-arrow"
}
}
}
}
background: Item {
@ -156,19 +175,6 @@ QtQuickControlStyle.ButtonStyle {
}
]
//TODO: create on demand?
PlasmaCore.SvgItem {
visible: control.menu !== null
width: units.iconSizes.small
height: width
anchors {
right: parent.right
rightMargin: surfaceNormal.margins.right
verticalCenter: parent.verticalCenter
}
svg: PlasmaCore.Svg { imagePath: "widgets/arrows" }
elementId: "down-arrow"
}
Component.onCompleted: {
padding.top = surfaceNormal.margins.top
padding.left = surfaceNormal.margins.left