~ubuntu-branches/ubuntu/quantal/kde-runtime/quantal

« back to all changes in this revision

Viewing changes to plasma/declarativeimports/plasmacomponents/qml/DualStateButton.qml

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-06-03 21:50:00 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120603215000-vn7oarsq0ynrydj5
Tags: upstream-4.8.80
Import upstream version 4.8.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
*   Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
3
 
*
4
 
*   This program is free software; you can redistribute it and/or modify
5
 
*   it under the terms of the GNU Library General Public License as
6
 
*   published by the Free Software Foundation; either version 2, or
7
 
*   (at your option) any later version.
8
 
*
9
 
*   This program is distributed in the hope that it will be useful,
10
 
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
*   GNU Library General Public License for more details
13
 
*
14
 
*   You should have received a copy of the GNU Library General Public
15
 
*   License along with this program; if not, write to the
16
 
*   Free Software Foundation, Inc.,
17
 
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 
*/
19
 
 
20
 
/**Documentanted API
21
 
Inherits:
22
 
        Item
23
 
 
24
 
Imports:
25
 
        QtQuick 1.0
26
 
        org.kde.plasma.core
27
 
 
28
 
Description:
29
 
 TODO i need more info here
30
 
 
31
 
Properties:
32
 
            bool checked:
33
 
            Returns if the Button is checked or not.
34
 
 
35
 
            alias pressed:
36
 
            TODO i need more info here
37
 
 
38
 
            alias text:
39
 
            Sets the text for the button
40
 
 
41
 
            QtObject theme:
42
 
            TODO needs info
43
 
 
44
 
            alias view:
45
 
            TODO needs info
46
 
 
47
 
            alias shadow:
48
 
            TODO needs info
49
 
Signals:
50
 
        clicked:
51
 
        The signal is emited when the button is clicked!
52
 
**/
53
 
 
54
 
import QtQuick 1.0
55
 
import org.kde.plasma.core 0.1 as PlasmaCore
56
 
 
57
 
Item {
58
 
    id: dualButton
59
 
 
60
 
    // Common API
61
 
    property bool checked
62
 
    property alias pressed: mouseArea.pressed
63
 
 
64
 
    signal clicked()
65
 
 
66
 
    // Plasma API
67
 
    property alias text: label.text // TODO: Not yet part of the common API
68
 
    property alias view: surfaceLoader.sourceComponent
69
 
    property alias shadow: shadowLoader.sourceComponent
70
 
 
71
 
    width: surfaceLoader.width + label.paintedWidth
72
 
    height: theme.defaultFont.mSize.height*1.6
73
 
    // TODO: needs to define if there will be specific graphics for
74
 
    //     disabled buttons
75
 
    opacity: dualButton.enabled ? 1.0 : 0.5
76
 
 
77
 
    function entered() {
78
 
        if (dualButton.enabled) {
79
 
            shadowLoader.state = "hover"
80
 
        }
81
 
    }
82
 
 
83
 
    function released() {
84
 
        if (dualButton.enabled) {
85
 
            dualButton.checked = !dualButton.checked;
86
 
            dualButton.clicked();
87
 
        }
88
 
    }
89
 
 
90
 
    Keys.onSpacePressed: entered();
91
 
    Keys.onReturnPressed: entered();
92
 
    Keys.onReleased: {
93
 
        if(event.key == Qt.Key_Space ||
94
 
           event.key == Qt.Key_Return)
95
 
            released();
96
 
    }
97
 
 
98
 
    Loader {
99
 
        id: shadowLoader
100
 
        anchors.fill: surfaceLoader
101
 
    }
102
 
 
103
 
    Loader {
104
 
        id: surfaceLoader
105
 
 
106
 
        anchors {
107
 
            verticalCenter: parent.verticalCenter
108
 
            left: text ? parent.left : undefined
109
 
            horizontalCenter: text ? undefined : parent.horizontalCenter
110
 
        }
111
 
    }
112
 
 
113
 
    Text {
114
 
        id: label
115
 
 
116
 
        text: dualButton.text
117
 
        anchors {
118
 
            top: parent.top
119
 
            bottom: parent.bottom
120
 
            left: surfaceLoader.right
121
 
            right: parent.right
122
 
            //FIXME: see how this margin will be set
123
 
            leftMargin: height/4
124
 
        }
125
 
        color: theme.textColor
126
 
        verticalAlignment: Text.AlignVCenter
127
 
    }
128
 
 
129
 
    MouseArea {
130
 
        id: mouseArea
131
 
 
132
 
        anchors.fill: parent
133
 
        hoverEnabled: true
134
 
 
135
 
        onReleased: dualButton.released();
136
 
        onEntered: dualButton.entered();
137
 
        onPressed: dualButton.forceActiveFocus();
138
 
        onExited: {
139
 
            shadowLoader.state = "shadow"
140
 
        }
141
 
    }
142
 
}
143