support for round buttons

This commit is contained in:
Marco Martin 2014-07-25 14:40:13 +02:00
parent a3266857ad
commit c8cb89faa9

View File

@ -102,8 +102,66 @@ QtQuickControlStyle.ButtonStyle {
} }
} }
background: Item { background: {
if (control.text.length == 0 && control.width == control.height && (control.parent && control.parent.checkedButton === undefined) && !control.flat) {
return roundButtonComponent
} else {
return buttonComponent
}
}
Component {
id: roundButtonComponent
Item {
id: roundButtonDelegate
anchors.fill: parent
property QtObject margins: QtObject {
property int left: delegate.width/8
property int top: delegate.width/8
property int right: delegate.width/8
property int bottom: delegate.width/8
}
property alias hasOverState: roundShadow.hasOverState
Private.RoundShadow {
id: roundShadow
visible: !flat
anchors.fill: parent
state: {
if (control.pressed) {
return "hidden"
} else if (control.hovered) {
return "hover"
} else if (control.activeFocus) {
return "focus"
} else {
return "shadow"
}
}
}
PlasmaCore.Svg {
id: buttonSvg
imagePath: "widgets/actionbutton"
}
PlasmaCore.SvgItem {
id: buttonItem
svg: buttonSvg
elementId: (control.pressed || control.checked) ? "pressed" : "normal"
width: Math.floor(parent.height/2) * 2
height: width
//internal: if there is no hover status, don't paint on mouse over in touchscreens
opacity: (control.pressed || control.checked || !control.flat || (roundShadow.hasOverState && mouse.containsMouse)) ? 1 : 0
Behavior on opacity {
PropertyAnimation { duration: units.longDuration }
}
}
}
}
Component {
id: buttonComponent
Item {
implicitHeight: Math.floor(Math.max(theme.mSize(theme.defaultFont).height*1.6, style.minimumHeight)) implicitHeight: Math.floor(Math.max(theme.mSize(theme.defaultFont).height*1.6, style.minimumHeight))
implicitWidth: { implicitWidth: {
@ -199,4 +257,5 @@ QtQuickControlStyle.ButtonStyle {
padding.bottom = surfaceNormal.margins.bottom padding.bottom = surfaceNormal.margins.bottom
} }
} }
}
} }