code clean
[mdictionary] / src / mdictionary / qml / IconButton.qml
1 import Qt 4.7
2
3 Rectangle {
4     id: rectangle
5
6     property alias pathToIcon: image.source;
7     property int iconWidth:rectangle.width-8;
8     property int iconHeight:rectangle.height-8;
9
10     signal clicked;
11     function press() { mouseArea.pressed }
12
13     radius: 50
14
15     Keys.onReturnPressed: {
16         rectangle.clicked();
17     }
18
19     MouseArea {
20         id: mouseArea
21         anchors.centerIn: parent;
22         width: rectangle.width
23         height: rectangle.height;
24         onClicked: {
25             rectangle.clicked();
26         }
27     }
28
29     Image {
30         id: image
31         z:4;
32         smooth: true
33         anchors.centerIn: parent
34         width: iconWidth;
35         height: iconHeight;
36     }
37
38     Image {
39         id: image1
40         smooth: true
41         width:  (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1 //(35*parent.height)/107 +1
42         height: parent.height
43         anchors.left: parent.left
44         source: "qrc:/button/buttonLeft.png"
45         fillMode:Image.Stretch
46     }
47
48     Image {
49         id: image3
50         smooth: true
51         height: parent.height
52         anchors.right: image2.left
53         anchors.rightMargin: -1
54         anchors.left: image1.right
55         anchors.leftMargin: -1
56         source: "qrc:/button/buttonCenter.png"
57         fillMode:Image.Stretch
58         //fillMode: Image.TileHorizontally
59
60     }
61
62
63     Image {
64         id: image2
65         smooth: true
66         width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1//(35*parent.height)/107 +1
67         height: parent.height
68         anchors.right: parent.right
69         source: "qrc:/button/buttonR.png"
70         fillMode:Image.Stretch
71     }
72
73
74     states: [
75         State {
76             name: "disable";
77             when: (rectangle.enabled == false);
78             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftDisabled.png" }
79             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterDisabled.png" }
80             PropertyChanges { target: image2; source: "qrc:/button/buttonRightDisabled.png" }
81         },
82         State {
83             name: "clicked";
84             when: (mouseArea.pressed == true && rectangle.enabled == true);
85             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftPushed.png" }
86             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterPushed.png" }
87             PropertyChanges { target: image2; source: "qrc:/button/buttonRightPushed.png" }
88         },
89         State {
90             name: "focused";
91             when: (rectangle.enabled && !mouseArea.pressed && rectangle.focus)
92
93             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftFocus.png" }
94             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterFocus.png" }
95             PropertyChanges { target: image2; source: "qrc:/button/buttonRFocus.png" }
96         }
97     ]
98 }