summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Qt3DStudio/Palettes/Project/ProjectView.qml
blob: 73c9481ca39d393d44321e69eda0e838c2d53b69 (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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/****************************************************************************
**
** 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

    Connections {
       target: _parentView.projectModel
       onSelectFileChanged: {
           projectTree.currentIndex = idx; // auto select a newly created file
       }
    }

    ColumnLayout {
        anchors.fill: parent
        spacing: 4

        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
                    property bool dragStarted: false
                    property point pressPoint
                    width: parent.width
                    height: 20
                    color: (index == projectTree.currentIndex || dragging) ? _selectionColor
                                                                           : "transparent"
                    function handlePress(mouse, tryDrag) {
                        projectTree.currentIndex = model.index;

                        if (mouse.button === Qt.LeftButton && tryDrag && _isDraggable) {
                            pressPoint = Qt.point(mouse.x, mouse.y);
                            dragStarted = false;
                        }
                    }

                    function handlePositionChange(mouse, item) {
                        if (_isDraggable && !dragStarted
                                && (Math.abs(mouse.x - pressPoint.x) > 4
                                    || Math.abs(mouse.y - pressPoint.y) > 4)) {
                            dragStarted = true;
                            _parentView.startDrag(item, index);
                        }
                    }

                    function handleClick(mouse) {
                        if (mouse.button === Qt.RightButton) {
                            var rootPoint = mapToItem(root, mouse.x, mouse.y);
                            _parentView.showContextMenu(rootPoint.x, rootPoint.y,
                                                        projectTree.currentIndex);
                        }
                    }

                    function handleDoubleClick(mouse) {
                        if (mouse.button === Qt.LeftButton) {
                            if (_isExpandable) {
                                if (_expanded)
                                    projectTree.model.collapse(index);
                                else
                                    projectTree.model.expand(index);
                            } else {
                                _parentView.openFile(index);
                            }
                        }
                    }

                    MouseArea {
                        id: delegateMouseArea
                        anchors.fill: parent
                        acceptedButtons: Qt.RightButton | Qt.LeftButton

                        onPressed: delegateItem.handlePress(mouse, false)
                        onClicked: delegateItem.handleClick(mouse)
                        onDoubleClicked: delegateItem.handleDoubleClick(mouse)

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

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

                                MouseArea {
                                    visible: _isExpandable
                                    anchors.fill: parent
                                    acceptedButtons: Qt.LeftButton
                                    onPressed: delegateItem.handlePress(mouse, false)
                                    onClicked: {
                                        if (_expanded)
                                            projectTree.model.collapse(index)
                                        else
                                            projectTree.model.expand(index)
                                    }
                                }
                            }

                            Image {
                                id: fileIconImage
                                source: fileIcon
                                MouseArea {
                                    anchors.fill: parent
                                    acceptedButtons: Qt.RightButton | Qt.LeftButton
                                    onPressed: delegateItem.handlePress(mouse, true)
                                    onPositionChanged: delegateItem.handlePositionChange(
                                                           mouse, fileIconImage)
                                    onClicked: delegateItem.handleClick(mouse)
                                    onDoubleClicked: delegateItem.handleDoubleClick(mouse)
                                }
                            }

                            StyledLabel {
                                id: fileNameLabel
                                text: _fileId ? fileName + " <" + _fileId + ">" : fileName;
                                color: {
                                    _isReferenced ? _textColor
                                                  : _isProjectReferenced ? _projectReferencedColor
                                                                         : _disabledColor
                                }
                                leftPadding: 2

                                MouseArea {
                                    anchors.fill: parent
                                    acceptedButtons: Qt.RightButton | Qt.LeftButton
                                    onPressed: delegateItem.handlePress(mouse, true)
                                    onPositionChanged: delegateItem.handlePositionChange(
                                                           mouse, fileNameLabel)
                                    onClicked: delegateItem.handleClick(mouse)
                                    onDoubleClicked: delegateItem.handleDoubleClick(mouse)
                                }
                            }

                            Item {
                                // Spacer item
                                width: 4
                                height: 1
                            }

                            Image {
                                source: _extraIcon ? _resDir + _extraIcon : ""
                                visible: _extraIcon ? true : false

                                MouseArea {
                                    id: warningMouseArea
                                    anchors.fill: parent
                                    acceptedButtons: Qt.RightButton | Qt.LeftButton
                                    hoverEnabled: true
                                    onPressed: delegateItem.handlePress(mouse, false)
                                    onClicked: delegateItem.handleClick(mouse)
                                    onDoubleClicked: _parentView.editPresentationId(
                                                         index, _parentView.isQmlStream(index))
                                }
                                StyledTooltip {
                                    text: _parentView.isPresentation(index)
                                          ? qsTr("No presentation Id")
                                          : qsTr("No Qml stream Id")
                                    enabled: warningMouseArea.containsMouse
                                }
                            }
                        }
                    }

                    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;
                        }
                    }
                }
                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 {
            Layout.fillWidth: true
            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")
            }
        }
    }
}