add qml-elements
[mdictionary] / src / mdictionary / qml / Button.qml
1 import Qt 4.7
2
3 BorderImage {
4     id: button
5     property alias textInButton: buttonText.text
6     signal clicked
7     opacity: 1
8
9     border { left: 10; top: 10; right: 10; bottom: 10 }
10
11     MouseArea {
12         id: mouseArea
13         anchors.centerIn: parent;
14         width:  ((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60)) - ((70*parent.height)/107)
15         height: parent.height
16         onClicked: {
17             button.clicked();
18         }
19     }
20
21     Text {
22         z:1
23         id: buttonText
24         anchors.centerIn: parent;
25         font.pixelSize: parent.height * .5
26         style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true
27     }
28
29     Rectangle {
30         id: shade
31         anchors.centerIn: parent;
32         radius: parent.height*.4;
33         color: "black";
34         opacity: 0
35         width:  parent.width//((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60))
36         height: parent.height
37     }
38
39     Image {
40         id: image1
41         width: (35*parent.height)/107
42         height: parent.height
43         anchors.left: parent.left
44         anchors.leftMargin: (parent.width - ((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60)))/2
45         source: "qrc:/button/buttonLeft.png"
46     }
47
48     Image {
49         id: image3
50         width: ((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60)) - ((70*parent.height)/107)
51         height: parent.height
52         anchors.horizontalCenter: parent.horizontalCenter
53         source: "qrc:/button/buttonCenter.png"
54     }
55
56     Image {
57         id: image2
58         width: (35*parent.height)/107
59         height: parent.height
60         anchors.right: parent.right
61         anchors.rightMargin: (parent.width - ((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60)))/2
62         source: "qrc:/button/buttonR.png"
63     }
64
65     states: [
66         State {
67             name: "pressed"; when: mouseArea.pressed == true
68             PropertyChanges { target: shade; opacity: 0.4 }
69             PropertyChanges { target: image1; opacity: 0.5 }
70             PropertyChanges { target: image3; opacity: 0.5 }
71             PropertyChanges { target: image2; opacity: 0.5 }
72         }
73     ]
74 }