summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h
blob: f6c54b56734e6b17bec299ccf70f1c9d0d58e83a (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
/****************************************************************************
**
** 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 ROWTREE_H
#define ROWTREE_H

#include "InteractiveTimelineItem.h"
#include "TimelineConstants.h"
#include "RowTypes.h"
#include "StudioObjectTypes.h"
#include "RowTreeLabelItem.h"

#include <QtCore/qpropertyanimation.h>
#include <QtCore/qparallelanimationgroup.h>

class RowTimeline;
class Ruler;
class ITimelineItemBinding;
class TimelineGraphicsScene;
class ITimelineItemProperty;

class RowTree : public InteractiveTimelineItem
{
    Q_OBJECT

public:
    enum class ExpandState {
        Unknown,
        Collapsed,
        Expanded,
        HiddenCollapsed,
        HiddenExpanded
    };

    enum class DnDState {
        None,
        Source, // the row being dragged while DnD-ing
        Parent, // parent of the insertion point
        SP_TARGET, // drop target for a subpresentation (layer, material or image rows)
        Any     // accept any state (default value in setDnDState() method)
    };

    enum class ActionState {
        None = 0,
        Action = 1,
        ChildAction = 2,
        ComponentAction = 4,
        MasterAction = 8,
        MasterChildAction = 16,
        MasterComponentAction = 32
    };
    Q_DECLARE_FLAGS(ActionStates, ActionState)

    explicit RowTree(TimelineGraphicsScene *timelineScene,
                     EStudioObjectType rowType = OBJTYPE_UNKNOWN, const QString &label = {});
    // property row constructor
    explicit RowTree(TimelineGraphicsScene *timelineScene, const QString &propType);
    ~RowTree();

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
               QWidget *widget = nullptr) override;
    void setState(State state) override;
    void setTimelineRow(RowTimeline *rowTimeline);
    void setParentRow(RowTree *parent);
    void addChild(RowTree *child);
    void addChildAt(RowTree *child, int index);
    void removeChild(RowTree *child);
    void setDnDState(DnDState state, DnDState onlyIfState = DnDState::Any, bool recursive = false);
    void setActionStates(ActionStates states);
    void setTreeWidth(double w);
    void setBinding(ITimelineItemBinding *binding);
    void setPropBinding(ITimelineItemProperty *binding); // for property rows
    void selectLabel();
    void togglePropertyExpanded();
    void setPropertyExpanded(bool expand);
    void showDataInputSelector(const QString &propertyname, const QPoint &pos);
    ITimelineItemProperty *propBinding();
    TreeControlType getClickedControl(const QPointF &scenePos);
    bool shy() const;
    bool visible() const;
    bool locked() const;
    bool expanded() const;
    bool expandHidden() const;
    ExpandState expandState() const { return m_expandState; }
    bool isDecendentOf(RowTree *row) const;
    bool isContainer() const;
    bool isProperty() const;
    bool isPropertyOrMaterial() const;
    bool isComponent() const;
    bool isComponentRoot() const;
    bool isMaster() const;
    bool hasPropertyChildren() const;
    bool empty() const; // has zero child rows (and zero properties)
    bool selected() const;
    bool draggable() const;
    bool hasDurationBar() const;
    bool propertyExpanded() const;
    int depth() const;
    int type() const override;
    int index() const;
    int indexInLayout() const;
    int treeWidth() const;
    EStudioObjectType rowType() const;
    QString propertyType() const;
    RowTree *getChildAt(int index) const;
    RowTree *parentRow() const;
    RowTree *getPropertyRow(const QString &type) const;
    QList<RowTree *> childRows() const;
    QList<RowTree *> childProps() const;
    RowTimeline *rowTimeline() const;
    QString label() const;
    void toggleShy();
    void toggleVisible();
    void toggleLocked();
    void updateFromBinding();
    void updateLabel();
    void setRowVisible(bool visible);
    void setDnDHover(bool val);
    void updateVariants(const QStringList &groups);
    DnDState getDnDState() const;

    ITimelineItemBinding *getBinding() const;
    void updateExpandStatus(ExpandState state, bool animate = true, bool forceChildUpdate = false);
    void updateArrowVisibility();
    void updateFilter();
    void updateLock(bool state);
    void updateSubpresentations(int updateParentsOnlyVal = 0);
    int clipX() const;
    int instance() const;

protected:
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;

private:
    void initialize();
    void initializeAnimations();
    void animateExpand(ExpandState state);
    void updateDepthRecursive();
    void updateLockRecursive(bool state);
    void updateLabelPosition();
    void updateIndices(bool isInsertion, int startIndex, int startIndexInLayout, bool isProperty);
    bool hasActionButtons() const;
    bool hasComponentAncestor() const;
    int removeChildFromLayout(RowTree *child) const;
    int getCountDecendentsRecursive() const;
    int addToLayout(int indexInLayout);
    int getLastChildIndex(bool isProperty) const;

    RowTree *m_parentRow = nullptr;
    RowTimeline *m_rowTimeline = nullptr;
    int m_depth = 1;
    int m_index = 0;
    int m_indexInLayout = 1;
    bool m_shy = false;
    bool m_visible = true;
    bool m_locked = false;
    bool m_isProperty = false;
    bool m_isPropertyExpanded = false;
    bool m_master = false;
    bool m_filtered = false;
    bool m_arrowVisible = false;
    bool m_dndHover = false;
    bool m_visibilityCtrld = false;
    bool m_onMasterSlide = false;
    DnDState m_dndState = DnDState::None;
    ActionStates m_actionStates = ActionState::None;
    bool m_hasSubpresentation = false;
    int m_numDescendantSubpresentations = 0;
    ExpandState m_expandState = ExpandState::HiddenCollapsed;
    TimelineGraphicsScene *m_scene;
    RowTreeLabelItem m_labelItem;
    EStudioObjectType m_rowType = OBJTYPE_UNKNOWN;
    QString m_propertyType; // for property rows
    QString m_label;
    QList<RowTree *> m_childRows;
    QList<RowTree *> m_childProps;
    QStringList m_variantsGroups;
    ITimelineItemBinding *m_binding = nullptr;
    ITimelineItemProperty *m_PropBinding = nullptr; // for property rows

    QRect m_rectArrow;
    QRect m_rectShy;
    QRect m_rectVisible;
    QRect m_rectLocked;
    QRect m_rectType;

    QParallelAnimationGroup m_expandAnimation;
    QPropertyAnimation *m_expandHeightAnimation;
    QPropertyAnimation *m_expandTimelineHeightAnimation;
    QPropertyAnimation *m_expandOpacityAnimation;
    QPropertyAnimation *m_expandTimelineOpacityAnimation;

    friend class RowTimeline;
    friend class RowTimelinePropertyGraph;
    friend class RowTimelineContextMenu;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(RowTree::ActionStates)

#endif // ROWTREE_H