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
49 property alias model: selectionListView.model
50 property int selectedIndex: -1 // read & write
51 //property string titleText: "Selection Dialog"
53 property Component delegate: // Note that this is the default delegate for the list
59 property bool selected: index == selectedIndex;
61 height: root.platformStyle.itemHeight
62 anchors.left: parent.left
63 anchors.right: parent.right
68 onPressed: selectedIndex = index;
76 color: delegateItem.selected ? 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 delegateItem.selected ? root.platformStyle.itemSelectedBackground :
85 root.platformStyle.itemBackground
90 elide: Text.ElideRight
91 color: delegateItem.selected ? 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
98 font: root.platformStyle.itemFont
100 Component.onCompleted: {
102 // Legacy. "name" used to be the role which was used by delegate
106 // "modelData" available for JS array and for models with one role
107 itemText.text = modelData
110 // C++ models have "display" role available always
111 itemText.text = display
121 if (status == DialogStatus.Opening && selectedIndex >= 0) {
122 selectionListView.positionViewAtIndex(selectedIndex, ListView.Center)
127 property Style platformStyle: SelectionDialogStyle {}
129 //Deprecated, TODO Remove this on w13
130 property alias style: root.platformStyle
133 property int __pressDelay: platformStyle.pressDelay
135 // the title field consists of the following parts: title string and
136 // a close button (which is in fact an image)
137 // it can additionally have an icon
138 titleText:"Selection Dialog"
140 // the content field which contains the selection content
144 property int listViewHeight
145 property int maxListViewHeight : visualParent
146 ? visualParent.height * 0.87
147 - root.platformStyle.titleBarHeight - root.platformStyle.contentSpacing - 50
149 ? root.parent.height * 0.87
150 - root.platformStyle.titleBarHeight - root.platformStyle.contentSpacing - 50
152 height: listViewHeight > maxListViewHeight ? maxListViewHeight : listViewHeight
154 y : root.platformStyle.contentSpacing
157 id: selectionListView
162 delegate: root.delegate
165 pressDelay: __pressDelay
169 flickableItem: selectionListView
170 platformStyle.inverted: true
172 onModelChanged: selectionContent.listViewHeight = model.count * platformStyle.itemHeight