qtmobility/examples/declarative-sfw-dialer/sfwexample/DialButton.qml
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 03 May 2010 13:18:40 +0300
changeset 4 90517678cc4f
permissions -rw-r--r--
Revision: 201015 Kit: 201018

import Qt 4.6

//Implementation of the dialButton control.
Item {
    id: dialButton
    width: 50
    height: 50
    property alias buttonText: innerText.text;
    property alias color: rectangleButton.color
    property color hoverColor: "lightsteelblue"
    property color pressColor: "slategray"
    signal clicked

    Rectangle {
        id: rectangleButton
        anchors.fill: parent
        radius: 5
        color: "steelblue"
        border.width: 3
        border.color: "black"

        Text {
            id: innerText
            font.pointSize: 20
            anchors.centerIn: parent
        }
    }
   
    states: [
        State {
            name: "Hovering"
            PropertyChanges {
                target: rectangleButton
                color: hoverColor
            }
        },
        State {
            name: "Pressed"
            PropertyChanges {
                target: rectangleButton
                color: pressColor
            }
        }
    ]
   
   
    transitions: [
        Transition {
            from: ""; to: "Hovering"
            ColorAnimation { duration: 100 }
        },
        Transition {
            from: "*"; to: "Pressed"
            ColorAnimation { duration: 10 }
        }
    ]
   
    MouseArea {
        hoverEnabled: true
        anchors.fill: dialButton
        onEntered: { dialButton.state='Hovering'}
        onExited: { dialButton.state=''}
        onClicked: { dialButton.clicked();}
        onPressed: { dialButton.state="Pressed" }
        onReleased: {
            if (containsMouse)
            dialButton.state="Hovering";
            else
            dialButton.state="";
        }
    }
}