2010-02-16 19:07:59 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-04-13 11:37:57 +02:00
|
|
|
import Qt 4.7
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
/* The view displaying the item grid.
|
|
|
|
|
|
2010-03-18 13:17:24 +02:00
|
|
|
The following Qml context properties have to be set:
|
|
|
|
|
- listmodel itemLibraryModel
|
|
|
|
|
- int itemLibraryIconWidth
|
|
|
|
|
- int itemLibraryIconHeight
|
|
|
|
|
|
|
|
|
|
itemLibraryModel has to have the following structure:
|
|
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
|
ListElement {
|
|
|
|
|
int sectionLibId
|
|
|
|
|
string sectionName
|
|
|
|
|
list sectionEntries: [
|
|
|
|
|
ListElement {
|
|
|
|
|
int itemLibId
|
|
|
|
|
string itemName
|
|
|
|
|
pixmap itemPixmap
|
|
|
|
|
},
|
|
|
|
|
...
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
...
|
|
|
|
|
}
|
2010-03-10 12:45:49 +02:00
|
|
|
*/
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
Rectangle {
|
|
|
|
|
id: itemsView
|
|
|
|
|
|
2010-02-25 09:45:00 +02:00
|
|
|
// public
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-05-31 15:27:52 +03:00
|
|
|
function scrollView(delta) {
|
|
|
|
|
scrollbar.scroll(-delta / style.scrollbarWheelDeltaFactor)
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
function resetView() {
|
|
|
|
|
expandAllEntries()
|
|
|
|
|
scrollbar.reset()
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-25 09:45:00 +02:00
|
|
|
signal itemSelected(int itemLibId)
|
|
|
|
|
signal itemDragged(int itemLibId)
|
|
|
|
|
|
|
|
|
|
signal stopDragAndDrop
|
|
|
|
|
|
|
|
|
|
// internal
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-02-25 09:45:00 +02:00
|
|
|
signal expandAllEntries
|
|
|
|
|
|
|
|
|
|
ItemsViewStyle { id: style }
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
color: style.backgroundColor
|
|
|
|
|
|
|
|
|
|
/* workaround: without this, a completed drag and drop operation would
|
2010-03-18 13:17:24 +02:00
|
|
|
result in the drag being continued when QmlView re-gains
|
|
|
|
|
focus */
|
2010-03-05 10:19:38 +01:00
|
|
|
MouseArea {
|
2010-02-16 17:24:18 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
|
hoverEnabled: true
|
2010-03-10 12:45:49 +02:00
|
|
|
onEntered: {
|
2010-03-18 13:17:24 +02:00
|
|
|
if (!pressed)
|
|
|
|
|
stopDragAndDrop()
|
|
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
2010-03-18 13:17:24 +02:00
|
|
|
signal selectionUpdated(int itemSectionIndex)
|
|
|
|
|
|
|
|
|
|
property int selectedItemLibId: -1
|
|
|
|
|
property int selectionSectionLibId: -1
|
|
|
|
|
|
|
|
|
|
function setSelection(itemLibId) {
|
|
|
|
|
selectedItemLibId = itemLibId
|
|
|
|
|
selectionSectionLibId = itemLibraryModel.getSectionLibId(itemLibId)
|
|
|
|
|
selectionUpdated(itemLibraryModel.getItemSectionIndex(itemLibId))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unsetSelection() {
|
|
|
|
|
selectedItemLibId = -1
|
|
|
|
|
selectionSectionLibId = -1
|
|
|
|
|
selectionUpdated(-1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: itemLibraryModel
|
|
|
|
|
onVisibilityChanged: {
|
|
|
|
|
if (itemLibraryModel.isItemVisible(selectedItemLibId))
|
|
|
|
|
setSelection(selectedItemLibId)
|
|
|
|
|
else
|
|
|
|
|
unsetSelection()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the following 3 properties are calculated here for performance
|
|
|
|
|
reasons and then passed to the section views */
|
|
|
|
|
property int entriesPerRow: Math.max(1, Math.floor((itemsFlickable.width - 2) / style.cellWidth))
|
|
|
|
|
property int cellWidth: Math.floor((itemsFlickable.width - 2) / entriesPerRow)
|
|
|
|
|
property int cellHeight: style.cellHeight
|
|
|
|
|
|
|
|
|
|
Component {
|
|
|
|
|
id: sectionDelegate
|
|
|
|
|
|
|
|
|
|
SectionView {
|
|
|
|
|
id: section
|
|
|
|
|
|
|
|
|
|
entriesPerRow: itemsView.entriesPerRow
|
|
|
|
|
cellWidth: itemsView.cellWidth
|
|
|
|
|
cellHeight: itemsView.cellHeight
|
|
|
|
|
|
|
|
|
|
width: itemsFlickable.width
|
|
|
|
|
itemHighlight: selector
|
|
|
|
|
|
|
|
|
|
property bool containsSelection: (selectionSectionLibId == sectionLibId)
|
|
|
|
|
|
|
|
|
|
onItemSelected: {
|
|
|
|
|
itemsView.setSelection(itemLibId)
|
|
|
|
|
itemsView.itemSelected(itemLibId)
|
|
|
|
|
}
|
|
|
|
|
onItemDragged: {
|
|
|
|
|
section.itemSelected(itemLibId)
|
|
|
|
|
itemsView.itemDragged(itemLibId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: itemsView
|
|
|
|
|
onExpandAllEntries: section.expand()
|
|
|
|
|
onSelectionUpdated: {
|
|
|
|
|
if (containsSelection) {
|
|
|
|
|
section.setSelection(itemSectionIndex)
|
|
|
|
|
section.focusSelection(itemsFlickable)
|
|
|
|
|
} else
|
|
|
|
|
section.unsetSelection()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component {
|
|
|
|
|
id: selector
|
|
|
|
|
|
|
|
|
|
Selector {
|
|
|
|
|
x: containsSelection? section.currentItem.x:0
|
|
|
|
|
y: containsSelection? section.currentItem.y:0
|
|
|
|
|
width: itemsView.cellWidth
|
|
|
|
|
height: itemsView.cellHeight
|
|
|
|
|
|
|
|
|
|
visible: containsSelection
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Flickable {
|
|
|
|
|
id: itemsFlickable
|
|
|
|
|
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: 3
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.left: parent.left
|
2010-04-12 15:40:11 +03:00
|
|
|
anchors.right: scrollbarFrame.left
|
2010-04-23 13:00:04 +02:00
|
|
|
boundsBehavior: Flickable.DragOverBounds
|
2010-03-18 13:17:24 +02:00
|
|
|
|
|
|
|
|
interactive: false
|
|
|
|
|
contentHeight: col.height
|
|
|
|
|
|
|
|
|
|
/* Limit the content position. Without this, resizing would get the
|
|
|
|
|
content position out of scope regarding the scrollbar. */
|
|
|
|
|
function limitContentPos() {
|
|
|
|
|
if (contentY < 0)
|
|
|
|
|
contentY = 0;
|
|
|
|
|
else {
|
|
|
|
|
var maxContentY = Math.max(0, contentHeight - height)
|
|
|
|
|
if (contentY > maxContentY)
|
|
|
|
|
contentY = maxContentY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onHeightChanged: limitContentPos()
|
|
|
|
|
onContentHeightChanged: limitContentPos()
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
id: col
|
|
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
model: itemLibraryModel // to be set in Qml context
|
|
|
|
|
delegate: sectionDelegate
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-12 15:40:11 +03:00
|
|
|
Item {
|
|
|
|
|
id: scrollbarFrame
|
2010-03-18 13:17:24 +02:00
|
|
|
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: 2
|
|
|
|
|
anchors.bottom: parent.bottom
|
2010-04-12 15:40:11 +03:00
|
|
|
anchors.bottomMargin: 1
|
2010-03-18 13:17:24 +02:00
|
|
|
anchors.right: parent.right
|
2010-04-29 14:40:33 +03:00
|
|
|
width: (itemsFlickable.contentHeight > itemsFlickable.height)? 11:0
|
2010-03-18 13:17:24 +02:00
|
|
|
|
2010-04-12 15:40:11 +03:00
|
|
|
Scrollbar {
|
|
|
|
|
id: scrollbar
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.leftMargin: 1
|
|
|
|
|
|
|
|
|
|
flickable: itemsFlickable
|
|
|
|
|
}
|
2010-03-18 13:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|