summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.h
blob: 36bd2820cc5e9bbe301820dc83a8c0c1d1418eb7 (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
/****************************************************************************
**
** 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 "TimelineGraphicsScene.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;

enum class ExpandState {
    Hidden,
    Collapsed,
    Expanded
};

class RowTree : public InteractiveTimelineItem
{
    Q_OBJECT

public:
    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 setParent(RowTree *parent);
    void addChild(RowTree *child);
    void addChildAt(RowTree *child, int index);
    void moveChild(int from, int to);   // NOT USED
    void removeChild(RowTree *child);
    void setMoveSourceRecursive(bool value);
    void setMoveTarget(bool value);
    void setTreeWidth(double w);
    void setBinding(ITimelineItemBinding *binding);
    void setPropBinding(ITimelineItemProperty *binding); // for property rows
    void selectLabel();
    void togglePropertyExpanded();
    void setPropertyExpanded(bool expand);
    ITimelineItemProperty *propBinding();
    TreeControlType getClickedControl(const QPointF &scenePos);
    bool shy() const;
    bool visible() const;
    bool locked() const;
    bool expanded() const;
    bool isDecendentOf(RowTree *row) const;
    bool isContainer() const;
    bool isProperty() const;
    bool isPropertyOrMaterial() 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;
    int index() const;
    int indexInLayout() const;
    int treeWidth() const;
    EStudioObjectType rowType() const;
    QString propertyType() 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();

    ITimelineItemBinding *getBinding() const;

protected:
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;

private:
    void initialize();
    void initializeAnimations();
    void animateExpand(ExpandState state);
    void updateExpandStatus(bool expand, bool childrenOnly = false);
    void updateDepthRecursive();
    void updateLockRecursive(bool state);
    void updateLabelPosition();
    void updateIndices(bool isInsertion, int startIndex, int startIndexInLayout, bool isProperty);
    bool hasActionButtons() const;
    bool hasComponentAncestor();
    int removeChildFromLayout(RowTree *child) const;
    int getCountDecendentsRecursive() const;
    int addChildToLayout(RowTree *child, int indexInLayout);

    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_expanded = true;
    bool m_moveSource = false;
    bool m_moveTarget = false;
    bool m_isProperty = false;
    bool m_isPropertyExpanded = false;
    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;
    ITimelineItemBinding *m_binding = nullptr;
    ITimelineItemProperty *m_PropBinding; // 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;
};

#endif // ROWTREE_H