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

View File

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

View File

@ -56,6 +56,23 @@ Item {
id: svgIcon 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 { Loader {
id: imageLoader id: imageLoader
anchors.fill: parent anchors.fill: parent

View File

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