summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineWidget.h
blob: ac01367ade43576821e4fd3bd7d4d505e4051555 (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
/****************************************************************************
**
** Copyright (C) 2018 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 TIMELINEWIDGET_H
#define TIMELINEWIDGET_H

#include <QtWidgets/qwidget.h>
#include <QtCore/qtimer.h>
#include "DispatchListeners.h"
#include "ObjectListModel.h"
#include "Qt3DSDMHandles.h"
#include "Qt3DSDMSignals.h"
#include "SelectedValueImpl.h"
#include "TreeHeaderView.h"
#include "Bindings/Qt3DSDMTimeline.h"
#include "NavigationBar.h"
#include "Control.h"

class RowTree;
class TimelineToolbar;
class TimelineSplitter;
class TimelineGraphicsScene;
class CTimelineTranslationManager;
class Qt3DSDMTimelineItemBinding;
class CClientDataModelBridge;
class IBreadCrumbProvider;

QT_FORWARD_DECLARE_CLASS(QMouseEvent)
QT_FORWARD_DECLARE_CLASS(QGraphicsView)

class TimelineWidget : public QWidget,
                       public CPresentationChangeListener,
                       public CClientPlayChangeListener,
                       public CControl
{
    Q_OBJECT

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

    QSize sizeHint() const override;

    TimelineToolbar *toolbar() const;
    QGraphicsView *viewTimelineContent() const;
    QGraphicsView *viewTreeContent() const;
    QVector<RowTree *> selectedRows() const;
    void openBarColorDialog();
    void onTimeBarColorChanged(const QColor &color);
    void setSelectedTimeBarsColor(const QColor &color, bool preview);
    void refreshVariants();
    void enableDnD(bool b = true);
    bool dndActive() const;
    bool blockMousePress() const;

    // Presentation Change Listener
    void OnNewPresentation() override;
    void OnClosingPresentation() override;
    void onSelectionChange(Q3DStudio::SSelectedValue inNewSelectable);

    //CClientPlayChangeListener
    void OnTimeChanged(long inTime) override;
    bool hasSelectedKeyframes() const;

    // CControl
    CDropTarget *FindDropCandidate(CPt &inMousePoint, Qt::KeyboardModifiers inFlags,
                                   EStudioObjectType objectType,
                                   Q3DStudio::DocumentEditorFileType::Enum fileType) override;
    void OnMouseMove(CPt inPoint, Qt::KeyboardModifiers inFlags) override;
    CPt GetPreferredSize() override;
    void SetSize(long inX, long inY) override;
    bool isFullReconstructPending() const { return m_fullReconstruct; }
    NavigationBar *navigationBar() const { return m_navigationBar; }

protected:
    // DataModel callbacks
    virtual void onActiveSlide(const qt3dsdm::Qt3DSDMSlideHandle &inMaster, int inIndex,
                               const qt3dsdm::Qt3DSDMSlideHandle &inSlide);
    void onAssetCreated(qt3dsdm::Qt3DSDMInstanceHandle inInstance);
    void onAssetDeleted(qt3dsdm::Qt3DSDMInstanceHandle inInstance);
    void onAnimationCreated(qt3dsdm::Qt3DSDMInstanceHandle parentInstance,
                            qt3dsdm::Qt3DSDMPropertyHandle property);
    void onKeyframeInserted(qt3dsdm::Qt3DSDMAnimationHandle inAnimation,
                            qt3dsdm::Qt3DSDMKeyframeHandle inKeyframe);
    void onKeyframeDeleted(qt3dsdm::Qt3DSDMAnimationHandle inAnimation,
                           qt3dsdm::Qt3DSDMKeyframeHandle inKeyframe);
    void onKeyframeUpdated(qt3dsdm::Qt3DSDMKeyframeHandle inKeyframe);
    void onFirstKeyframeDynamicSet(qt3dsdm::Qt3DSDMAnimationHandle inAnimation);
    void onAnimationDeleted(qt3dsdm::Qt3DSDMInstanceHandle parentInstance,
                            qt3dsdm::Qt3DSDMPropertyHandle property);
    void onActionEvent(qt3dsdm::Qt3DSDMActionHandle inAction, qt3dsdm::Qt3DSDMSlideHandle inSlide,
                       qt3dsdm::Qt3DSDMInstanceHandle inOwner);
    void onPropertyLinked(qt3dsdm::Qt3DSDMInstanceHandle inInstance,
                          qt3dsdm::Qt3DSDMPropertyHandle inProperty);
    void onPropertyUnlinked(qt3dsdm::Qt3DSDMInstanceHandle inInstance,
                            qt3dsdm::Qt3DSDMPropertyHandle inProperty);
    void onChildAdded(int inParent, int inChild, long inIndex);
    void onChildRemoved(int inParent, int inChild, long inIndex);
    void onChildMoved(int inParent, int inChild, long inOldIndex, long inNewIndex);
    void onPropertyChanged(qt3dsdm::Qt3DSDMInstanceHandle inInstance,
                           qt3dsdm::Qt3DSDMPropertyHandle inProperty);
    void onAsyncUpdate();

    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private:
    typedef QHash<qt3dsdm::Qt3DSDMInstanceHandle, RowTree *> THandleMap;

    Qt3DSDMTimelineItemBinding *getBindingForHandle(int handle,
                                                    Qt3DSDMTimelineItemBinding *binding) const;
    void insertToHandlesMapRecursive(Qt3DSDMTimelineItemBinding *binding);
    void insertToHandlesMap(Qt3DSDMTimelineItemBinding *binding);
    Q3DStudio::CString getPlaybackMode();
    void refreshKeyframe(qt3dsdm::Qt3DSDMAnimationHandle inAnimation,
                         qt3dsdm::Qt3DSDMKeyframeHandle inKeyframe,
                         ETimelineKeyframeTransaction inTransaction);
    void updateActionStates(const QSet<RowTree *> &rows);
    void setTreeWidth(int width);

    TreeHeaderView *m_viewTreeHeader = nullptr;
    QGraphicsView *m_viewTreeContent = nullptr;
    QGraphicsView *m_viewTimelineHeader = nullptr;
    QGraphicsView *m_viewTimelineContent = nullptr;
    NavigationBar *m_navigationBar = nullptr;
    TimelineToolbar *m_toolbar = nullptr;
    TimelineGraphicsScene *m_graphicsScene;
    TimelineSplitter *m_splitter = nullptr;
    CTimelineTranslationManager *m_translationManager = nullptr;
    FlatObjectListModel *m_model = nullptr;
    Qt3DSDMTimelineItemBinding *m_binding = nullptr;
    bool m_splitterPressed = false;
    QSize m_preferredSize;
    QMultiHash<qt3dsdm::Qt3DSDMInstanceHandle, qt3dsdm::Qt3DSDMPropertyHandle> m_dirtyProperties;
    QHash<int, int> m_moveMap; // key: child handle, value: parent handle
    QHash<int, QStringList> m_variantsMap; // key: obj handle, value: variant groups
    QSet<int> m_actionChanges; // key: object handle
    QSet<int> m_subpresentationChanges; // key: object handle
    QMultiHash<int, int> m_keyframeChangesMap; // key: object handle, value: property handle
    QTimer m_asyncUpdateTimer;
    bool m_fullReconstruct = false;
    bool m_blockMousePress = false;
    CClientDataModelBridge *m_bridge = nullptr;
    IBreadCrumbProvider *m_BreadCrumbProvider = nullptr;

    // data model connection
    std::vector<std::shared_ptr<qt3dsdm::ISignalConnection>> m_connections;
    qt3dsdm::Qt3DSDMSlideHandle m_activeSlide;
    THandleMap m_handlesMap;
};

#endif // TIMELINEWIDGET_H