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
|
|
|
// view displaying one item library section including its grid
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
Column {
|
|
|
|
|
id: sectionView
|
|
|
|
|
|
2010-02-25 09:45:00 +02:00
|
|
|
// public
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-04-13 11:20:39 +02:00
|
|
|
property variant itemHighlight
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
property int entriesPerRow
|
|
|
|
|
property int cellWidth
|
|
|
|
|
property int cellHeight
|
|
|
|
|
|
2010-04-13 11:20:39 +02:00
|
|
|
property variant currentItem: gridView.currentItem
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
function expand() {
|
2010-03-10 12:45:49 +02:00
|
|
|
gridFrame.state = ""
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-25 09:45:00 +02:00
|
|
|
signal itemSelected(int itemLibId)
|
|
|
|
|
signal itemDragged(int itemLibId)
|
|
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
function setSelection(itemSectionIndex)
|
|
|
|
|
{
|
2010-03-18 13:17:24 +02:00
|
|
|
gridView.currentIndex = itemSectionIndex
|
2010-03-10 12:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unsetSelection()
|
|
|
|
|
{
|
2010-03-18 13:17:24 +02:00
|
|
|
gridView.currentIndex = -1
|
2010-03-10 12:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function focusSelection(flickable) {
|
2010-03-18 13:17:24 +02:00
|
|
|
var pos = -1;
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-03-18 13:17:24 +02:00
|
|
|
if (!gridView.currentItem)
|
|
|
|
|
return;
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-03-18 13:17:24 +02:00
|
|
|
var currentItemX = sectionView.x + gridFrame.x + gridView.x + gridView.currentItem.x;
|
|
|
|
|
var currentItemY = sectionView.y + gridFrame.y + gridView.y + gridView.currentItem.y
|
|
|
|
|
- gridView.contentY; // workaround: GridView reports wrong contentY
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-03-18 13:17:24 +02:00
|
|
|
if (currentItemY < flickable.contentY)
|
|
|
|
|
pos = Math.max(0, currentItemY)
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-03-18 13:17:24 +02:00
|
|
|
else if ((currentItemY + gridView.currentItem.height) >
|
|
|
|
|
(flickable.contentY + flickable.height - 1))
|
|
|
|
|
pos = Math.min(Math.max(0, flickable.contentHeight - flickable.height),
|
|
|
|
|
currentItemY + gridView.currentItem.height - flickable.height + 1)
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-03-18 13:17:24 +02:00
|
|
|
if (pos >= 0)
|
|
|
|
|
flickable.contentY = pos
|
2010-03-10 12:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-25 09:45:00 +02:00
|
|
|
// internal
|
|
|
|
|
|
|
|
|
|
ItemsViewStyle { id: style }
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
Component {
|
|
|
|
|
id: itemDelegate
|
|
|
|
|
|
|
|
|
|
ItemView {
|
|
|
|
|
id: item
|
2010-02-25 09:45:00 +02:00
|
|
|
|
2010-03-18 13:17:24 +02:00
|
|
|
width: cellWidth
|
|
|
|
|
height: cellHeight
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
onItemPressed: sectionView.itemSelected(itemLibId)
|
|
|
|
|
onItemDragged: sectionView.itemDragged(itemLibId)
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
// clickable header bar
|
2010-02-16 17:24:18 +02:00
|
|
|
Rectangle {
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: style.sectionTitleHeight
|
|
|
|
|
|
|
|
|
|
color: style.sectionTitleBackgroundColor
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: arrow
|
|
|
|
|
|
2010-04-30 12:28:08 +03:00
|
|
|
Rectangle { y: 0; x: 0; height: 1; width: 11; color: style.sectionArrowColor }
|
|
|
|
|
Rectangle { y: 1; x: 1; height: 1; width: 9; color: style.sectionArrowColor }
|
|
|
|
|
Rectangle { y: 2; x: 2; height: 1; width: 7; color: style.sectionArrowColor }
|
|
|
|
|
Rectangle { y: 3; x: 3; height: 1; width: 5; color: style.sectionArrowColor }
|
|
|
|
|
Rectangle { y: 4; x: 4; height: 1; width: 3; color: style.sectionArrowColor }
|
|
|
|
|
Rectangle { y: 5; x: 5; height: 1; width: 1; color: style.sectionArrowColor }
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
anchors.left: parent.left
|
2010-04-30 12:28:08 +03:00
|
|
|
anchors.leftMargin: 10
|
2010-02-16 17:24:18 +02:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2010-04-30 12:28:08 +03:00
|
|
|
width: 11
|
|
|
|
|
height: 6
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
transformOrigin: Item.Center
|
|
|
|
|
}
|
|
|
|
|
Text {
|
|
|
|
|
id: text
|
|
|
|
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
anchors.left: arrow.right
|
2010-04-30 12:28:08 +03:00
|
|
|
anchors.leftMargin: 12
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
text: sectionName // to be set by model
|
2010-02-16 17:24:18 +02:00
|
|
|
color: style.sectionTitleTextColor
|
2010-03-18 13:17:24 +02:00
|
|
|
elide: Text.ElideMiddle
|
2010-04-30 12:28:08 +03:00
|
|
|
font.bold: true
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
2010-03-05 10:19:38 +01:00
|
|
|
MouseArea {
|
2010-02-16 17:24:18 +02:00
|
|
|
anchors.fill: parent
|
2010-03-10 12:45:49 +02:00
|
|
|
onClicked: gridFrame.toggleExpanded()
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item { height: 2; width: 1 }
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: gridFrame
|
|
|
|
|
|
2010-02-25 09:45:00 +02:00
|
|
|
function toggleExpanded() {
|
|
|
|
|
state = ((state == "")? "shrunk":"")
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clip: true
|
2010-02-25 09:45:00 +02:00
|
|
|
width: entriesPerRow * cellWidth + 1
|
|
|
|
|
height: Math.ceil(sectionEntries.count / entriesPerRow) * cellHeight + 1
|
2010-02-16 17:24:18 +02:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
|
|
|
|
|
GridView {
|
|
|
|
|
id: gridView
|
|
|
|
|
|
2010-03-01 11:37:21 +01:00
|
|
|
Connections {
|
2010-03-10 12:45:49 +02:00
|
|
|
target: itemLibraryModel // to be set in Qml context
|
|
|
|
|
onSectionVisibilityChanged: {
|
2010-03-18 13:17:24 +02:00
|
|
|
/* workaround: reset model in order to get the grid view
|
|
|
|
|
updated properly under all conditions */
|
|
|
|
|
if (changedSectionLibId == sectionLibId)
|
|
|
|
|
gridView.model = sectionEntries
|
|
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.rightMargin: 1
|
|
|
|
|
anchors.bottomMargin: 1
|
|
|
|
|
|
|
|
|
|
cellWidth: sectionView.cellWidth
|
|
|
|
|
cellHeight: sectionView.cellHeight
|
2010-03-10 12:45:49 +02:00
|
|
|
model: sectionEntries // to be set by model
|
2010-02-16 17:24:18 +02:00
|
|
|
delegate: itemDelegate
|
2010-03-18 13:17:24 +02:00
|
|
|
highlight: itemHighlight
|
2010-02-16 17:24:18 +02:00
|
|
|
interactive: false
|
|
|
|
|
highlightFollowsCurrentItem: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
states: [
|
2010-03-18 13:17:24 +02:00
|
|
|
State {
|
|
|
|
|
name: "shrunk"
|
|
|
|
|
PropertyChanges {
|
|
|
|
|
target: gridFrame
|
|
|
|
|
height: 0
|
|
|
|
|
opacity: 0
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
2010-03-18 13:17:24 +02:00
|
|
|
PropertyChanges {
|
|
|
|
|
target: arrow
|
|
|
|
|
rotation: -90
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item { height: 4; width: 1 }
|
|
|
|
|
}
|