-
Notifications
You must be signed in to change notification settings - Fork 21
/
source-tree.hpp
223 lines (168 loc) · 5.49 KB
/
source-tree.hpp
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
#pragma once
#include <QList>
#include <QVector>
#include <QPointer>
#include <QListView>
#include <QCheckBox>
#include <QStaticText>
#include <QAbstractListModel>
#include <QStyledItemDelegate>
#include <obs.hpp>
#include <obs-frontend-api.h>
#include "vertical-canvas.hpp"
class QLabel;
class QCheckBox;
class QLineEdit;
class SourceTree;
class QSpacerItem;
class QHBoxLayout;
class LockedCheckBox;
class VisibilityCheckBox;
class VisibilityItemWidget;
class SourceTreeSubItemCheckBox : public QCheckBox {
Q_OBJECT
};
class SourceTreeItem : public QFrame {
Q_OBJECT
friend class SourceTree;
friend class SourceTreeModel;
void mouseDoubleClickEvent(QMouseEvent *event) override;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEnterEvent *event) override;
#else
void enterEvent(QEvent *event) override;
#endif
void leaveEvent(QEvent *event) override;
virtual bool eventFilter(QObject *object, QEvent *event) override;
void Update(bool force);
enum class Type {
Unknown,
Item,
Group,
SubItem,
};
void DisconnectSignals();
void ReconnectSignals();
Type type = Type::Unknown;
public:
explicit SourceTreeItem(SourceTree *tree, OBSSceneItem sceneitem);
~SourceTreeItem();
bool IsEditing();
private:
QSpacerItem *spacer = nullptr;
QCheckBox *expand = nullptr;
QLabel *iconLabel = nullptr;
VisibilityCheckBox *vis = nullptr;
LockedCheckBox *lock = nullptr;
QHBoxLayout *boxLayout = nullptr;
QLabel *label = nullptr;
QLineEdit *editor = nullptr;
std::string newName;
SourceTree *tree;
OBSSceneItem sceneitem;
static void removeItem(void *data, calldata_t *cd);
static void itemVisible(void *data, calldata_t *cd);
static void itemLocked(void *data, calldata_t *cd);
static void itemSelect(void *data, calldata_t *cd);
static void itemDeselect(void *data, calldata_t *cd);
static void reorderGroup(void *data, calldata_t *);
static void renamed(void *data, calldata_t *cd);
static void removeSource(void *data, calldata_t *);
virtual void paintEvent(QPaintEvent *event) override;
void ExitEditModeInternal(bool save);
private slots:
void Clear();
void EnterEditMode();
void ExitEditMode(bool save);
void VisibilityChanged(bool visible);
void LockedChanged(bool locked);
void Renamed(const QString &name);
void ExpandClicked(bool checked);
void Select();
void Deselect();
};
class SourceTreeModel : public QAbstractListModel {
Q_OBJECT
friend class SourceTree;
friend class SourceTreeItem;
friend class CanvasDock;
SourceTree *st;
QVector<OBSSceneItem> items;
bool hasGroups = false;
static void OBSFrontendEvent(enum obs_frontend_event event, void *ptr);
void Clear();
void SceneChanged();
void ReorderItems();
void Add(obs_sceneitem_t *item);
void Remove(obs_sceneitem_t *item);
OBSSceneItem Get(int idx);
QString GetNewGroupName();
void AddGroup();
void GroupSelectedItems(QModelIndexList &indices);
void UngroupSelectedGroups(QModelIndexList &indices);
void ExpandGroup(obs_sceneitem_t *item);
void CollapseGroup(obs_sceneitem_t *item);
void UpdateGroupState(bool update);
public:
explicit SourceTreeModel(SourceTree *st);
~SourceTreeModel();
virtual int rowCount(const QModelIndex &parent) const override;
virtual QVariant data(const QModelIndex &index, int role) const override;
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
virtual Qt::DropActions supportedDropActions() const override;
};
class SourceTree : public QListView {
Q_OBJECT
bool ignoreReorder = false;
CanvasDock *canvasDock;
friend class SourceTreeModel;
friend class SourceTreeItem;
friend class CanvasDock;
bool textPrepared = false;
QStaticText textNoSources;
//QSvgRenderer iconNoSources;
bool iconsVisible = true;
void UpdateNoSourcesMessage();
void ResetWidgets();
void UpdateWidget(const QModelIndex &idx, obs_sceneitem_t *item);
void UpdateWidgets(bool force = false);
inline SourceTreeModel *GetStm() const { return reinterpret_cast<SourceTreeModel *>(model()); }
public:
inline SourceTreeItem *GetItemWidget(int idx)
{
QWidget *widget = indexWidget(GetStm()->createIndex(idx, 0));
return reinterpret_cast<SourceTreeItem *>(widget);
}
explicit SourceTree(CanvasDock *canvas_dock, QWidget *parent = nullptr);
inline bool IgnoreReorder() const { return ignoreReorder; }
inline void Clear() { GetStm()->Clear(); }
inline void Add(obs_sceneitem_t *item) { GetStm()->Add(item); }
inline OBSSceneItem Get(int idx) { return GetStm()->Get(idx); }
inline QString GetNewGroupName() { return GetStm()->GetNewGroupName(); }
void SelectItem(obs_sceneitem_t *sceneitem, bool select);
bool MultipleBaseSelected() const;
bool GroupsSelected() const;
bool GroupedItemsSelected() const;
void UpdateIcons();
void SetIconsVisible(bool visible);
public slots:
inline void ReorderItems() { GetStm()->ReorderItems(); }
inline void RefreshItems() { GetStm()->SceneChanged(); }
void Remove(OBSSceneItem item, OBSScene scene);
void GroupSelectedItems();
void UngroupSelectedGroups();
void AddGroup();
bool Edit(int idx);
void NewGroupEdit(int idx);
protected:
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
virtual void dropEvent(QDropEvent *event) override;
virtual void paintEvent(QPaintEvent *event) override;
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
};
class SourceTreeDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
SourceTreeDelegate(QObject *parent);
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};