add focus in qml
[mdictionary] / src / mdictionary / qml / Button.qml
index dd94a40..953fdbc 100644 (file)
@@ -1,6 +1,6 @@
 import Qt 4.7
 
-BorderImage {
+Rectangle {
     id: button
     property alias textInButton: buttonText.text
     property bool checkable: false
@@ -14,7 +14,14 @@ BorderImage {
 
     function setText(string) { textInButton = qsTr(string); }
     function press() { mouseArea.pressed }
-    border { left: 10; top: 10; right: 10; bottom: 10 }
+
+    Keys.onReturnPressed: {
+        button.clicked();
+        if(checkable){
+            button.checked=!button.checked;
+            button.changeCheck();
+        }
+    }
 
     MouseArea {
         id: mouseArea
@@ -43,7 +50,7 @@ BorderImage {
 
     Image {
         id: image1
-        width:  (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1 //(35*parent.height)/107 +1
+        width:  (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1
         height: parent.height
         anchors.left: parent.left
         source: "qrc:/button/buttonLeft.png"
@@ -60,13 +67,15 @@ BorderImage {
         anchors.left: image1.right
         anchors.leftMargin: -1
         source: "qrc:/button/buttonCenter.png"
-        fillMode:Image.Stretch
+        //fillMode:Image.Stretch
+        fillMode: Image.TileHorizontally
+
     }
 
     Image {
         id: image2
         smooth: true
-        width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1//(35*parent.height)/107 +1
+        width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1
         height: parent.height
         anchors.right: parent.right
         source: "qrc:/button/buttonR.png"
@@ -89,6 +98,15 @@ BorderImage {
             PropertyChanges { target: image1; source: "qrc:/button/buttonLeftDisabled.png" }
             PropertyChanges { target: image3; source: "qrc:/button/buttonCenterDisabled.png" }
             PropertyChanges { target: image2; source: "qrc:/button/buttonRightDisabled.png" }
+        },
+        State {
+            name: "focused";
+            when: (button.enabled && !mouseArea.pressed && button.focus)
+
+            PropertyChanges { target: image1; source: "qrc:/button/buttonLeftFocus.png" }
+            PropertyChanges { target: image3; source: "qrc:/button/buttonCenterFocus.png" }
+            PropertyChanges { target: image2; source: "qrc:/button/buttonRFocus.png" }
         }
+
     ]
 }