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 ****************************************************************************/
43 import "UIConstants.js" as UI
44 import "MultiSelectionDialog.js" as MultiSelectionDialog
49 property alias model: selectionListView.model
50 // Common API: property list<int> selectedIndexes (currently not possible due to QTBUG-10822)
51 property variant selectedIndexes: [] // read & write, variant is supposed to be list<int>
52 property alias acceptButtonText: acceptButton.text //Convenience wrapper on top of the buttons
53 property alias rejectButtonText: rejectButton.text //Convenience wrapper on top of the buttons
54 //property alias titleText: titleLabel.text
56 property Component delegate: // Note that this is the default delegate for the list
63 height: root.platformStyle.itemHeight
64 anchors.left: parent.left
65 anchors.right: parent.right
70 onPressed: MultiSelectionDialog.__toggleIndex(index);
76 color: MultiSelectionDialog.__isSelected(index) ? root.platformStyle.itemSelectedBackgroundColor : root.platformStyle.itemBackgroundColor
82 border { left: UI.CORNER_MARGINS; top: UI.CORNER_MARGINS; right: UI.CORNER_MARGINS; bottom: UI.CORNER_MARGINS }
83 source: delegateMouseArea.pressed ? root.platformStyle.itemPressedBackground :
84 MultiSelectionDialog.__isSelected(index) ? root.platformStyle.itemSelectedBackground :
85 root.platformStyle.itemBackground
90 elide: Text.ElideRight
91 color: MultiSelectionDialog.__isSelected(index) ? root.platformStyle.itemSelectedTextColor : root.platformStyle.itemTextColor
92 anchors.verticalCenter: delegateItem.verticalCenter
93 anchors.left: parent.left
94 anchors.right: parent.right
95 anchors.leftMargin: root.platformStyle.itemLeftMargin
96 anchors.rightMargin: root.platformStyle.itemRightMargin
97 font: root.platformStyle.itemFont
99 Component.onCompleted: {
101 // Legacy. "name" used to be the role which was used by delegate
105 // "modelData" available for JS array and for models with one role
106 itemText.text = modelData
109 // C++ models have "display" role available always
110 itemText.text = display
120 property Style platformStyle: SelectionDialogStyle {}
122 //Deprecated, TODO Remove this on w13
123 property alias style: root.platformStyle
126 property int __pressDelay: platformStyle.pressDelay
127 property variant __selectedIndexesHash: []
131 property variant oldSelectedIndexes: []
134 if (status == DialogStatus.Opening) {
135 selectionListView.positionViewAtIndex(selectedIndexes[0], ListView.Center)
137 if (status == DialogStatus.Open)
138 backup.oldSelectedIndexes = selectedIndexes
140 onRejected: { selectedIndexes = backup.oldSelectedIndexes }
142 onSelectedIndexesChanged: {
143 MultiSelectionDialog.__syncHash();
146 // the title field consists of the following parts: title string and
147 // a close button (which is in fact an image)
148 // it can additionally have an icon
149 titleText: "Multi-Selection Dialog"
151 // the content field which contains the selection content
155 property int listViewHeight
156 property int maxListViewHeight : visualParent
157 ? visualParent.height * 0.87
158 - buttonRow.childrenRect.height - root.platformStyle.contentSpacing - root.platformStyle.buttonsTopMargin
159 - root.platformStyle.titleBarHeight
161 ? root.parent.height * 0.87
162 - buttonRow.childrenRect.height - root.platformStyle.contentSpacing - root.platformStyle.buttonsTopMargin
163 - root.platformStyle.titleBarHeight
165 height: listViewHeight > maxListViewHeight ? maxListViewHeight : listViewHeight
167 y : root.platformStyle.contentSpacing
170 id: selectionListView
175 delegate: root.delegate
178 pressDelay: __pressDelay
182 flickableItem: selectionListView
183 platformStyle.inverted: true
185 onModelChanged: selectionContent.listViewHeight = model.count * platformStyle.itemHeight
193 height: childrenRect.height //+ root.platformStyle.buttonsTopMargin
194 y: root.platformStyle.buttonsTopMargin
197 if (acceptButton.width + rejectButton.width > width) {
198 acceptButton.width = width / 2
199 rejectButton.width = width / 2
201 acceptButton.width = acceptButton.implicitWidth
202 rejectButton.width = rejectButton.implicitWidth
208 height: childrenRect.height
209 anchors.horizontalCenter: parent.horizontalCenter
212 height: implicitHeight
213 objectName: "acceptButton"
218 platformStyle: ButtonStyle {inverted: true}
222 height: implicitHeight
223 objectName: "rejectButton"
228 platformStyle: ButtonStyle {inverted: true}