summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/Project/ProjectView.qml
blob: 387bbba20522cf531c7c530efc8e3bc1c59b41da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.8
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../controls"

Rectangle {
    id: root

    color: _backgroundColor

    ColumnLayout {
        anchors.fill: parent
        spacing: 4
        width: parent.width

        Item {
            Layout.fillWidth: true
            Layout.fillHeight: true

            MouseArea {
                anchors.fill: parent
                acceptedButtons: Qt.RightButton
                onClicked: {
                    _parentView.showContextMenu(mouse.x, mouse.y, projectTree.currentIndex);
                }
            }

            ListView {
                id: projectTree

                anchors.fill: parent
                clip: true

                ScrollBar.vertical: ScrollBar {}

                model: _parentView.projectModel

                onCurrentIndexChanged: {
                    // Try to keep something selected always
                    if ((currentIndex < 0 || currentIndex >= count) && count > 0)
                        currentIndex = 0;
                }

                delegate: Rectangle {
                    id: delegateItem
                    property bool dragging: false
                    width: parent.width
                    height: 20
                    color: (index == projectTree.currentIndex || dragging) ? _selectionColor
                                                                           : "transparent"

                    Row {
                        x: _depth*28
                        anchors.verticalCenter: delegateItem.verticalCenter

                        Image {
                            source: _resDir + (_expanded ? "arrow_down.png" : "arrow.png")
                            opacity: _isExpandable ? 1 : 0

                            MouseArea {
                                visible: _isExpandable
                                anchors.fill: parent
                                onClicked: {
                                    if (_expanded)
                                       projectTree.model.collapse(index)
                                    else
                                        projectTree.model.expand(index)
                                    delegateMouseArea.clickPending = false
                                }
                            }
                        }

                        Image {
                            source: fileIcon

                            Item {
                                id: dragItemIcon

                                visible: _isDraggable
                                anchors.fill: parent

                                Drag.active: dragAreaIcon.drag.active
                                Drag.hotSpot.x: width / 2
                                Drag.hotSpot.y: height / 2
                                Drag.dragType: Drag.Automatic
                                Drag.supportedActions: Qt.CopyAction

                                MouseArea {
                                    id: dragAreaIcon
                                    anchors.fill: parent
                                    drag.target: dragItemIcon
                                }

                                Drag.onDragStarted: _parentView.startDrag(dragAreaIcon, index)
                            }
                        }

                        StyledLabel {
                            text: fileName
                            color: _isReferenced ? _textColor : _disabledColor
                            leftPadding: 2

                            Item {
                                id: dragItem

                                visible: _isDraggable
                                anchors.fill: parent

                                Drag.active: dragArea.drag.active
                                Drag.hotSpot.x: width / 2
                                Drag.hotSpot.y: height / 2
                                Drag.dragType: Drag.Automatic
                                Drag.supportedActions: Qt.CopyAction

                                MouseArea {
                                    id: dragArea
                                    anchors.fill: parent
                                    drag.target: dragItem
                                }

                                Drag.onDragStarted: _parentView.startDrag(dragArea, index)
                            }
                        }
                    }

                    DropArea {
                        anchors.fill: parent

                        onEntered: {
                            if (drag.hasUrls
                                    && projectTree.model.hasValidUrlsForDropping(drag.urls)) {
                                dragging = true;
                                drag.accept(Qt.CopyAction)
                            } else {
                                drag.accepted = false;
                            }
                        }

                        onExited: {
                            dragging = false;
                        }

                        onDropped: {
                            if (drop.hasUrls)
                                projectTree.model.importUrls(drop.urls, index, false);
                            dragging = false;
                        }
                    }

                    MouseArea {
                        id: delegateMouseArea
                        property bool clickPending: false
                        anchors.fill: parent
                        acceptedButtons: Qt.RightButton|Qt.LeftButton
                        propagateComposedEvents: true
                        onPressed: {
                            projectTree.currentIndex = model.index;

                            // Presses must be ignored by this handler in order for dragging to work
                            mouse.accepted = false;

                            // Since ignoring presses means we don't get doubleClicked events,
                            // detect doubleclick using custom timer.
                            if (clickPending) {
                                if (_isExpandable) {
                                    if (_expanded)
                                        projectTree.model.collapse(index);
                                    else
                                        projectTree.model.expand(index);
                                }
                                clickPending = false;
                            } else {
                                clickPending = true;
                                doubleClickTimer.restart();
                            }
                        }
                        Timer {
                            id: doubleClickTimer
                            repeat: false
                            triggeredOnStart: false
                            interval: 500
                            onTriggered: parent.clickPending = false;
                        }
                    }
                }
                DropArea {
                    // Leftover listview area. Dropping here is equivalent to dropping to root
                    anchors.bottom: parent.bottom
                    anchors.left: parent.left
                    anchors.right: parent.right
                    height: parent.height - parent.contentHeight
                    onEntered: {
                        if (drag.hasUrls && projectTree.model.hasValidUrlsForDropping(drag.urls))
                            drag.accept(Qt.CopyAction)
                        else
                            drag.accepted = false;
                    }
                    onDropped: {
                        if (drop.hasUrls)
                            projectTree.model.importUrls(drop.urls, 0, false)
                    }
                }
            }
        }

        StyledMenuSeparator {
            leftPadding: 12
            rightPadding: 12
        }

        RowLayout {
            width: parent.width
            Layout.margins: 4
            Layout.rightMargin: 12
            Layout.leftMargin: 12

            StyledToolButton {
                enabledImage: "Asset-import-Normal.png";
                onClicked: _parentView.assetImportAction(projectTree.currentIndex);
                toolTipText: qsTr("Import Assets");
            }

            Item {
                Layout.fillWidth: true
            }

            StyledToolButton {
                enabledImage: "Objects-Effect-Normal.png";
                onClicked: _parentView.effectAction(projectTree.currentIndex)
                toolTipText: qsTr("Open Effect Library")
            }

            StyledToolButton {
                enabledImage: "Objects-Text-Normal.png";
                onClicked: _parentView.fontAction(projectTree.currentIndex)
                toolTipText: qsTr("Open Font Library")
            }

            StyledToolButton {
                enabledImage: "Objects-Image-Normal.png";
                onClicked: _parentView.imageAction(projectTree.currentIndex)
                toolTipText: qsTr("Open Map Library")
            }

            StyledToolButton {
                enabledImage: "Objects-Material-Normal.png";
                onClicked: _parentView.materialAction(projectTree.currentIndex)
                toolTipText: qsTr("Open Material Library")
            }

            StyledToolButton {
                enabledImage: "Assets-Model.png";
                onClicked: _parentView.modelAction(projectTree.currentIndex)
                toolTipText: qsTr("Open Model Library")
            }

            StyledToolButton {
                enabledImage: "Objects-Behavior-Normal.png";
                onClicked: _parentView.behaviorAction(projectTree.currentIndex)
                toolTipText: qsTr("Open Behavior Library")
            }
        }
    }
}