-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
source-dock.hpp
219 lines (176 loc) · 5.53 KB
/
source-dock.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
#pragma once
#include <qboxlayout.h>
#include <QCheckBox>
#include <QDockWidget>
#include <QSlider>
#include <QPlainTextEdit>
#include <QScrollArea>
#include <memory>
#include "obs.h"
#include <obs-frontend-api.h>
#include <QSplitter>
#include "media-control.hpp"
#include "obs.hpp"
#include "qt-display.hpp"
#include "volume-meter.hpp"
#define SHOW_PREVIEW 1
#define SHOW_AUDIO 2
#define SHOW_VOLUME 4
#define SHOW_MUTE 8
#define SHOW_MEDIA 16
#define SHOW_ALL 31
typedef std::function<bool(QObject *, QEvent *)> EventFilterFunc;
class OBSEventFilter : public QObject {
Q_OBJECT
public:
OBSEventFilter(EventFilterFunc filter_) : filter(filter_) {}
protected:
bool eventFilter(QObject *obj, QEvent *event) { return filter(obj, event); }
public:
EventFilterFunc filter;
};
class LockedCheckBox : public QCheckBox {
Q_OBJECT
public:
LockedCheckBox();
explicit LockedCheckBox(QWidget *parent);
};
class VisibilityCheckBox : public QCheckBox {
Q_OBJECT
public:
VisibilityCheckBox();
explicit VisibilityCheckBox(QWidget *parent);
};
class MuteCheckBox : public QCheckBox {
Q_OBJECT
public:
MuteCheckBox();
explicit MuteCheckBox(QWidget *parent);
};
class SliderIgnoreScroll : public QSlider {
Q_OBJECT
public:
SliderIgnoreScroll(QWidget *parent = nullptr);
SliderIgnoreScroll(Qt::Orientation orientation, QWidget *parent = nullptr);
protected:
virtual void wheelEvent(QWheelEvent *event) override;
};
class SourceDock : public QSplitter {
Q_OBJECT
private:
OBSSource source = nullptr;
std::unique_ptr<OBSEventFilter> eventFilter;
QAction *action = nullptr;
float zoom = 1.0f;
float scrollX = 0.5f;
float scrollY = 0.5f;
int scrollingFromX = 0;
int scrollingFromY = 0;
bool selected;
OBSQTDisplay *preview = nullptr;
VolumeMeter *volMeter = nullptr;
QWidget *volMeterWidget = nullptr;
obs_volmeter_t *obs_volmeter = nullptr;
LockedCheckBox *locked = nullptr;
SliderIgnoreScroll *slider = nullptr;
MuteCheckBox *mute = nullptr;
MediaControl *mediaControl = nullptr;
bool showTimeDecimals = true;
bool showTimeRemaining = true;
QWidget *volControl = nullptr;
bool switch_scene_enabled = false;
QFrame *activeFrame = nullptr;
QLabel *activeLabel = nullptr;
QWidget *sceneItems = nullptr;
QScrollArea *sceneItemsScrollArea = nullptr;
QPushButton *propertiesButton = nullptr;
QPushButton *filtersButton = nullptr;
QPlainTextEdit *textInput = nullptr;
QTimer *textInputTimer = nullptr;
obs_data_t *textInputCustomStyle = nullptr;
OBSSignal visibleSignal;
OBSSignal addSignal;
OBSSignal removeSignal;
OBSSignal reorderSignal;
OBSSignal refreshSignal;
static void DrawPreview(void *data, uint32_t cx, uint32_t cy);
static void OBSVolumeLevel(void *data, const float magnitude[MAX_AUDIO_CHANNELS], const float peak[MAX_AUDIO_CHANNELS],
const float inputPeak[MAX_AUDIO_CHANNELS]);
static void OBSVolume(void *data, calldata_t *calldata);
static void OBSMute(void *data, calldata_t *calldata);
static void OBSActiveChanged(void *, calldata_t *);
static bool AddSceneItem(obs_scene_t *scene, obs_sceneitem_t *item, void *data);
int GetSceneItemCount(obs_scene_t *scene);
bool GetSourceRelativeXY(int mouseX, int mouseY, int &x, int &y);
bool HandleMouseClickEvent(QMouseEvent *event);
bool HandleMouseMoveEvent(QMouseEvent *event);
bool HandleMouseWheelEvent(QWheelEvent *event);
bool HandleFocusEvent(QFocusEvent *event);
bool HandleKeyEvent(QKeyEvent *event);
OBSEventFilter *BuildEventFilter();
private slots:
void LockVolumeControl(bool lock);
void MuteVolumeControl(bool mute);
void SliderChanged(int vol);
void SetOutputVolume(double volume);
void SetMute(bool muted);
void ActiveChanged();
void VisibilityChanged(int id);
void RefreshItems();
void SetActive(int active);
public:
SourceDock(QString name, bool selected, QWidget *parent = nullptr);
~SourceDock();
void SetSource(const OBSSource source_);
OBSSource GetSource();
bool GetSelected() { return selected; }
void setAction(QAction *action);
void EnablePreview();
void DisablePreview();
bool PreviewEnabled();
void EnableVolMeter();
void DisableVolMeter();
bool VolMeterEnabled();
void EnableVolControls();
void UpdateVolControls();
void DisableVolControls();
bool VolControlsEnabled();
void EnableMediaControls();
void DisableMediaControls();
bool MediaControlsEnabled();
bool GetShowMs() { return mediaControl ? mediaControl->GetShowMs() : showTimeDecimals; }
void SetShowMs(bool b) { showTimeDecimals = b; }
bool GetShowTimeRemaining() { return mediaControl ? mediaControl->GetShowTimeRemaining() : showTimeRemaining; }
void SetShowTimeRemaining(bool b) { showTimeRemaining = b; }
void EnableSwitchScene();
void DisableSwitchScene();
bool SwitchSceneEnabled();
void EnableShowActive();
void DisableShowActive();
bool ShowActiveEnabled();
void EnableSceneItems();
void DisableSceneItems();
bool SceneItemsEnabled();
void EnableProperties();
void DisableProperties();
bool PropertiesEnabled();
void EnableFilters();
void DisableFilters();
bool FiltersEnabled();
void EnableTextInput();
void DisableTextInput();
bool TextInputEnabled();
obs_data_t *GetCustomTextInputStyle();
void SetCustomTextInputStyle(obs_data_t *);
void ApplyCustomTextInputStyle();
float GetZoom() const { return zoom; }
void SetZoom(float zoom);
float GetScrollX() { return scrollX; }
void SetScrollX(float scroll);
float GetScrollY() { return scrollY; }
void SetScrollY(float scroll);
QByteArray saveSplitState();
bool restoreSplitState(const QByteArray &splitState);
};
inline std::list<SourceDock *> source_docks;
inline std::list<QMainWindow *> source_windows;