dd94a401b28d89692d8ed505ee86789df16adf1d
[mdictionary] / src / mdictionary / qml / Button.qml
1 import Qt 4.7
2
3 BorderImage {
4     id: button
5     property alias textInButton: buttonText.text
6     property bool checkable: false
7     property bool checked: false
8
9     height: 20;
10     width: 60;
11
12     signal clicked;
13     signal changeCheck;
14
15     function setText(string) { textInButton = qsTr(string); }
16     function press() { mouseArea.pressed }
17     border { left: 10; top: 10; right: 10; bottom: 10 }
18
19     MouseArea {
20         id: mouseArea
21         anchors.centerIn: parent;
22         width:  parent.width;
23         height: parent.height;
24         onClicked: {
25             button.clicked();
26             if(checkable){
27                 button.checked=!button.checked;
28                 button.changeCheck();
29             }
30         }
31     }
32
33     Text {
34         z:1
35         id: buttonText
36         width: parent.width;
37         anchors.centerIn: parent;
38         horizontalAlignment: Text.AlignHCenter
39         font.pixelSize: parent.height * .5
40         elide: Text.ElideRight;
41         style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true
42     }
43
44     Image {
45         id: image1
46         width:  (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1 //(35*parent.height)/107 +1
47         height: parent.height
48         anchors.left: parent.left
49         source: "qrc:/button/buttonLeft.png"
50         smooth: true
51         fillMode:Image.Stretch
52     }
53
54     Image {
55         id: image3
56         smooth: true
57         height: parent.height
58         anchors.right: image2.left
59         anchors.rightMargin: -1
60         anchors.left: image1.right
61         anchors.leftMargin: -1
62         source: "qrc:/button/buttonCenter.png"
63         fillMode:Image.Stretch
64     }
65
66     Image {
67         id: image2
68         smooth: true
69         width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1//(35*parent.height)/107 +1
70         height: parent.height
71         anchors.right: parent.right
72         source: "qrc:/button/buttonR.png"
73         fillMode:Image.Stretch
74     }
75
76     states: [
77         State {
78             name: "pressed";
79             when: ((button.enabled) && (mouseArea.pressed || (button.checkable && button.checked) ) )
80
81             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftPushed.png" }
82             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterPushed.png" }
83             PropertyChanges { target: image2; source: "qrc:/button/buttonRightPushed.png" }
84         },
85         State {
86             name: "disabled";
87             when: (button.enabled == false);
88
89             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftDisabled.png" }
90             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterDisabled.png" }
91             PropertyChanges { target: image2; source: "qrc:/button/buttonRightDisabled.png" }
92         }
93     ]
94 }