1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
35 /* The view displaying the item grid.
37 The following Qml context properties have to be set:
38 - listmodel itemLibraryModel
39 - int itemLibraryIconWidth
40 - int itemLibraryIconHeight
42 itemLibraryModel has to have the following structure:
48 list sectionEntries: [
66 function scrollView(delta) {
67 scrollbar.scroll(-delta / style.scrollbarWheelDeltaFactor)
70 function resetView() {
75 signal itemSelected(int itemLibId)
76 signal itemDragged(int itemLibId)
78 signal stopDragAndDrop
82 signal expandAllEntries
84 ItemsViewStyle { id: style }
86 color: style.backgroundColor
88 /* workaround: without this, a completed drag and drop operation would
89 result in the drag being continued when QmlView re-gains
100 signal selectionUpdated(int itemSectionIndex)
102 property int selectedItemLibId: -1
103 property int selectionSectionLibId: -1
105 function setSelection(itemLibId) {
106 selectedItemLibId = itemLibId
107 selectionSectionLibId = itemLibraryModel.getSectionLibId(itemLibId)
108 selectionUpdated(itemLibraryModel.getItemSectionIndex(itemLibId))
111 function unsetSelection() {
112 selectedItemLibId = -1
113 selectionSectionLibId = -1
118 target: itemLibraryModel
119 onVisibilityChanged: {
120 if (itemLibraryModel.isItemVisible(selectedItemLibId))
121 setSelection(selectedItemLibId)
127 /* the following 3 properties are calculated here for performance
128 reasons and then passed to the section views */
129 property int entriesPerRow: Math.max(1, Math.floor((itemsFlickable.width - 2) / style.cellWidth))
130 property int cellWidth: Math.floor((itemsFlickable.width - 2) / entriesPerRow)
131 property int cellHeight: style.cellHeight
139 entriesPerRow: itemsView.entriesPerRow
140 cellWidth: itemsView.cellWidth
141 cellHeight: itemsView.cellHeight
143 width: itemsFlickable.width
144 itemHighlight: selector
146 property bool containsSelection: (selectionSectionLibId == sectionLibId)
149 itemsView.setSelection(itemLibId)
150 itemsView.itemSelected(itemLibId)
153 section.itemSelected(itemLibId)
154 itemsView.itemDragged(itemLibId)
159 onExpandAllEntries: section.expand()
160 onSelectionUpdated: {
161 if (containsSelection) {
162 section.setSelection(itemSectionIndex)
163 section.focusSelection(itemsFlickable)
165 section.unsetSelection()
173 x: containsSelection? section.currentItem.x:0
174 y: containsSelection? section.currentItem.y:0
175 width: itemsView.cellWidth
176 height: itemsView.cellHeight
178 visible: containsSelection
187 anchors.top: parent.top
189 anchors.bottom: parent.bottom
190 anchors.left: parent.left
191 anchors.right: scrollbarFrame.left
192 boundsBehavior: Flickable.DragOverBounds
195 contentHeight: col.height
197 /* Limit the content position. Without this, resizing would get the
198 content position out of scope regarding the scrollbar. */
199 function limitContentPos() {
203 var maxContentY = Math.max(0, contentHeight - height)
204 if (contentY > maxContentY)
205 contentY = maxContentY;
208 onHeightChanged: limitContentPos()
209 onContentHeightChanged: limitContentPos()
215 model: itemLibraryModel // to be set in Qml context
216 delegate: sectionDelegate
224 anchors.top: parent.top
226 anchors.bottom: parent.bottom
227 anchors.bottomMargin: 1
228 anchors.right: parent.right
229 width: (itemsFlickable.contentHeight > itemsFlickable.height)? 11:0
234 anchors.leftMargin: 1
236 flickable: itemsFlickable