2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-02-16 19:07:59 +02:00
|
|
|
|
2013-09-13 17:06:10 +02:00
|
|
|
import QtQuick 2.1
|
2010-03-10 12:45:49 +02:00
|
|
|
// view displaying an item library grid item
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
Item {
|
|
|
|
|
id: itemView
|
|
|
|
|
|
2010-02-25 09:45:00 +02:00
|
|
|
// public
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-02-19 14:21:36 +02:00
|
|
|
signal itemPressed()
|
2010-02-16 17:24:18 +02:00
|
|
|
signal itemDragged()
|
|
|
|
|
|
2010-02-25 09:45:00 +02:00
|
|
|
// internal
|
|
|
|
|
|
|
|
|
|
ItemsViewStyle { id: style }
|
2010-03-10 12:45:49 +02:00
|
|
|
|
|
|
|
|
// frame
|
2010-02-16 17:24:18 +02:00
|
|
|
Rectangle {
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.left: parent.left
|
2010-02-17 11:58:33 +01:00
|
|
|
anchors.right: parent.right
|
2010-02-16 17:24:18 +02:00
|
|
|
height: 1
|
2010-02-17 11:56:16 +01:00
|
|
|
color: style.gridLineLighter
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
height: 1
|
2010-02-17 11:56:16 +01:00
|
|
|
color: style.gridLineDarker
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
width: 1
|
2010-02-17 11:56:16 +01:00
|
|
|
color: style.gridLineLighter
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
width: 1
|
2010-02-17 11:56:16 +01:00
|
|
|
color: style.gridLineDarker
|
|
|
|
|
}
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.top:parent.top
|
|
|
|
|
anchors.right:parent.right
|
|
|
|
|
width:1
|
|
|
|
|
height:1
|
|
|
|
|
color: style.backgroundColor
|
|
|
|
|
}
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.bottom:parent.bottom
|
|
|
|
|
anchors.left:parent.left
|
|
|
|
|
width:1
|
|
|
|
|
height:1
|
|
|
|
|
color: style.backgroundColor
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Image {
|
|
|
|
|
id: itemIcon
|
|
|
|
|
|
|
|
|
|
anchors.top: parent.top
|
2010-02-25 09:45:00 +02:00
|
|
|
anchors.topMargin: style.cellVerticalMargin
|
2010-02-16 17:24:18 +02:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
width: itemLibraryIconWidth // to be set in Qml context
|
|
|
|
|
height: itemLibraryIconHeight // to be set in Qml context
|
2010-07-13 10:11:05 +10:00
|
|
|
source: itemLibraryIconPath // to be set by model
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
id: text
|
2010-03-18 13:17:24 +02:00
|
|
|
elide: Text.ElideMiddle
|
2010-02-16 17:24:18 +02:00
|
|
|
anchors.top: itemIcon.bottom
|
2010-02-25 09:45:00 +02:00
|
|
|
anchors.topMargin: style.cellVerticalSpacing
|
2010-03-10 12:45:49 +02:00
|
|
|
anchors.left: parent.left
|
2010-03-18 13:17:24 +02:00
|
|
|
anchors.leftMargin: style.cellHorizontalMargin
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.rightMargin: style.cellHorizontalMargin
|
2010-02-16 17:24:18 +02:00
|
|
|
width: style.textWidth
|
|
|
|
|
height: style.textHeight
|
|
|
|
|
|
|
|
|
|
verticalAlignment: "AlignVCenter"
|
|
|
|
|
horizontalAlignment: "AlignHCenter"
|
2010-03-10 12:45:49 +02:00
|
|
|
text: itemName // to be set by model
|
2010-02-16 17:24:18 +02:00
|
|
|
color: style.itemNameTextColor
|
2013-09-18 12:40:51 +02:00
|
|
|
renderType: Text.NativeRendering
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
2010-03-05 10:19:38 +01:00
|
|
|
MouseArea {
|
2010-03-10 12:45:49 +02:00
|
|
|
id: mouseRegion
|
2010-02-16 17:24:18 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
|
|
2010-02-19 14:21:36 +02:00
|
|
|
property bool reallyPressed: false
|
|
|
|
|
property int pressedX
|
|
|
|
|
property int pressedY
|
|
|
|
|
|
|
|
|
|
onPressed: {
|
|
|
|
|
reallyPressed = true
|
|
|
|
|
pressedX = mouse.x
|
|
|
|
|
pressedY = mouse.y
|
|
|
|
|
itemPressed()
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
2010-02-19 14:21:36 +02:00
|
|
|
onPositionChanged: {
|
|
|
|
|
if (reallyPressed &&
|
2010-03-10 12:45:49 +02:00
|
|
|
(Math.abs(mouse.x - pressedX) +
|
|
|
|
|
Math.abs(mouse.y - pressedY)) > 3) {
|
2010-02-19 14:21:36 +02:00
|
|
|
itemDragged()
|
2010-03-10 12:45:49 +02:00
|
|
|
reallyPressed = false
|
2010-02-19 14:21:36 +02:00
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
2010-02-19 14:21:36 +02:00
|
|
|
onReleased: reallyPressed = false
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|