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 ****************************************************************************/
47 property alias titleText: titleAreaText.text
48 property url titleIcon
49 property variant buttonTexts: []
50 property bool privateCloseIcon: false
52 signal buttonClicked(int index)
54 onButtonTextsChanged: {
55 for (var i = buttonRow.children.length; i > 0; --i) {
56 buttonRow.children[i - 1].destroy()
58 for (var j = 0; j < buttonTexts.length; ++j) {
59 var button = buttonComponent.createObject(buttonRow)
60 button.text = buttonTexts[j]
70 width: internal.buttonWidth()
71 height: privateStyle.toolBarHeightLandscape
72 platformInverted: root.platformInverted
75 if (root.status == DialogStatus.Open) {
76 root.buttonClicked(index)
86 function buttonWidth() {
87 switch (buttonTexts.length) {
89 case 1: return Math.round((privateStyle.dialogMaxSize - 3 * platformStyle.paddingMedium) / 2)
90 default: return (buttonContainer.width - (buttonTexts.length + 1) *
91 platformStyle.paddingMedium) / buttonTexts.length
95 function iconSource() {
96 if (privateCloseIcon) {
97 return privateStyle.imagePath((iconMouseArea.pressed && !iconMouseArea.pressCancelled
98 ? "qtg_graf_popup_close_pressed"
99 : "qtg_graf_popup_close_normal"),
100 root.platformInverted)
102 return root.titleIcon
108 anchors.left: parent.left
109 anchors.right: parent.right
110 height: platformStyle.graphicSizeSmall + 2 * platformStyle.paddingLarge
112 LayoutMirroring.enabled: privateCloseIcon ? false : undefined
113 LayoutMirroring.childrenInherit: true
116 id: titleLayoutHelper // needed to make the text mirror correctly
118 anchors.left: parent.left
119 anchors.right: titleAreaIcon.source == "" ? parent.right : titleAreaIcon.left
120 anchors.top: parent.top
121 anchors.bottom: parent.bottom
122 anchors.margins: platformStyle.paddingLarge
127 LayoutMirroring.enabled: root.LayoutMirroring.enabled
130 font { family: platformStyle.fontFamilyRegular; pixelSize: platformStyle.fontSizeLarge }
131 color: root.platformInverted ? platformStyle.colorNormalLinkInverted
132 : platformStyle.colorNormalLink
133 elide: Text.ElideRight
134 horizontalAlignment: Text.AlignLeft
135 verticalAlignment: Text.AlignVCenter
142 anchors.right: parent.right
143 anchors.rightMargin: platformStyle.paddingLarge
144 anchors.verticalCenter: parent.verticalCenter
145 source: internal.iconSource()
146 sourceSize.height: platformStyle.graphicSizeSmall
147 sourceSize.width: platformStyle.graphicSizeSmall
152 property bool pressCancelled
154 anchors.centerIn: parent
155 width: parent.width + 2 * platformStyle.paddingLarge
156 height: parent.height + 2 * platformStyle.paddingLarge
157 enabled: privateCloseIcon && root.status == DialogStatus.Open
160 pressCancelled = false
161 privateStyle.play(Android.BasicButton)
169 privateStyle.play(Android.PopupClose)
171 onExited: pressCancelled = true
179 LayoutMirroring.enabled: false
180 LayoutMirroring.childrenInherit: true
183 height: buttonTexts.length ? privateStyle.toolBarHeightLandscape + 2 * platformStyle.paddingSmall : 0
187 objectName: "buttonRow"
188 anchors.centerIn: parent
189 spacing: platformStyle.paddingMedium