pressed effect for the label

This commit is contained in:
Marco Martin 2011-11-28 13:49:28 +01:00
parent 794bd80a01
commit d5167f2529
4 changed files with 65 additions and 12 deletions

View File

@ -26,8 +26,8 @@ Item {
// Commmon API
property bool flat: true
property bool checked: false
property bool checkable: false
property bool checked: defaultAction ? defaultAction.checked : false
property bool checkable: defaultAction ? defaultAction.checkable : false
property alias pressed: mouse.pressed
property alias text: label.text
property alias iconSource: icon.source
@ -35,11 +35,16 @@ Item {
signal clicked()
// Plasma extensiuons
property QtObject defaultAction
onFlatChanged: {
delegate.opacity = 1
if (!flat) {
delegate.opacity = 1
}
}
enabled: defaultAction==undefined||defaultAction.enabled
implicitWidth: {
if (label.paintedWidth == 0) {
@ -88,12 +93,18 @@ Item {
return
}
if (button.checkable) {
if (defaultAction && defaultAction.checkable) {
defaultAction.checked = !defaultAction.checked
} else if (button.checkable) {
button.checked = !button.checked
}
button.clicked()
button.forceActiveFocus()
if (defaultAction) {
defaultAction.trigger()
}
}
}
@ -142,10 +153,10 @@ Item {
Item {
anchors.fill: parent
property QtObject margins: QtObject {
property int left: 16
property int top: 16
property int right: 16
property int bottom: 16
property int left: 8
property int top: 8
property int right: 8
property int bottom: 8
}
RoundShadow {
anchors.fill: parent
@ -175,6 +186,10 @@ Item {
rightMargin: delegate.margins.right
bottomMargin: delegate.margins.bottom
}
scale: internal.userPressed ? 0.9 : 1
Behavior on scale {
PropertyAnimation { duration: 100 }
}
IconLoader {
id: icon
@ -184,6 +199,8 @@ Item {
left: label.text ? parent.left : undefined
horizontalCenter: label.text ? undefined : parent.horizontalCenter
}
width: label.text ? implicitWidth : roundToStandardSize(parent.width)
height: width
}
Text {

View File

@ -127,6 +127,10 @@ Item {
Item {
id: buttonContent
state: (internal.userPressed || checked) ? "pressed" : "normal"
scale: state == "pressed" ? 0.9 : 1
Behavior on scale {
PropertyAnimation { duration: 100 }
}
states: [
State { name: "normal" },

View File

@ -56,6 +56,23 @@ Item {
id: svgIcon
}
function roundToStandardSize(size)
{
if (size >= theme.enormousIconSize) {
return theme.enormousIconSize
} else if (size >= theme.hugeIconSize) {
return theme.hugeIconSize
} else if (size >= theme.largeIconSize) {
return theme.largeIconSize
} else if (size >= theme.mediumIconSize) {
return theme.mediumIconSize
} else if (size >= theme.smallMediumIconSize) {
return theme.smallMediumIconSize
} else {
return theme.smallIconSize
}
}
Loader {
id: imageLoader
anchors.fill: parent

View File

@ -26,8 +26,8 @@ Item {
// Commmon API
property bool flat: true
property bool checked: false
property bool checkable: false
property bool checked: defaultAction ? defaultAction.checked : false
property bool checkable: defaultAction ? defaultAction.checkable : false
property alias pressed: mouse.pressed
property alias text: label.text
property alias iconSource: icon.source
@ -35,6 +35,11 @@ Item {
signal clicked()
// Plasma extensiuons
property QtObject defaultAction
enabled: defaultAction==undefined||defaultAction.enabled
onFlatChanged: {
surface.opacity = 1
@ -88,12 +93,18 @@ Item {
return
}
if (button.checkable) {
if (defaultAction && defaultAction.checkable) {
defaultAction.checked = !defaultAction.checked
} else if (button.checkable) {
button.checked = !button.checked
}
button.clicked()
button.forceActiveFocus()
if (defaultAction) {
defaultAction.trigger()
}
}
}
@ -112,7 +123,7 @@ Item {
//internal: if there is no hover status, don't paint on mouse over in touchscreens
opacity: (internal.userPressed || checked || !flat || (shadow.hasOverState && mouse.containsMouse)) ? 1 : 0
Behavior on opacity {
PropertyAnimation { duration: 250 }
PropertyAnimation { duration: 100 }
}
}
@ -124,6 +135,10 @@ Item {
rightMargin: surface.margins.right
bottomMargin: surface.margins.bottom
}
scale: internal.userPressed ? 0.9 : 1
Behavior on scale {
PropertyAnimation { duration: 250 }
}
IconLoader {
id: icon