aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/materialeditor/materialeditorcontextobject.h
blob: af155511338c814e68e53b9d38b6c3b6037c0f28 (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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#pragma once

#include <model.h>
#include <modelnode.h>

#include <QObject>
#include <QUrl>
#include <QQmlPropertyMap>
#include <QQmlComponent>
#include <QColor>
#include <QPoint>
#include <QMouseEvent>

namespace QmlDesigner {

class MaterialEditorContextObject : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QUrl specificsUrl READ specificsUrl WRITE setSpecificsUrl NOTIFY specificsUrlChanged)
    Q_PROPERTY(QString specificQmlData READ specificQmlData WRITE setSpecificQmlData NOTIFY specificQmlDataChanged)
    Q_PROPERTY(QQmlComponent *specificQmlComponent READ specificQmlComponent NOTIFY specificQmlComponentChanged)

    Q_PROPERTY(QString stateName READ stateName WRITE setStateName NOTIFY stateNameChanged)
    Q_PROPERTY(QStringList allStateNames READ allStateNames WRITE setAllStateNames NOTIFY allStateNamesChanged)
    Q_PROPERTY(QStringList possibleTypes READ possibleTypes WRITE setPossibleTypes NOTIFY possibleTypesChanged)
    Q_PROPERTY(int possibleTypeIndex READ possibleTypeIndex NOTIFY possibleTypeIndexChanged)

    Q_PROPERTY(bool isBaseState READ isBaseState WRITE setIsBaseState NOTIFY isBaseStateChanged)
    Q_PROPERTY(bool selectionChanged READ selectionChanged WRITE setSelectionChanged NOTIFY selectionChangedChanged)

    Q_PROPERTY(int majorVersion READ majorVersion WRITE setMajorVersion NOTIFY majorVersionChanged)

    Q_PROPERTY(bool hasAliasExport READ hasAliasExport NOTIFY hasAliasExportChanged)
    Q_PROPERTY(bool hasActiveTimeline READ hasActiveTimeline NOTIFY hasActiveTimelineChanged)
    Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged)
    Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged)
    Q_PROPERTY(bool hasMaterialRoot READ hasMaterialRoot WRITE setHasMaterialRoot NOTIFY hasMaterialRootChanged)

    Q_PROPERTY(QQmlPropertyMap *backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged)

public:
    MaterialEditorContextObject(QQmlContext *context, QObject *parent = nullptr);

    QUrl specificsUrl() const { return m_specificsUrl; }
    QString specificQmlData() const {return m_specificQmlData; }
    QQmlComponent *specificQmlComponent();
    QString stateName() const { return m_stateName; }
    QStringList allStateNames() const { return m_allStateNames; }
    QStringList possibleTypes() const { return m_possibleTypes; }
    int possibleTypeIndex() const { return m_possibleTypeIndex; }

    bool isBaseState() const { return m_isBaseState; }
    bool selectionChanged() const { return m_selectionChanged; }

    QQmlPropertyMap *backendValues() const { return m_backendValues; }

    Q_INVOKABLE QString convertColorToString(const QVariant &color);
    Q_INVOKABLE QColor colorFromString(const QString &colorString);

    Q_INVOKABLE void changeTypeName(const QString &typeName);
    Q_INVOKABLE void insertKeyframe(const QString &propertyName);

    Q_INVOKABLE void hideCursor();
    Q_INVOKABLE void restoreCursor();
    Q_INVOKABLE void holdCursorInPlace();

    Q_INVOKABLE int devicePixelRatio();

    Q_INVOKABLE QStringList allStatesForId(const QString &id);

    Q_INVOKABLE bool isBlocked(const QString &propName) const;
    Q_INVOKABLE void goIntoComponent();

    enum ToolBarAction {
        ApplyToSelected = 0,
        ApplyToSelectedAdd,
        AddNewMaterial,
        DeleteCurrentMaterial,
        OpenMaterialBrowser
    };
    Q_ENUM(ToolBarAction)

    int majorVersion() const;
    void setMajorVersion(int majorVersion);

    bool hasActiveTimeline() const;
    void setHasActiveTimeline(bool b);

    bool hasQuick3DImport() const;
    void setHasQuick3DImport(bool b);

    bool hasMaterialRoot() const;
    void setHasMaterialRoot(bool b);

    bool hasModelSelection() const;
    void setHasModelSelection(bool b);

    bool hasAliasExport() const { return m_aliasExport; }

    void setSelectedMaterial(const ModelNode &matNode);

    void setSpecificsUrl(const QUrl &newSpecificsUrl);
    void setSpecificQmlData(const QString &newSpecificQmlData);
    void setStateName(const QString &newStateName);
    void setAllStateNames(const QStringList &allStates);
    void setPossibleTypes(const QStringList &types);
    void setCurrentType(const QString &type);
    void setIsBaseState(bool newIsBaseState);
    void setSelectionChanged(bool newSelectionChanged);
    void setBackendValues(QQmlPropertyMap *newBackendValues);
    void setModel(QmlDesigner::Model *model);

    void triggerSelectionChanged();
    void setHasAliasExport(bool hasAliasExport);

signals:
    void specificsUrlChanged();
    void specificQmlDataChanged();
    void specificQmlComponentChanged();
    void stateNameChanged();
    void allStateNamesChanged();
    void possibleTypesChanged();
    void possibleTypeIndexChanged();
    void isBaseStateChanged();
    void selectionChangedChanged();
    void backendValuesChanged();
    void majorVersionChanged();
    void hasAliasExportChanged();
    void hasActiveTimelineChanged();
    void hasQuick3DImportChanged();
    void hasMaterialRootChanged();
    void hasModelSelectionChanged();

private:
    void updatePossibleTypeIndex();

    QUrl m_specificsUrl;
    QString m_specificQmlData;
    QQmlComponent *m_specificQmlComponent = nullptr;
    QQmlContext *m_qmlContext = nullptr;

    QString m_stateName;
    QStringList m_allStateNames;
    QStringList m_possibleTypes;
    int m_possibleTypeIndex = -1;
    QString m_currentType;

    int m_majorVersion = 1;

    QQmlPropertyMap *m_backendValues = nullptr;
    Model *m_model = nullptr;

    QPoint m_lastPos;

    bool m_isBaseState = false;
    bool m_selectionChanged = false;
    bool m_aliasExport = false;
    bool m_hasActiveTimeline = false;
    bool m_hasQuick3DImport = false;
    bool m_hasMaterialRoot = false;
    bool m_hasModelSelection = false;

    ModelNode m_selectedMaterial;
};

} // QmlDesigner