FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
obs-studio-ftl/UI/properties-view.cpp at develop · mixer/obs-studio-ftl · GitHub
This repository was archived by the owner on Jul 21, 2020. It is now read-only.
mixer
obs-studio-ftl
Repository navigation
Code
Issues
6
(6)
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
obs-studio-ftl
/
UI
/
properties-view.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
2028 lines (1624 loc) · 52.7 KB
Breadcrumbs
obs-studio-ftl
/
UI
/
properties-view.cpp
Copy path
File metadata and controls
2028 lines (1624 loc) · 52.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
include
<
QFormLayout
>
#
include
<
QScrollBar
>
#
include
<
QLabel
>
#
include
<
QCheckBox
>
#
include
<
QFont
>
#
include
<
QFontDialog
>
#
include
<
QLineEdit
>
#
include
<
QSpinBox
>
#
include
<
QSlider
>
#
include
<
QDoubleSpinBox
>
#
include
<
QComboBox
>
#
include
<
QListWidget
>
#
include
<
QPushButton
>
#
include
<
QStandardItem
>
#
include
<
QFileDialog
>
#
include
<
QColorDialog
>
#
include
<
QPlainTextEdit
>
#
include
<
QDialogButtonBox
>
#
include
<
QMenu
>
#
include
<
QStackedWidget
>
#
include
"
double-slider.hpp
"
#
include
"
qt-wrappers.hpp
"
#
include
"
properties-view.hpp
"
#
include
"
properties-view.moc.hpp
"
#
include
"
obs-app.hpp
"
#
include
<
cstdlib
>
#
include
<
initializer_list
>
#
include
<
string
>
using
namespace
std
;
static
inline
QColor
color_from_int
(
long
long
val)
{
return
QColor
( val &
0xff
,
(val >>
8
) &
0xff
,
(val >>
16
) &
0xff
,
(val >>
24
) &
0xff
);
}
static
inline
long
long
color_to_int
(QColor color)
{
auto
shift = [&](
unsigned
val,
int
shift)
{
return
((val &
0xff
) << shift);
};
return
shift
(color.
red
(),
0
) |
shift
(color.
green
(),
8
) |
shift
(color.
blue
(),
16
) |
shift
(color.
alpha
(),
24
);
}
namespace
{
struct
frame_rate_tag
{
enum
tag_type {
SIMPLE
,
RATIONAL
,
USER
,
} type =
SIMPLE
;
const
char
*val =
nullptr
;
frame_rate_tag
() =
default
;
explicit
frame_rate_tag
(tag_type type)
: type(type)
{}
explicit
frame_rate_tag
(
const
char
*val)
: type(
USER
),
val(val)
{}
static
frame_rate_tag
simple
() {
return
frame_rate_tag{
SIMPLE
}; }
static
frame_rate_tag
rational
() {
return
frame_rate_tag{
RATIONAL
}; }
};
struct
common_frame_rate
{
const
char
*fps_name;
media_frames_per_second fps;
};
}
Q_DECLARE_METATYPE
(frame_rate_tag);
Q_DECLARE_METATYPE
(media_frames_per_second);
void
OBSPropertiesView::ReloadProperties
()
{
if
(obj) {
properties.
reset
(
reloadCallback
(obj));
}
else
{
properties.
reset
(
reloadCallback
((
void
*)type.
c_str
()));
obs_properties_apply_settings
(properties.
get
(), settings);
}
uint32_t
flags =
obs_properties_get_flags
(properties.
get
());
deferUpdate = (flags &
OBS_PROPERTIES_DEFER_UPDATE
) !=
0
;
RefreshProperties
();
}
#
define
NO_PROPERTIES_STRING
QTStr
(
"
Basic.PropertiesWindow.NoProperties
"
)
void OBSPropertiesView::RefreshProperties()
{
int
h, v;
GetScrollPos
(h, v);
children.
clear
();
if
(widget)
widget->
deleteLater
();
widget =
new
QWidget
();
QFormLayout *layout =
new
QFormLayout;
layout->
setFieldGrowthPolicy
(QFormLayout::AllNonFixedFieldsGrow);
widget->
setLayout
(layout);
QSizePolicy
mainPolicy
(QSizePolicy::Expanding, QSizePolicy::Expanding);
QSizePolicy
policy
(QSizePolicy::Preferred, QSizePolicy::Preferred);
//
widget->setSizePolicy(policy);
layout->
setLabelAlignment
(Qt::AlignRight);
obs_property_t
*property =
obs_properties_first
(properties.
get
());
bool
hasNoProperties = !property;
while
(property) {
AddProperty
(property, layout);
obs_property_next
(&property);
}
setWidgetResizable
(
true
);
setWidget
(widget);
SetScrollPos
(h, v);
setSizePolicy
(mainPolicy);
lastFocused.
clear
();
if
(lastWidget) {
lastWidget->
setFocus
(Qt::OtherFocusReason);
lastWidget =
nullptr
;
}
if
(hasNoProperties) {
QLabel *noPropertiesLabel =
new
QLabel
(
NO_PROPERTIES_STRING
);
layout->
addWidget
(noPropertiesLabel);
}
}
void
OBSPropertiesView::SetScrollPos
(
int
h,
int
v)
{
QScrollBar *scroll =
horizontalScrollBar
();
if
(scroll)
scroll->
setValue
(h);
scroll =
verticalScrollBar
();
if
(scroll)
scroll->
setValue
(v);
}
void
OBSPropertiesView::GetScrollPos
(
int
&h,
int
&v)
{
h = v =
0
;
QScrollBar *scroll =
horizontalScrollBar
();
if
(scroll)
h = scroll->
value
();
scroll =
verticalScrollBar
();
if
(scroll)
v = scroll->
value
();
}
OBSPropertiesView::OBSPropertiesView
(OBSData settings_,
void
*obj_,
PropertiesReloadCallback reloadCallback,
PropertiesUpdateCallback callback_,
int
minSize_)
: VScrollArea (
nullptr
),
properties (
nullptr
, obs_properties_destroy),
settings (settings_),
obj (obj_),
reloadCallback (reloadCallback),
callback (callback_),
minSize (minSize_)
{
setFrameShape
(QFrame::NoFrame);
ReloadProperties
();
}
OBSPropertiesView::OBSPropertiesView
(OBSData settings_,
const
char
*type_,
PropertiesReloadCallback reloadCallback_,
int
minSize_)
: VScrollArea (
nullptr
),
properties (
nullptr
, obs_properties_destroy),
settings (settings_),
type (type_),
reloadCallback (reloadCallback_),
minSize (minSize_)
{
setFrameShape
(QFrame::NoFrame);
ReloadProperties
();
}
void
OBSPropertiesView::resizeEvent
(QResizeEvent *event)
{
emit
PropertiesResized
();
VScrollArea::resizeEvent
(event);
}
QWidget *
OBSPropertiesView::NewWidget
(
obs_property_t
*prop, QWidget *widget,
const
char
*signal)
{
const
char
*long_desc =
obs_property_long_description
(prop);
WidgetInfo *info =
new
WidgetInfo
(
this
, prop, widget);
connect
(widget, signal, info,
SLOT
(
ControlChanged
()));
children.
emplace_back
(info);
widget->
setToolTip
(
QT_UTF8
(long_desc));
return
widget;
}
QWidget *
OBSPropertiesView::AddCheckbox
(
obs_property_t
*prop)
{
const
char
*name =
obs_property_name
(prop);
const
char
*desc =
obs_property_description
(prop);
bool
val =
obs_data_get_bool
(settings, name);
QCheckBox *checkbox =
new
QCheckBox
(
QT_UTF8
(desc));
checkbox->
setCheckState
(val ? Qt::Checked : Qt::Unchecked);
return
NewWidget
(prop, checkbox,
SIGNAL
(
stateChanged
(
int
)));
}
QWidget *
OBSPropertiesView::AddText
(
obs_property_t
*prop, QFormLayout *layout,
QLabel *&label)
{
const
char
*name =
obs_property_name
(prop);
const
char
*val =
obs_data_get_string
(settings, name);
obs_text_type type =
obs_proprety_text_type
(prop);
if
(type ==
OBS_TEXT_MULTILINE
) {
QPlainTextEdit *edit =
new
QPlainTextEdit
(
QT_UTF8
(val));
return
NewWidget
(prop, edit,
SIGNAL
(
textChanged
()));
}
else
if
(type ==
OBS_TEXT_PASSWORD
) {
QLayout *subLayout =
new
QHBoxLayout
();
QLineEdit *edit =
new
QLineEdit
();
QPushButton *show =
new
QPushButton
();
show->
setText
(
QTStr
(
"
Show
"
));
show->
setCheckable
(
true
);
edit->
setText
(
QT_UTF8
(val));
edit->
setEchoMode
(QLineEdit::Password);
subLayout->
addWidget
(edit);
subLayout->
addWidget
(show);
WidgetInfo *info =
new
WidgetInfo
(
this
, prop, edit);
connect
(show, &QAbstractButton::toggled,
info, &WidgetInfo::TogglePasswordText);
connect
(show, &QAbstractButton::toggled, [=](
bool
hide)
{
show->
setText
(hide ?
QTStr
(
"
Hide
"
) :
QTStr
(
"
Show
"
));
});
children.
emplace_back
(info);
label =
new
QLabel
(
QT_UTF8
(
obs_property_description
(prop)));
layout->
addRow
(label, subLayout);
edit->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
connect
(edit,
SIGNAL
(
textEdited
(
const
QString &)),
info,
SLOT
(
ControlChanged
()));
return
nullptr
;
}
QLineEdit *edit =
new
QLineEdit
();
edit->
setText
(
QT_UTF8
(val));
edit->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
return
NewWidget
(prop, edit,
SIGNAL
(
textEdited
(
const
QString &)));
}
void
OBSPropertiesView::AddPath
(
obs_property_t
*prop, QFormLayout *layout,
QLabel **label)
{
const
char
*name =
obs_property_name
(prop);
const
char
*val =
obs_data_get_string
(settings, name);
QLayout *subLayout =
new
QHBoxLayout
();
QLineEdit *edit =
new
QLineEdit
();
QPushButton *button =
new
QPushButton
(
QTStr
(
"
Browse
"
));
if
(!
obs_property_enabled
(prop)) {
edit->
setEnabled
(
false
);
button->
setEnabled
(
false
);
}
button->
setProperty
(
"
themeID
"
,
"
settingsButtons
"
);
edit->
setText
(
QT_UTF8
(val));
edit->
setReadOnly
(
true
);
edit->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
subLayout->
addWidget
(edit);
subLayout->
addWidget
(button);
WidgetInfo *info =
new
WidgetInfo
(
this
, prop, edit);
connect
(button,
SIGNAL
(
clicked
()), info,
SLOT
(
ControlChanged
()));
children.
emplace_back
(info);
*label =
new
QLabel
(
QT_UTF8
(
obs_property_description
(prop)));
layout->
addRow
(*label, subLayout);
}
void
OBSPropertiesView::AddInt
(
obs_property_t
*prop, QFormLayout *layout,
QLabel **label)
{
obs_number_type type =
obs_property_int_type
(prop);
QLayout *subLayout =
new
QHBoxLayout
();
const
char
*name =
obs_property_name
(prop);
int
val = (
int
)
obs_data_get_int
(settings, name);
QSpinBox *spin =
new
QSpinBox
();
if
(!
obs_property_enabled
(prop))
spin->
setEnabled
(
false
);
int
minVal =
obs_property_int_min
(prop);
int
maxVal =
obs_property_int_max
(prop);
int
stepVal =
obs_property_int_step
(prop);
spin->
setMinimum
(minVal);
spin->
setMaximum
(maxVal);
spin->
setSingleStep
(stepVal);
spin->
setValue
(val);
spin->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
WidgetInfo *info =
new
WidgetInfo
(
this
, prop, spin);
children.
emplace_back
(info);
if
(type ==
OBS_NUMBER_SLIDER
) {
QSlider *slider =
new
QSlider
();
slider->
setMinimum
(minVal);
slider->
setMaximum
(maxVal);
slider->
setPageStep
(stepVal);
slider->
setValue
(val);
slider->
setOrientation
(Qt::Horizontal);
subLayout->
addWidget
(slider);
connect
(slider,
SIGNAL
(
valueChanged
(
int
)),
spin,
SLOT
(
setValue
(
int
)));
connect
(spin,
SIGNAL
(
valueChanged
(
int
)),
slider,
SLOT
(
setValue
(
int
)));
}
connect
(spin,
SIGNAL
(
valueChanged
(
int
)), info,
SLOT
(
ControlChanged
()));
subLayout->
addWidget
(spin);
*label =
new
QLabel
(
QT_UTF8
(
obs_property_description
(prop)));
layout->
addRow
(*label, subLayout);
}
void
OBSPropertiesView::AddFloat
(
obs_property_t
*prop, QFormLayout *layout,
QLabel **label)
{
obs_number_type type =
obs_property_float_type
(prop);
QLayout *subLayout =
new
QHBoxLayout
();
const
char
*name =
obs_property_name
(prop);
double
val =
obs_data_get_double
(settings, name);
QDoubleSpinBox *spin =
new
QDoubleSpinBox
();
if
(!
obs_property_enabled
(prop))
spin->
setEnabled
(
false
);
double
minVal =
obs_property_float_min
(prop);
double
maxVal =
obs_property_float_max
(prop);
double
stepVal =
obs_property_float_step
(prop);
spin->
setMinimum
(minVal);
spin->
setMaximum
(maxVal);
spin->
setSingleStep
(stepVal);
spin->
setValue
(val);
spin->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
WidgetInfo *info =
new
WidgetInfo
(
this
, prop, spin);
children.
emplace_back
(info);
if
(type ==
OBS_NUMBER_SLIDER
) {
DoubleSlider *slider =
new
DoubleSlider
();
slider->
setDoubleConstraints
(minVal, maxVal, stepVal, val);
slider->
setOrientation
(Qt::Horizontal);
subLayout->
addWidget
(slider);
connect
(slider,
SIGNAL
(
doubleValChanged
(
double
)),
spin,
SLOT
(
setValue
(
double
)));
connect
(spin,
SIGNAL
(
valueChanged
(
double
)),
slider,
SLOT
(
setDoubleVal
(
double
)));
}
connect
(spin,
SIGNAL
(
valueChanged
(
double
)), info,
SLOT
(
ControlChanged
()));
subLayout->
addWidget
(spin);
*label =
new
QLabel
(
QT_UTF8
(
obs_property_description
(prop)));
layout->
addRow
(*label, subLayout);
}
static
void
AddComboItem
(QComboBox *combo,
obs_property_t
*prop,
obs_combo_format format,
size_t
idx)
{
const
char
*name =
obs_property_list_item_name
(prop, idx);
QVariant var;
if
(format ==
OBS_COMBO_FORMAT_INT
) {
long
long
val =
obs_property_list_item_int
(prop, idx);
var = QVariant::fromValue<
long
long
>(val);
}
else
if
(format ==
OBS_COMBO_FORMAT_FLOAT
) {
double
val =
obs_property_list_item_float
(prop, idx);
var = QVariant::fromValue<
double
>(val);
}
else
if
(format ==
OBS_COMBO_FORMAT_STRING
) {
var =
QByteArray
(
obs_property_list_item_string
(prop, idx));
}
combo->
addItem
(
QT_UTF8
(name), var);
if
(!
obs_property_list_item_disabled
(prop, idx))
return
;
int
index = combo->
findText
(
QT_UTF8
(name));
if
(index <
0
)
return
;
QStandardItemModel *model =
dynamic_cast
<QStandardItemModel*>(combo->
model
());
if
(!model)
return
;
QStandardItem *item = model->
item
(index);
item->
setFlags
(Qt::NoItemFlags);
}
template
<
long
long
get_int
(
obs_data_t
*,
const
char
*),
double get_double(
obs_data_t
*,
const
char
*),
const
char *get_string(
obs_data_t
*,
const
char
*)>
static string from_obs_data(
obs_data_t
*data,
const
char
*name,
obs_combo_format format)
{
switch
(format) {
case
OBS_COMBO_FORMAT_INT
:
return
to_string
(
get_int
(data, name));
case
OBS_COMBO_FORMAT_FLOAT
:
return
to_string
(
get_double
(data, name));
case
OBS_COMBO_FORMAT_STRING
:
return
get_string
(data, name);
default
:
return
"
"
;
}
}
static
string
from_obs_data
(
obs_data_t
*data,
const
char
*name,
obs_combo_format format)
{
return
from_obs_data<obs_data_get_int, obs_data_get_double,
obs_data_get_string>(data, name, format);
}
static
string
from_obs_data_autoselect
(
obs_data_t
*data,
const
char
*name,
obs_combo_format format)
{
return
from_obs_data<obs_data_get_autoselect_int,
obs_data_get_autoselect_double,
obs_data_get_autoselect_string>(data, name, format);
}
QWidget *
OBSPropertiesView::AddList
(
obs_property_t
*prop,
bool
&warning)
{
const
char
*name =
obs_property_name
(prop);
QComboBox *combo =
new
QComboBox
();
obs_combo_type type =
obs_property_list_type
(prop);
obs_combo_format format =
obs_property_list_format
(prop);
size_t
count =
obs_property_list_item_count
(prop);
int
idx = -
1
;
for
(
size_t
i =
0
; i < count; i++)
AddComboItem
(combo, prop, format, i);
if
(type ==
OBS_COMBO_TYPE_EDITABLE
)
combo->
setEditable
(
true
);
combo->
setMaxVisibleItems
(
40
);
combo->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
string value =
from_obs_data
(settings, name, format);
if
(format ==
OBS_COMBO_FORMAT_STRING
&&
type ==
OBS_COMBO_TYPE_EDITABLE
) {
combo->
lineEdit
()->
setText
(
QT_UTF8
(value.
c_str
()));
}
else
{
idx = combo->
findData
(
QByteArray
(value.
c_str
()));
}
if
(type ==
OBS_COMBO_TYPE_EDITABLE
)
return
NewWidget
(prop, combo,
SIGNAL
(
editTextChanged
(
const
QString &)));
if
(idx != -
1
)
combo->
setCurrentIndex
(idx);
if
(
obs_data_has_autoselect_value
(settings, name)) {
string autoselect =
from_obs_data_autoselect
(settings, name, format);
int
id = combo->
findData
(
QT_UTF8
(autoselect.
c_str
()));
if
(id != -
1
&& id != idx) {
QString actual = combo->
itemText
(id);
QString selected = combo->
itemText
(idx);
QString combined =
QTStr
(
"
Basic.PropertiesWindow.AutoSelectFormat
"
);
combo->
setItemText
(idx,
combined.
arg
(selected).
arg
(actual));
}
}
QAbstractItemModel *model = combo->
model
();
warning = idx != -
1
&&
model->
flags
(model->
index
(idx,
0
)) == Qt::NoItemFlags;
WidgetInfo *info =
new
WidgetInfo
(
this
, prop, combo);
connect
(combo,
SIGNAL
(
currentIndexChanged
(
int
)), info,
SLOT
(
ControlChanged
()));
children.
emplace_back
(info);
/*
trigger a settings update if the index was not found
*/
if
(idx == -
1
)
info->
ControlChanged
();
return
combo;
}
static
void
NewButton
(QLayout *layout, WidgetInfo *info,
const
char
*themeIcon,
void
(WidgetInfo::*method)())
{
QPushButton *button =
new
QPushButton
();
button->
setProperty
(
"
themeID
"
, themeIcon);
button->
setFlat
(
true
);
button->
setMaximumSize
(
22
,
22
);
button->
setSizePolicy
(QSizePolicy::Maximum, QSizePolicy::Maximum);
QObject::connect
(button, &QPushButton::clicked, info, method);
layout->
addWidget
(button);
}
void
OBSPropertiesView::AddEditableList
(
obs_property_t
*prop,
QFormLayout *layout, QLabel *&label)
{
const
char
*name =
obs_property_name
(prop);
obs_data_array_t
*array =
obs_data_get_array
(settings, name);
QListWidget *list =
new
QListWidget
();
size_t
count =
obs_data_array_count
(array);
if
(!
obs_property_enabled
(prop))
list->
setEnabled
(
false
);
list->
setSortingEnabled
(
false
);
list->
setSelectionMode
(QAbstractItemView::ExtendedSelection);
list->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
for
(
size_t
i =
0
; i < count; i++) {
obs_data_t
*item =
obs_data_array_item
(array, i);
list->
addItem
(
QT_UTF8
(
obs_data_get_string
(item,
"
value
"
)));
obs_data_release
(item);
}
WidgetInfo *info =
new
WidgetInfo
(
this
, prop, list);
QVBoxLayout *sideLayout =
new
QVBoxLayout
();
NewButton
(sideLayout, info,
"
addIconSmall
"
,
&WidgetInfo::EditListAdd);
NewButton
(sideLayout, info,
"
removeIconSmall
"
,
&WidgetInfo::EditListRemove);
NewButton
(sideLayout, info,
"
configIconSmall
"
,
&WidgetInfo::EditListEdit);
NewButton
(sideLayout, info,
"
upArrowIconSmall
"
,
&WidgetInfo::EditListUp);
NewButton
(sideLayout, info,
"
downArrowIconSmall
"
,
&WidgetInfo::EditListDown);
sideLayout->
addStretch
(
0
);
QHBoxLayout *subLayout =
new
QHBoxLayout
();
subLayout->
addWidget
(list);
subLayout->
addLayout
(sideLayout);
children.
emplace_back
(info);
label =
new
QLabel
(
QT_UTF8
(
obs_property_description
(prop)));
layout->
addRow
(label, subLayout);
obs_data_array_release
(array);
}
QWidget *
OBSPropertiesView::AddButton
(
obs_property_t
*prop)
{
const
char
*desc =
obs_property_description
(prop);
QPushButton *button =
new
QPushButton
(
QT_UTF8
(desc));
button->
setProperty
(
"
themeID
"
,
"
settingsButtons
"
);
button->
setSizePolicy
(QSizePolicy::Maximum, QSizePolicy::Maximum);
return
NewWidget
(prop, button,
SIGNAL
(
clicked
()));
}
void
OBSPropertiesView::AddColor
(
obs_property_t
*prop, QFormLayout *layout,
QLabel *&label)
{
QPushButton *button =
new
QPushButton;
QLabel *colorLabel =
new
QLabel;
const
char
*name =
obs_property_name
(prop);
long
long
val =
obs_data_get_int
(settings, name);
QColor color =
color_from_int
(val);
if
(!
obs_property_enabled
(prop)) {
button->
setEnabled
(
false
);
colorLabel->
setEnabled
(
false
);
}
button->
setProperty
(
"
themeID
"
,
"
settingsButtons
"
);
button->
setText
(
QTStr
(
"
Basic.PropertiesWindow.SelectColor
"
));
button->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
colorLabel->
setFrameStyle
(QFrame::Sunken | QFrame::Panel);
colorLabel->
setText
(color.
name
(QColor::HexArgb));
colorLabel->
setPalette
(
QPalette
(color));
colorLabel->
setAutoFillBackground
(
true
);
colorLabel->
setAlignment
(Qt::AlignCenter);
colorLabel->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
QHBoxLayout *subLayout =
new
QHBoxLayout;
subLayout->
setContentsMargins
(
0
,
0
,
0
,
0
);
subLayout->
addWidget
(colorLabel);
subLayout->
addWidget
(button);
WidgetInfo *info =
new
WidgetInfo
(
this
, prop, colorLabel);
connect
(button,
SIGNAL
(
clicked
()), info,
SLOT
(
ControlChanged
()));
children.
emplace_back
(info);
label =
new
QLabel
(
QT_UTF8
(
obs_property_description
(prop)));
layout->
addRow
(label, subLayout);
}
static
void
MakeQFont
(
obs_data_t
*font_obj, QFont &font,
bool
limit =
false
)
{
const
char
*face =
obs_data_get_string
(font_obj,
"
face
"
);
const
char
*style =
obs_data_get_string
(font_obj,
"
style
"
);
int
size = (
int
)
obs_data_get_int
(font_obj,
"
size
"
);
uint32_t
flags = (
uint32_t
)
obs_data_get_int
(font_obj,
"
flags
"
);
if
(face) {
font.
setFamily
(face);
font.
setStyleName
(style);
}
if
(size) {
if
(limit) {
int
max_size = font.
pointSize
();
if
(max_size <
28
) max_size =
28
;
if
(size > max_size) size = max_size;
}
font.
setPointSize
(size);
}
if
(flags &
OBS_FONT_BOLD
) font.
setBold
(
true
);
if
(flags &
OBS_FONT_ITALIC
) font.
setItalic
(
true
);
if
(flags &
OBS_FONT_UNDERLINE
) font.
setUnderline
(
true
);
if
(flags &
OBS_FONT_STRIKEOUT
) font.
setStrikeOut
(
true
);
}
void
OBSPropertiesView::AddFont
(
obs_property_t
*prop, QFormLayout *layout,
QLabel *&label)
{
const
char
*name =
obs_property_name
(prop);
obs_data_t
*font_obj =
obs_data_get_obj
(settings, name);
const
char
*face =
obs_data_get_string
(font_obj,
"
face
"
);
const
char
*style =
obs_data_get_string
(font_obj,
"
style
"
);
QPushButton *button =
new
QPushButton;
QLabel *fontLabel =
new
QLabel;
QFont font;
if
(!
obs_property_enabled
(prop)) {
button->
setEnabled
(
false
);
fontLabel->
setEnabled
(
false
);
}
font = fontLabel->
font
();
MakeQFont
(font_obj, font,
true
);
button->
setProperty
(
"
themeID
"
,
"
settingsButtons
"
);
button->
setText
(
QTStr
(
"
Basic.PropertiesWindow.SelectFont
"
));
button->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
fontLabel->
setFrameStyle
(QFrame::Sunken | QFrame::Panel);
fontLabel->
setFont
(font);
fontLabel->
setText
(
QString
(
"
%1 %2
"
).
arg
(face, style));
fontLabel->
setAlignment
(Qt::AlignCenter);
fontLabel->
setToolTip
(
QT_UTF8
(
obs_property_long_description
(prop)));
QHBoxLayout *subLayout =
new
QHBoxLayout;
subLayout->
setContentsMargins
(
0
,
0
,
0
,
0
);
subLayout->
addWidget
(fontLabel);
subLayout->
addWidget
(button);
WidgetInfo *info =
new
WidgetInfo
(
this
, prop, fontLabel);
connect
(button,
SIGNAL
(
clicked
()), info,
SLOT
(
ControlChanged
()));
children.
emplace_back
(info);
label =
new
QLabel
(
QT_UTF8
(
obs_property_description
(prop)));
layout->
addRow
(label, subLayout);
obs_data_release
(font_obj);
}
namespace
std
{
template
<>
struct
default_delete
<
obs_data_t
> {
void
operator
()(
obs_data_t
*data)
{
obs_data_release
(data);
}
};
template
<>
struct
default_delete
<
obs_data_item_t
> {
void
operator
()(
obs_data_item_t
*item)
{
obs_data_item_release
(&item);
}
};
}
template
<
typename
T>
static
double
make_epsilon
(T val)
{
return
val *
0.00001
;
}
static
bool
matches_range
(media_frames_per_second &match,
media_frames_per_second fps,
const
frame_rate_range_t
&pair)
{
auto
val =
media_frames_per_second_to_frame_interval
(fps);
auto
max_ =
media_frames_per_second_to_frame_interval
(pair.
first
);
auto
min_ =
media_frames_per_second_to_frame_interval
(pair.
second
);
if
(min_ <= val && val <= max_) {
match = fps;
return
true
;
}
return
false
;
}
static
bool
matches_ranges
(media_frames_per_second &best_match,
media_frames_per_second fps,
const
frame_rate_ranges_t
&fps_ranges,
bool
exact=
false
)
{
auto
convert_fn = media_frames_per_second_to_frame_interval;
auto
val =
convert_fn
(fps);
auto
epsilon =
make_epsilon
(val);
bool
match =
false
;
auto
best_dist = numeric_limits<
double
>::
max
();
for
(
auto
&pair : fps_ranges) {
auto
max_ =
convert_fn
(pair.
first
);
auto
min_ =
convert_fn
(pair.
second
);
/*
blog(LOG_INFO, "%lg ≤ %lg ≤ %lg? %s %s %s",
min_, val, max_,
fabsl(min_ - val) < epsilon ? "true" : "false",
min_ <= val && val <= max_ ? "true" : "false",
fabsl(min_ - val) < epsilon ? "true" :
"false");
*/
if
(
matches_range
(best_match, fps, pair))
return
true
;
if
(exact)
continue
;
auto
min_dist =
fabsl
(min_ - val);
auto
max_dist =
fabsl
(max_ - val);
if
(min_dist < epsilon && min_dist < best_dist) {
best_match = pair.
first
;
match =
true
;
continue
;
}
if
(max_dist < epsilon && max_dist < best_dist) {
best_match = pair.
second
;
match =
true
;
continue
;
}
}
return
match;
}
static
media_frames_per_second
make_fps
(
uint32_t
num,
uint32_t
den)
{
media_frames_per_second fps{};
fps.
numerator
= num;
fps.
denominator
= den;
return
fps;
}
static
const
common_frame_rate common_fps[] = {
{
"
60
"
, {
60
,
1
}},
{
"
59.94
"
, {
60000
,
1001
}},
{
"
50
"
, {
50
,
1
}},
{
"
48
"
, {
48
,
1
}},
{
"
30
"
, {
30
,
1
}},
{
"
29.97
"
, {
30000
,
1001
}},
{
"
25
"
, {
25
,
1
}},
{
"
24
"
, {
24
,
1
}},
{
"
23.976
"
, {
24000
,
1001
}},
};
static
void
UpdateSimpleFPSSelection
(OBSFrameRatePropertyWidget *fpsProps,
const
media_frames_per_second *current_fps)
{
if
(!current_fps || !
media_frames_per_second_is_valid
(*current_fps)) {
fpsProps->
simpleFPS
->
setCurrentIndex
(
0
);
return
;
}
auto
combo = fpsProps->
simpleFPS
;
auto
num = combo->
count
();
for
(
int
i =
0
; i < num; i++) {
auto
variant = combo->
itemData
(i);
if
(!variant.
canConvert
<media_frames_per_second>())
continue
;
auto
fps = variant.
value
<media_frames_per_second>();
if
(fps != *current_fps)
continue
;
combo->
setCurrentIndex
(i);
return
;
}
combo->
setCurrentIndex
(
0
);
}
static
void
AddFPSRanges
(vector<common_frame_rate> &items,
const
frame_rate_ranges_t
&ranges)
{
auto
InsertFPS = [&](media_frames_per_second fps)
{
auto
fps_val =
media_frames_per_second_to_fps
(fps);
auto
end_ =
end
(items);
auto
i =
begin
(items);
for
(; i != end_; i++) {
auto
i_fps_val =
media_frames_per_second_to_fps
(i->
fps
);
if
(
fabsl
(i_fps_val - fps_val) <
0.01
)
return
;
if
(i_fps_val > fps_val)
continue
;
break
;
}
items.
insert
(i, {
nullptr
, fps});
};
for
(
auto
&range : ranges) {
InsertFPS
(range.
first
);
InsertFPS
(range.
second
);
}
}
static
QWidget *
CreateSimpleFPSValues
(OBSFrameRatePropertyWidget *fpsProps,
bool
&selected,
const
media_frames_per_second *current_fps)
{
auto
widget =
new
QWidget{};
widget->
setSizePolicy
(QSizePolicy::Expanding, QSizePolicy::Expanding);
auto
layout =
new
QVBoxLayout{};
layout->
setContentsMargins
(
0
,
0
,
0
,
0
);
auto
items = vector<common_frame_rate>{};
items.
reserve
(
sizeof
(common_fps)/
sizeof
(common_frame_rate));
auto
combo = fpsProps->
simpleFPS
=
new
QComboBox{};
combo->
addItem
(
"
"
,
QVariant::fromValue
(
make_fps
(
0
,
0
)));
for
(
const
auto
&fps : common_fps) {
media_frames_per_second best_match{};
if
(!
matches_ranges
(best_match, fps.
fps
, fpsProps->
fps_ranges
))
continue
;
items.
push_back
({fps.
fps_name
, best_match});
}
AddFPSRanges
(items, fpsProps->
fps_ranges
);
for
(
const
auto
&item : items) {
auto
var =
QVariant::fromValue
(item.
fps
);
auto
name = item.
fps_name
?
QString
(item.
fps_name
) :
QString
(
"
%1
"
)
.
arg
(
media_frames_per_second_to_fps
(item.
fps
));
combo->
addItem
(name, var);
bool
select = current_fps && *current_fps == item.
fps
;
if
(select) {
combo->
setCurrentIndex
(combo->
count
() -
1
);
selected =
true
;
}
}
layout->
addWidget
(combo,
0
, Qt::AlignTop);
widget->
setLayout
(layout);
return
widget;
}
static
void
UpdateRationalFPSWidgets
(OBSFrameRatePropertyWidget *fpsProps,
const
media_frames_per_second *current_fps)
{
if
(!current_fps || !
media_frames_per_second_is_valid
(*current_fps)) {
fpsProps->
numEdit
->
setValue
(
0
);
fpsProps->
denEdit
->
setValue
(
0
);
return
;
}
auto
combo = fpsProps->
fpsRange
;
auto
num = combo->
count
();
for
(
int
i =
0
; i < num; i++) {
auto
variant = combo->
itemData
(i);
if
(!variant.
canConvert
<
size_t
>())
continue
;
auto
idx = variant.
value
<
size_t
>();
if
(fpsProps->
fps_ranges
.
size
() < idx)
continue
;
media_frames_per_second match{};
if
(!
matches_range
(match, *current_fps,
fpsProps->
fps_ranges
[idx]))
continue
;
combo->
setCurrentIndex
(i);
break
;
}
fpsProps->
numEdit
->
setValue
(current_fps->
numerator
);
fpsProps->
denEdit
->
setValue
(current_fps->
denominator
);
}
static
QWidget *
CreateRationalFPS
(OBSFrameRatePropertyWidget *fpsProps,
bool
&selected,
const
media_frames_per_second *current_fps)
{
auto
widget =
new
QWidget{};
widget->
setSizePolicy
(QSizePolicy::Expanding, QSizePolicy::Expanding);
auto
layout =
new
QFormLayout{};
layout->
setContentsMargins
(
0
,
0
,
0
,
0
);
layout->
setSpacing
(
4
);
auto
str =
QTStr
(
"
Basic.PropertiesView.FPS.ValidFPSRanges
"
);
auto
rlabel =
new
QLabel{str};
auto
combo = fpsProps->
fpsRange
=
new
QComboBox{};
auto
convert_fps = media_frames_per_second_to_fps;
//
auto convert_fi = media_frames_per_second_to_frame_interval;
for
(
size_t
i =
0
; i < fpsProps->
fps_ranges
.
size
(); i++) {
auto
&pair = fpsProps->
fps_ranges
[i];
combo->
addItem
(QString{
"
%1 - %2
"
}
.
arg
(
convert_fps
(pair.
first
))
.
arg
(
convert_fps
(pair.
second
)),
QVariant::fromValue
(i));
media_frames_per_second match;
if
(!current_fps || !
matches_range
(match, *current_fps, pair))
continue
;
combo->
setCurrentIndex
(combo->
count
() -
1
);
selected =
true
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL