add focus in qml
[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     MouseArea {
16         id: mouseArea
17         anchors.centerIn: parent;
18         width: rectangle.width
19         height: rectangle.height;
20         onClicked: {
21             rectangle.clicked();
22         }
23     }
24
25     Image {
26         id: image
27         z:4;
28         smooth: true
29         anchors.centerIn: parent
30         width: iconWidth;
31         height: iconHeight;
32     }
33
34     Image {
35         id: image1
36         smooth: true
37         width:  (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1 //(35*parent.height)/107 +1
38         height: parent.height
39         anchors.left: parent.left
40         source: "qrc:/button/buttonLeft.png"
41         fillMode:Image.Stretch
42     }
43
44     Image {
45         id: image3
46         smooth: true
47         height: parent.height
48         anchors.right: image2.left
49         anchors.rightMargin: -1
50         anchors.left: image1.right
51         anchors.leftMargin: -1
52         source: "qrc:/button/buttonCenter.png"
53         fillMode:Image.Stretch
54         //fillMode: Image.TileHorizontally
55
56     }
57
58
59     Image {
60         id: image2
61         smooth: true
62         width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1//(35*parent.height)/107 +1
63         height: parent.height
64         anchors.right: parent.right
65         source: "qrc:/button/buttonR.png"
66         fillMode:Image.Stretch
67     }
68
69
70     states: [
71         State {
72             name: "disable";
73             when: (rectangle.enabled == false);
74             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftDisabled.png" }
75             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterDisabled.png" }
76             PropertyChanges { target: image2; source: "qrc:/button/buttonRightDisabled.png" }
77         },
78         State {
79             name: "clicked";
80             when: (mouseArea.pressed == true && rectangle.enabled == true);
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: "focused";
87             when: (rectangle.enabled && !mouseArea.pressed && rectangle.focus)
88
89             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftFocus.png" }
90             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterFocus.png" }
91             PropertyChanges { target: image2; source: "qrc:/button/buttonRFocus.png" }
92         }
93     ]
94 }