2012-02-11 00:58:30 +01:00
|
|
|
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
|
|
|
|
import QtQuick 1.1
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: welcomeButton
|
2012-08-14 14:46:35 +02:00
|
|
|
width: Math.max(116, icon.width)
|
2012-09-27 08:18:50 +02:00
|
|
|
height: icon.height
|
2012-08-18 03:30:50 +02:00
|
|
|
z: 0
|
2012-02-11 00:58:30 +01:00
|
|
|
|
|
|
|
property string baseIconName
|
|
|
|
property alias label : labelText.text
|
|
|
|
|
|
|
|
signal clicked
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: icon
|
2012-02-19 03:12:27 +01:00
|
|
|
source: "images/"+baseIconName+"-off.png"
|
2012-02-11 00:58:30 +01:00
|
|
|
anchors.centerIn: parent
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: hoveredIcon
|
2012-02-19 03:12:27 +01:00
|
|
|
source: "images/"+baseIconName+"-on.png"
|
2012-02-11 00:58:30 +01:00
|
|
|
anchors.centerIn: parent
|
|
|
|
opacity: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: labelImage
|
2012-08-18 03:30:50 +02:00
|
|
|
property bool displayBelowButton: false
|
|
|
|
source: displayBelowButton ? "images/button-label-bottom.png" : "images/button-label.png"
|
2012-02-11 00:58:30 +01:00
|
|
|
opacity: 0
|
2012-08-14 14:46:35 +02:00
|
|
|
visible: labelText.text.length > 0 //don't show label bg without text
|
2012-02-11 00:58:30 +01:00
|
|
|
|
2012-08-18 03:30:50 +02:00
|
|
|
|
2012-02-11 00:58:30 +01:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2012-08-18 03:30:50 +02:00
|
|
|
y: displayBelowButton ? parent.height-8 : -height+8
|
2012-02-11 00:58:30 +01:00
|
|
|
|
|
|
|
Text {
|
|
|
|
id: labelText
|
2012-08-18 03:30:50 +02:00
|
|
|
anchors.baseline: parent.bottom
|
|
|
|
//text baseline depends on label image orientation,
|
|
|
|
//0.3 and 0.55 constants have to be adjusted when button-label.png is modified
|
|
|
|
anchors.baselineOffset: labelImage.displayBelowButton ? -parent.height*0.3 : -parent.height*0.55
|
2012-02-11 00:58:30 +01:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
|
|
|
font {
|
|
|
|
weight: Font.DemiBold
|
|
|
|
pointSize: 14
|
|
|
|
}
|
|
|
|
color: "#272727"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
states: State {
|
|
|
|
name: "hovered"
|
2012-08-18 03:30:50 +02:00
|
|
|
//update the tooltip position before it's displayed,
|
|
|
|
//since we don't have a property to bind directly
|
|
|
|
StateChangeScript {
|
|
|
|
name: "updateLabelPosition"
|
|
|
|
script: labelImage.displayBelowButton = welcomeButton.mapToItem(null,0,0).y < labelImage.height
|
|
|
|
}
|
2012-02-11 00:58:30 +01:00
|
|
|
PropertyChanges { target: hoveredIcon; opacity: 1.0 }
|
|
|
|
PropertyChanges { target: labelImage; opacity: 1.0 }
|
2012-08-18 03:30:50 +02:00
|
|
|
//raise this button, so tooltip is not obscured by the next items in the grid
|
|
|
|
PropertyChanges { target: welcomeButton; z: 1 }
|
2012-02-11 00:58:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
transitions: Transition {
|
|
|
|
from: ""; to: "hovered"; reversible: true
|
|
|
|
NumberAnimation { targets: [hoveredIcon, labelImage]; property: "opacity"; duration: 150; easing.type: Easing.InOutQuad }
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
hoverEnabled: true
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
onEntered: welcomeButton.state = "hovered"
|
|
|
|
onExited: welcomeButton.state = ""
|
|
|
|
onClicked: welcomeButton.clicked()
|
|
|
|
}
|
|
|
|
}
|