summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/Action/ActionView.h
blob: a4b717893b6b98531fa3750f5bcbb33383957ef2 (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
/****************************************************************************
**
** 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 ACTIONVIEW_H
#define ACTIONVIEW_H

#include <QQuickWidget>
#include <QColor>
#include <QPointer>
#include <QTimer>

#include "stdafx.h"
#include "DispatchListeners.h"
#include "EventsBrowserView.h"
#include "EventsModel.h"
#include "ObjectBrowserView.h"
#include "ObjectListModel.h"
#include "PropertyModel.h"
#include "SelectedValueImpl.h"
#include "Qt3DSDMHandles.h"
#include "Qt3DSDMSignals.h"
#include "Qt3DSDMStudioSystem.h"
#include "Qt3DSDMMetaDataTypes.h"
#include "TabOrderHandler.h"
#include "MouseHelper.h"

class ActionModel;
class CClientDataModelBridge;
class CCore;
class CDoc;
class IObjectReferenceHelper;

QT_FORWARD_DECLARE_CLASS(QAbstractItemModel)

struct HandlerArgument {
    Q_PROPERTY(qt3dsdm::HandlerArgumentType::Value type MEMBER m_type FINAL)
    Q_PROPERTY(QString name MEMBER m_name FINAL)
    Q_PROPERTY(int handle MEMBER m_handle FINAL)
    Q_PROPERTY(QVariant value MEMBER m_value FINAL)
    Q_PROPERTY(qt3dsdm::CompleteMetaDataType::Enum completeType MEMBER m_completeType FINAL)

    qt3dsdm::Qt3DSDMHandlerArgHandle m_handle;
    qt3dsdm::HandlerArgumentType::Value m_type;
    qt3dsdm::CompleteMetaDataType::Enum m_completeType;
    QString m_name;
    QVariant m_value;

    Q_GADGET
};

Q_DECLARE_METATYPE(HandlerArgument)

class ActionView : public QQuickWidget,
                   public CPresentationChangeListener,
                   public TabNavigable
{
    Q_OBJECT

    Q_PROPERTY(QAbstractItemModel *actionsModel READ actionsModel NOTIFY itemChanged FINAL)
    Q_PROPERTY(QAbstractItemModel *propertyModel READ propertyModel NOTIFY propertyModelChanged FINAL)
    Q_PROPERTY(QString itemIcon READ itemIcon NOTIFY itemChanged FINAL)
    Q_PROPERTY(QString itemText READ itemText NOTIFY itemChanged FINAL)
    Q_PROPERTY(QColor itemColor READ itemColor NOTIFY itemChanged FINAL)
    Q_PROPERTY(bool hasItem MEMBER m_hasItem NOTIFY hasItemChanged FINAL)
    Q_PROPERTY(QString triggerObjectName READ triggerObjectName NOTIFY actionChanged FINAL)
    Q_PROPERTY(QString targetObjectName READ targetObjectName NOTIFY actionChanged FINAL)
    Q_PROPERTY(QString eventName READ eventName NOTIFY actionChanged FINAL)
    Q_PROPERTY(QString handlerName READ handlerName NOTIFY actionChanged FINAL)
    Q_PROPERTY(QVariantList handlerArguments READ handlerArguments NOTIFY actionChanged FINAL)
    Q_PROPERTY(PropertyInfo property READ property NOTIFY propertyChanged FINAL)
    Q_PROPERTY(QString firedEvent MEMBER m_firedEvent NOTIFY firedEventChanged FINAL)

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

    QSize sizeHint() const override;

    void setItem(const qt3dsdm::Qt3DSDMInstanceHandle &handle);
    QString itemIcon() const;
    QString itemText() const;
    QColor itemColor() const;
    QAbstractItemModel *actionsModel() const;
    QAbstractItemModel *propertyModel() const;
    QString targetObjectName() const;
    QString triggerObjectName() const;
    QString eventName() const;
    QString handlerName() const;
    QVariantList handlerArguments() const;
    PropertyInfo property() const;

    Q_INVOKABLE void setCurrentActionIndex(int index);
    Q_INVOKABLE void setCurrentPropertyIndex(int handle, int index);
    Q_INVOKABLE void addAction();
    Q_INVOKABLE void deleteAction(int index);
    Q_INVOKABLE QObject *showTriggerObjectBrowser(const QPoint &point);
    Q_INVOKABLE QObject *showTargetObjectBrowser(const QPoint &point);
    Q_INVOKABLE void showContextMenu(int x, int y);
    Q_INVOKABLE QObject *showEventBrowser(const QPoint &point);
    Q_INVOKABLE QObject *showHandlerBrowser(const QPoint &point);
    Q_INVOKABLE QObject *showEventBrowserForArgument(int handle, const QPoint &point);
    Q_INVOKABLE void setArgumentValue(int handle, const QVariant &value);
    Q_INVOKABLE QStringList slideNames();
    Q_INVOKABLE int slideNameToIndex(const QString &name);
    Q_INVOKABLE bool toolTipsEnabled();

    // CPresentationChangeListener
    void OnNewPresentation() override;

    // ISelectionChangeListener
    void OnSelectionSet(Q3DStudio::SSelectedValue inSelectable);

    // Action callback
    void OnActionAdded(qt3dsdm::Qt3DSDMActionHandle inAction, qt3dsdm::Qt3DSDMSlideHandle inSlide,
                       qt3dsdm::Qt3DSDMInstanceHandle inOwner);
    void OnActionDeleted(qt3dsdm::Qt3DSDMActionHandle inAction, qt3dsdm::Qt3DSDMSlideHandle inSlide,
                         qt3dsdm::Qt3DSDMInstanceHandle inOwner);
    void OnActionModified(qt3dsdm::Qt3DSDMActionHandle inAction);
    void OnHandlerArgumentModified(qt3dsdm::Qt3DSDMHandlerArgHandle inHandlerArgument);
    void OnInstancePropertyValueChanged(qt3dsdm::Qt3DSDMInstanceHandle inInstance,
                                        qt3dsdm::Qt3DSDMPropertyHandle inProperty);
    void OnInstanceDeleted(qt3dsdm::Qt3DSDMInstanceHandle inInstance);
    void OnTargetSelectionChanged();
    void OnTriggerSelectionChanged();

protected:
    void focusInEvent(QFocusEvent *event) override;
    void focusOutEvent(QFocusEvent *event) override;

Q_SIGNALS:
    void itemChanged();
    void actionChanged();
    void propertyModelChanged();
    void propertyChanged();
    void firedEventChanged();
    void hasItemChanged();
    void actionFocused(bool);

private Q_SLOTS:
    void copyAction();
    void cutAction();
    void pasteAction();

private:
    void setTriggerObject(const qt3dsdm::SObjectRefType &object);
    void setTargetObject(const qt3dsdm::SObjectRefType &object);
    void setEvent(const qt3dsdm::Qt3DSDMEventHandle &event);
    void setHandler(const qt3dsdm::Qt3DSDMHandlerHandle &handler);
    QVariant handlerArgumentValue(int handle) const;
    void updateHandlerArguments();
    void emitActionChanged();
    void updateFiredEvent();
    void resetFiredEvent();
    void updateFiredEventFromHandle(int handle);
    void showBrowser(QQuickWidget *browser, const QPoint &point);
    void updateActionStates();

    static CDoc *GetDoc();
    static CClientDataModelBridge *GetBridge();

    void initialize();
    QColor m_baseColor = QColor::fromRgb(75, 75, 75);
    QColor m_selectColor = Qt::transparent;
    qt3dsdm::Qt3DSDMInstanceHandle m_itemHandle;
    IObjectReferenceHelper *m_objRefHelper = nullptr;
    ActionModel *m_actionsModel = nullptr;
    PropertyModel *m_propertyModel = nullptr;
    std::vector<std::shared_ptr<qt3dsdm::ISignalConnection>>
        m_connections; /// connections to the DataModel
    QPointer<ObjectListModel> m_objectsModel;
    QPointer<ObjectBrowserView> m_triggerObjectBrowser;
    QPointer<ObjectBrowserView> m_targetObjectBrowser;
    QPointer<EventsModel> m_eventsModel;
    QPointer<EventsModel> m_handlersModel;
    QPointer<EventsModel> m_fireEventsModel;
    QPointer<EventsBrowserView> m_eventsBrowser;
    QPointer<EventsBrowserView> m_handlerBrowser;
    QPointer<EventsBrowserView> m_fireEventsBrowser;
    int m_currentActionIndex = -1;
    int m_currentPropertyIndex = -1;
    qt3dsdm::Qt3DSDMHandlerArgHandle m_currentPropertyNameHandle;
    qt3dsdm::Qt3DSDMHandlerArgHandle m_currentPropertyValueHandle;
    QVariantList m_handlerArguments;
    QTimer m_actionChangedCompressionTimer;
    QString m_firedEvent;
    MouseHelper m_mouseHelper;
    QSize m_preferredSize;
    bool m_hasItem = false;
    QAction *m_actionDel;
    QAction *m_actionCopy;
    QAction *m_actionCut;
    QAction *m_actionPaste;
};

#endif // ACTIONVIEW_H