summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlView.h
blob: 75d07d73575bdb9d4fc68bcb57211d2cde6da243 (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
/****************************************************************************
**
** 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$
**
****************************************************************************/

#ifndef INSPECTORCONTROLVIEW_H
#define INSPECTORCONTROLVIEW_H

#include <QtQuickWidgets/qquickwidget.h>
#include <QtCore/qpointer.h>
#include "DispatchListeners.h"
#include "Dispatch.h"
#include "Qt3DSFileTools.h"
#include "TabOrderHandler.h"
#include "MouseHelper.h"
#include "QmlUtils.h"
#include "DataInputSelectView.h"

class InspectorControlModel;
class VariantsGroupModel;
class CInspectableBase;
class ImageChooserView;
class DataInputSelectView;
class ImageChooserModel;
class MeshChooserView;
class ObjectBrowserView;
class ObjectListModel;
class FileChooserView;
class TextureChooserView;
class MaterialRefView;

QT_FORWARD_DECLARE_CLASS(QAbstractItemModel)

class InspectorControlView : public QQuickWidget,
                             public CPresentationChangeListener,
                             public IDataModelListener,
                             public TabNavigable
{
    Q_OBJECT
    Q_PROPERTY(QString titleText READ titleText NOTIFY titleChanged FINAL)
    Q_PROPERTY(QString titleIcon READ titleIcon NOTIFY titleChanged FINAL)

public:
    explicit InspectorControlView(const QSize &preferredSize, QWidget *parent = nullptr);
    ~InspectorControlView() override;

    void OnSelectionSet(Q3DStudio::SSelectedValue inValue);
    QAbstractItemModel *inspectorControlModel() const;

    QString titleText() const;
    QString titleIcon() const;
    VariantsGroupModel *variantsModel() const { return m_variantsGroupModel; }

    Q_INVOKABLE QColor titleColor(int instance = 0, int handle = 0) const;
    Q_INVOKABLE QColor showColorDialog(const QColor &color, int instance = 0, int handle = 0);
    Q_INVOKABLE void showContextMenu(int x, int y, int handle, int instance);
    Q_INVOKABLE void showTagContextMenu(int x, int y, const QString &group, const QString &tag);
    Q_INVOKABLE void showDataInputChooser(int handle, int instance, const QPoint &point);
    Q_INVOKABLE void showGroupContextMenu(int x, int y, const QString &group);
    Q_INVOKABLE QObject *showImageChooser(int handle, int instance, const QPoint &point);
    Q_INVOKABLE QObject *showFilesChooser(int handle, int instance, const QPoint &point);
    Q_INVOKABLE QObject *showMeshChooser(int handle, int instance, const QPoint &point);
    Q_INVOKABLE QObject *showObjectReference(int handle, int instance, const QPoint &point);
    Q_INVOKABLE QObject *showMaterialReference(int handle, int instance, const QPoint &point);
    Q_INVOKABLE QObject *showTextureChooser(int handle, int instance, const QPoint &point);
    Q_INVOKABLE bool toolTipsEnabled();
    Q_INVOKABLE bool isRefMaterial(int instance) const;
    Q_INVOKABLE bool isEditable(int handle) const;
    Q_INVOKABLE QString convertPathToProjectRoot(const QString &presentationPath);
    Q_INVOKABLE QString noneString() const;

    // IDataModelListener
    void OnBeginDataModelNotifications() override;
    void OnEndDataModelNotifications() override;
    void OnImmediateRefreshInstanceSingle(qt3dsdm::Qt3DSDMInstanceHandle inInstance) override;
    void OnImmediateRefreshInstanceMultiple(qt3dsdm::Qt3DSDMInstanceHandle *inInstance,
                                            long inInstanceCount) override;

Q_SIGNALS:
    void titleChanged();
    void controlsChanged();
    void imageSelected(const QString &name);
    void dialogCurrentColorChanged(const QColor &newColor);

public Q_SLOTS:
    void toggleMasterLink();

protected:
    QSize sizeHint() const override;
    void mousePressEvent(QMouseEvent *event) override;

private:
    void setInspectable(CInspectableBase *inInspectable);
    void initialize();
    void onFilesChanged(const Q3DStudio::TFileModificationList &inFileModificationList);
    void OnNewPresentation() override;
    void OnClosingPresentation() override;
    void filterMaterials(std::vector<Q3DStudio::CFilePath> &materials);
    void filterMatDatas(std::vector<Q3DStudio::CFilePath> &matDatas);
    void setPropertyValueFromFilename(long instance, int handle, const QString &name);
    CInspectableBase *createInspectableFromSelectable(Q3DStudio::SSelectedValue selectable);
    bool canLinkProperty(int instance, int handle) const;
    bool canOpenInInspector(int instance, int handle) const;
    void openInInspector();
    void onPropertyChanged(qt3dsdm::Qt3DSDMInstanceHandle inInstance,
                           qt3dsdm::Qt3DSDMPropertyHandle inProperty);
    void onChildAdded(int inChild);
    void onChildRemoved();

    std::vector<std::shared_ptr<qt3dsdm::ISignalConnection>> m_connections;
    QColor m_backgroundColor;
    VariantsGroupModel *m_variantsGroupModel = nullptr;
    InspectorControlModel *m_inspectorControlModel = nullptr;
    CInspectableBase *m_inspectableBase = nullptr;
    QPointer<ImageChooserView> m_imageChooserView;
    QPointer<MeshChooserView> m_meshChooserView;
    QPointer<FileChooserView> m_fileChooserView;
    QPointer<TextureChooserView> m_textureChooserView;
    QPointer<ObjectBrowserView> m_objectReferenceView;
    QPointer<MaterialRefView> m_matRefListWidget;
    QPointer<ObjectListModel> m_objectReferenceModel;
    QPointer<DataInputSelectView> m_dataInputChooserView;
    std::vector<Q3DStudio::CFilePath> m_fileList;
    MouseHelper m_mouseHelper;
    QmlUtils m_qmlUtils;

    int m_contextMenuInstance = 0;
    int m_contextMenuHandle = 0;

    QSize m_preferredSize;
    QColor m_currentColor;

    class ActiveBrowserData
    {
    public:
        void setData(QWidget *browser, int handle, int instance)
        {
            m_browser = browser;
            m_handle = handle;
            m_instance = instance;
        }
        void clear()
        {
            if (isActive())
                m_browser->close();
            m_browser.clear();
            m_handle = -1;
            m_instance = -1;
        }
        bool isActive() const
        {
            return !m_browser.isNull() && m_browser->isVisible();
        }

        QPointer<QWidget> m_browser = nullptr;
        int m_handle = -1;
        int m_instance = -1;
    };

    ActiveBrowserData m_activeBrowser;
};

#endif // INSPECTORCONTROLVIEW_H