Don't duplicate background resizing to contents

The code in Button is
panel.implicitWidth: max(label+borders, backgroundImplicitSize)

by setting the background implicitSize to be max(size, labels+borders)
we just duplicate the functionality.

This worked, but icon only buttons became smaller because we weren't
setting the implicitHeight of the label properly.

(two wrongs were making a right)

We need to move the RowLayout inside an Item as we are modiyfing the
preferredHeight of RowLayout, but this doesn't sync back to updating the
implicitHeight which Button.qml uses.

This fixes all binding loops and the rather broken icon only flat
button.

Change-Id: Id2f9c2ab37b2280ee69dc1473f388fe686e3327e
This commit is contained in:
David Edmundson 2014-09-23 00:41:12 +02:00 committed by David Edmundson
parent b2a5ebc926
commit 8a70067e8c

View File

@ -34,9 +34,16 @@ QtQuickControlStyle.ButtonStyle {
property int minimumWidth
property int minimumHeight
label: RowLayout {
label: Item {
//wrapper is needed as we are adjusting the preferredHeight of the layout from the default
//and the implicitHeight is implicitly read only
implicitHeight: buttonContent.Layout.preferredHeight
implicitWidth: buttonContent.implicitWidth
RowLayout {
id: buttonContent
anchors.fill: parent
spacing: units.smallSpacing
Layout.preferredHeight: Math.max(units.iconSizes.small, label.implicitHeight)
property real minimumWidth: Layout.minimumWidth + style.padding.left + style.padding.right
@ -59,6 +66,10 @@ QtQuickControlStyle.ButtonStyle {
id: icon
source: control.iconName || control.iconSource
anchors.verticalCenter: parent.verticalCenter
implicitHeight: label.implicitHeight
implicitWidth: implicitHeight
Layout.minimumWidth: valid ? parent.height: 0
Layout.maximumWidth: Layout.minimumWidth
visible: valid
@ -104,6 +115,7 @@ QtQuickControlStyle.ButtonStyle {
}
}
}
}
background: {
if (control.text.length == 0 && control.width == control.height && (control.parent && control.parent.checkedButton === undefined) && !control.flat) {
@ -117,7 +129,9 @@ QtQuickControlStyle.ButtonStyle {
id: roundButtonComponent
Item {
id: roundButtonDelegate
anchors.fill: parent
implicitHeight: Math.floor(theme.mSize(theme.defaultFont).height*1.6)
implicitWidth: implicitHeight
property QtObject margins: QtObject {
property int left: control.width/8
property int top: control.width/8
@ -166,13 +180,13 @@ QtQuickControlStyle.ButtonStyle {
id: buttonComponent
Item {
id: buttonSurface
implicitHeight: Math.floor(Math.max(theme.mSize(theme.defaultFont).height*1.6, style.minimumHeight))
implicitHeight: Math.floor(theme.mSize(theme.defaultFont).height*1.6)
implicitWidth: {
if (control.text.length == 0) {
implicitHeight;
} else {
Math.max(theme.mSize(theme.defaultFont).width*12, style.minimumWidth);
Math.floor(theme.mSize(theme.defaultFont).width*12);
}
}
Connections {