fd49c8e427d6f9039afc28f37fac162cc0a65145
[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     function setText(string) { textInButton = string; }
10     border { left: 10; top: 10; right: 10; bottom: 10 }
11
12     MouseArea {
13         id: mouseArea
14         anchors.centerIn: parent;
15         width:  parent.width;
16         height: parent.height;
17         onClicked: {
18             button.clicked();
19         }
20     }
21
22     Text {
23         z:1
24         id: buttonText
25         anchors.centerIn: parent;
26         font.pixelSize: parent.height * .5
27         style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true
28     }
29
30     Image {
31         id: image1
32         width: (35*parent.height)/107 +1
33         height: parent.height
34         anchors.left: parent.left
35         source: "qrc:/button/buttonLeft.png"
36         fillMode:Image.Stretch
37     }
38
39     Image {
40         id: image3
41         smooth: true
42         width: parent.width - ((70*parent.height)/107) +1;
43         height: parent.height
44         anchors.horizontalCenter: parent.horizontalCenter
45         source: "qrc:/button/buttonCenter.png"
46         fillMode:Image.Stretch
47     }
48
49     Image {
50         id: image2
51         smooth: true
52         width: (35*parent.height)/107 +1
53         height: parent.height
54         anchors.right: parent.right
55         source: "qrc:/button/buttonR.png"
56         fillMode:Image.Stretch
57     }
58
59     states: [
60         State {
61             name: "pressed";
62             when: (mouseArea.pressed == true && button.enabled == true);
63
64             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftPushed.png" }
65             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterPushed.png" }
66             PropertyChanges { target: image2; source: "qrc:/button/buttonRightPushed.png" }
67         },
68         State {
69             name: "disabled";
70             when: (button.enabled == false);
71
72             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftDisabled.png" }
73             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterDisabled.png" }
74             PropertyChanges { target: image2; source: "qrc:/button/buttonRightDisabled.png" }
75         }
76     ]
77
78
79
80 /*    MouseArea {
81         id: mouseArea
82         anchors.centerIn: parent;
83         width:  ((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60)) - ((70*parent.height)/107)
84         height: parent.height
85         onClicked: {
86             button.clicked();
87         }
88     }
89
90     Text {
91         z:1
92         id: buttonText
93         anchors.centerIn: parent;
94         font.pixelSize: parent.height * .5
95         style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true
96         PropertyChanges {
97             target: button;
98             width: (button.width> buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.8)
99         }
100     }
101
102     Rectangle {
103         id: shade
104         anchors.centerIn: parent;
105         radius: parent.height*.4;
106         color: "black";
107         opacity: 0
108         width:  ((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60))
109         height: parent.height
110     }
111
112     Image {
113         id: image1
114         width: (35*parent.height)/107 +1
115         height: parent.height
116         anchors.left: parent.left
117         anchors.leftMargin: (parent.width - ((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60)))/2
118         source: "qrc:/button/buttonLeft.png"
119     }
120
121     Image {
122         id: image3
123         smooth: true
124         width: (((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60)) - ((70*parent.height)/107))+1
125         height: parent.height
126         anchors.horizontalCenter: parent.horizontalCenter
127         source: "qrc:/button/buttonCenter.png"
128     }
129
130     Image {
131         id: image2
132         smooth: true
133         width: (35*parent.height)/107 +1
134         height: parent.height
135         anchors.right: parent.right
136         anchors.rightMargin: (parent.width - ((parent.width > buttonText.text.length*buttonText.font.pixelSize*.8) ? (parent.width) : (buttonText.text.length*buttonText.font.pixelSize*.60)))/2
137         source: "qrc:/button/buttonR.png"
138     }
139
140     states: [
141         State {
142             name: "pressed"; when: mouseArea.pressed == true
143             PropertyChanges { target: shade; opacity: 0.4 }
144             PropertyChanges { target: image1; opacity: 0.5 }
145             PropertyChanges { target: image3; opacity: 0.5 }
146             PropertyChanges { target: image2; opacity: 0.5 }
147         }
148     ]
149     */
150 }