added android components
[mardrone] / mardrone / imports / com / nokia / extras / TumblerButton.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Qt Components project.
8 **
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 **   * Redistributions of source code must retain the above copyright
16 **     notice, this list of conditions and the following disclaimer.
17 **   * Redistributions in binary form must reproduce the above copyright
18 **     notice, this list of conditions and the following disclaimer in
19 **     the documentation and/or other materials provided with the
20 **     distribution.
21 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 **     the names of its contributors may be used to endorse or promote
23 **     products derived from this software without specific prior written
24 **     permission.
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 import QtQuick 1.1
42 import "constants.js" as UI
43
44 /*
45    Class: TumblerButton
46    button component that has a label and has click event handling.
47
48    A button is a component that accepts user input and send a clicked() signal for
49    the application to handle. The button has resizable properties, event
50    handling, and can undergo state changes and transitions.
51
52    The TumblerButton has a fixed width. Longer text will be elided.
53    To avoid that for longer texts please set the implicitWidth explicitly.
54
55    <code>
56        // Create a button with different icon states:
57        // This approach works for all supported states: normal, disabled, pressed, selected, selected && disabled
58        TumblerButton {
59            text: "Tumbler Button"
60        }
61    </code>
62 */
63 Item {
64     id: tumblerbutton
65
66     /*
67      * Property: text
68      * [string] The text displayed on button.
69      */
70     property string text: "Get Value"
71
72     /*
73      * Property: pressed
74      * [bool] (ReadOnly) Is true when the button is pressed
75      */
76     property alias pressed: mouse.pressed
77
78     property QtObject style: TumblerButtonStyle{}
79
80     /*
81      * Event: clicked
82      * Is emitted after the button is released
83      */
84     signal clicked
85
86     height: UI.SIZE_BUTTON
87     width: UI.WIDTH_TUMBLER_BUTTON // fixed width to prevent jumping size after selecting value from tumbler
88
89     BorderImage {
90         border { top: UI.CORNER_MARGINS; bottom: UI.CORNER_MARGINS;
91             left: UI.CORNER_MARGINS; right: UI.CORNER_MARGINS }
92         anchors.fill: parent
93         source: mouse.pressed ?
94                 tumblerbutton.style.pressedBackground : tumblerbutton.enabled ?
95                     tumblerbutton.style.background : tumblerbutton.style.disabledBackground;
96     }
97
98     MouseArea {
99         id: mouse
100
101         anchors.fill: parent
102         enabled: parent.enabled
103         onClicked: {
104             parent.clicked()
105         }
106     }
107
108     Image {
109         id: icon
110
111         anchors { right: (label.text != "") ? parent.right : undefined;
112             rightMargin: UI.INDENT_DEFAULT;
113             horizontalCenter: (label.text != "") ? undefined : parent.horizontalCenter;
114             verticalCenter: parent.verticalCenter;
115         }
116         height: sourceSize.height
117         width: sourceSize.width
118         source: "image://theme/meegotouch-combobox-indicator" +
119                 (tumblerbutton.style.inverted ? "-inverted" : "") +
120                 (tumblerbutton.enabled ? "" : "-disabled") +
121                 (mouse.pressed ? "-pressed" : "")
122     }
123
124     Text {
125         id: label
126
127         anchors { left: parent.left; right: icon.left;
128             leftMargin: UI.INDENT_DEFAULT; rightMargin: UI.INDENT_DEFAULT;
129             verticalCenter: parent.verticalCenter }
130         font { family: UI.FONT_FAMILY; pixelSize: UI.FONT_DEFAULT_SIZE;
131             bold: UI.FONT_BOLD_BUTTON; capitalization: tumblerbutton.style.fontCapitalization }
132         text: tumblerbutton.text
133         color: (mouse.pressed) ? 
134             tumblerbutton.style.pressedTextColor :
135                 (tumblerbutton.enabled) ?
136                     tumblerbutton.style.textColor : tumblerbutton.style.disabledTextColor ;
137         horizontalAlignment: Text.AlignLeft
138         elide: Text.ElideRight
139     }
140 }