1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Components project.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
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
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
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."
39 ****************************************************************************/
42 import "constants.js" as UI
46 button component that has a label and has click event handling.
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.
52 The TumblerButton has a fixed width. Longer text will be elided.
53 To avoid that for longer texts please set the implicitWidth explicitly.
56 // Create a button with different icon states:
57 // This approach works for all supported states: normal, disabled, pressed, selected, selected && disabled
59 text: "Tumbler Button"
68 * [string] The text displayed on button.
70 property string text: "Get Value"
74 * [bool] (ReadOnly) Is true when the button is pressed
76 property alias pressed: mouse.pressed
78 property QtObject style: TumblerButtonStyle{}
82 * Is emitted after the button is released
86 height: UI.SIZE_BUTTON
87 width: UI.WIDTH_TUMBLER_BUTTON // fixed width to prevent jumping size after selecting value from tumbler
90 border { top: UI.CORNER_MARGINS; bottom: UI.CORNER_MARGINS;
91 left: UI.CORNER_MARGINS; right: UI.CORNER_MARGINS }
93 source: mouse.pressed ?
94 tumblerbutton.style.pressedBackground : tumblerbutton.enabled ?
95 tumblerbutton.style.background : tumblerbutton.style.disabledBackground;
102 enabled: parent.enabled
111 anchors { right: (label.text != "") ? parent.right : undefined;
112 rightMargin: UI.INDENT_DEFAULT;
113 horizontalCenter: (label.text != "") ? undefined : parent.horizontalCenter;
114 verticalCenter: parent.verticalCenter;
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" : "")
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