~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to qml/func/common/ButtonBehavior.qml

  • Committer: kobe
  • Date: 2015-02-13 07:37:10 UTC
  • Revision ID: xiangli@ubuntukylin.com-20150213073710-0jyp02ilyi5njj10
Qt Version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import QtQuick 1.1
2
 
 
3
 
Item {
4
 
    id: behavior
5
 
 
6
 
    signal clicked
7
 
    property bool pressed: false
8
 
    property alias containsMouse: mouseArea.containsMouse
9
 
    property bool checkable: true
10
 
    property bool checked: true
11
 
    property bool triState: false
12
 
 
13
 
    onCheckableChanged: { if(!checkable) checked = false }
14
 
    MouseArea {
15
 
        id: mouseArea
16
 
        anchors.fill: parent
17
 
        hoverEnabled: true
18
 
        onPressed: behavior.pressed = true
19
 
        onEntered: if(pressed && enabled) behavior.pressed = true
20
 
        onExited: behavior.pressed = false
21
 
        onCanceled: behavior.pressed = false
22
 
        onReleased: {
23
 
            if(behavior.pressed && behavior.enabled) {
24
 
                behavior.pressed = false
25
 
                if(behavior.checkable)
26
 
                    behavior.checked = !behavior.checked;
27
 
                behavior.clicked()
28
 
            }
29
 
        }
30
 
    }
31
 
}