2014-03-23 08:07:54 +00:00
|
|
|
|
#include <QFormLayout>
|
2015-02-04 09:59:12 +00:00
|
|
|
|
#include <QScrollBar>
|
2014-03-23 08:07:54 +00:00
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QCheckBox>
|
2014-08-17 12:50:30 +00:00
|
|
|
|
#include <QFont>
|
|
|
|
|
#include <QFontDialog>
|
2014-03-23 08:07:54 +00:00
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QSpinBox>
|
2015-03-18 01:34:21 +00:00
|
|
|
|
#include <QSlider>
|
2014-03-23 08:07:54 +00:00
|
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
|
#include <QComboBox>
|
2015-04-13 18:23:54 +00:00
|
|
|
|
#include <QListWidget>
|
2014-05-30 09:44:14 +00:00
|
|
|
|
#include <QPushButton>
|
2022-11-20 01:32:05 +00:00
|
|
|
|
#include <QRadioButton>
|
|
|
|
|
#include <QButtonGroup>
|
2014-06-12 00:01:47 +00:00
|
|
|
|
#include <QStandardItem>
|
2014-06-28 02:55:47 +00:00
|
|
|
|
#include <QFileDialog>
|
2014-07-19 19:00:14 +00:00
|
|
|
|
#include <QColorDialog>
|
2015-04-13 18:23:54 +00:00
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QMenu>
|
2020-10-14 01:58:41 +00:00
|
|
|
|
#include <QMessageBox>
|
2015-08-18 12:57:36 +00:00
|
|
|
|
#include <QStackedWidget>
|
2019-03-31 11:35:48 +00:00
|
|
|
|
#include <QDir>
|
2019-02-14 16:48:10 +00:00
|
|
|
|
#include <QGroupBox>
|
2021-03-22 05:47:19 +00:00
|
|
|
|
#include <QObject>
|
2020-10-14 01:58:41 +00:00
|
|
|
|
#include <QDesktopServices>
|
2015-03-18 01:34:21 +00:00
|
|
|
|
#include "double-slider.hpp"
|
2019-04-07 00:56:52 +00:00
|
|
|
|
#include "slider-ignorewheel.hpp"
|
2019-04-21 11:10:46 +00:00
|
|
|
|
#include "spinbox-ignorewheel.hpp"
|
2014-03-23 08:07:54 +00:00
|
|
|
|
#include "qt-wrappers.hpp"
|
|
|
|
|
#include "properties-view.hpp"
|
2015-08-18 12:57:36 +00:00
|
|
|
|
#include "properties-view.moc.hpp"
|
2022-08-06 05:03:28 +00:00
|
|
|
|
#include "plain-text-edit.hpp"
|
2014-06-15 05:05:50 +00:00
|
|
|
|
#include "obs-app.hpp"
|
2015-08-18 12:57:36 +00:00
|
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <initializer_list>
|
2021-03-22 05:47:19 +00:00
|
|
|
|
#include <obs-data.h>
|
|
|
|
|
#include <obs.h>
|
|
|
|
|
#include <qtimer.h>
|
2014-03-23 08:07:54 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2014-07-19 19:00:14 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 12:57:36 +00:00
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(frame_rate_tag);
|
|
|
|
|
Q_DECLARE_METATYPE(media_frames_per_second);
|
|
|
|
|
|
2014-09-30 13:36:50 +00:00
|
|
|
|
void OBSPropertiesView::ReloadProperties()
|
|
|
|
|
{
|
2022-02-08 19:07:23 +00:00
|
|
|
|
if (weakObj || rawObj) {
|
|
|
|
|
OBSObject strongObj = GetObject();
|
|
|
|
|
void *obj = strongObj ? strongObj.Get() : rawObj;
|
2023-08-03 23:09:25 +00:00
|
|
|
|
if (obj)
|
2022-02-08 19:07:23 +00:00
|
|
|
|
properties.reset(reloadCallback(obj));
|
2015-02-04 04:50:37 +00:00
|
|
|
|
} else {
|
|
|
|
|
properties.reset(reloadCallback((void *)type.c_str()));
|
|
|
|
|
obs_properties_apply_settings(properties.get(), settings);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 23:09:25 +00:00
|
|
|
|
uint32_t flags = obs_properties_get_flags(properties.get());
|
2023-08-03 23:27:02 +00:00
|
|
|
|
deferUpdate = enableDefer && (flags & OBS_PROPERTIES_DEFER_UPDATE) != 0;
|
2023-08-03 23:09:25 +00:00
|
|
|
|
|
2014-09-30 13:36:50 +00:00
|
|
|
|
RefreshProperties();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-16 17:31:00 +00:00
|
|
|
|
#define NO_PROPERTIES_STRING QTStr("Basic.PropertiesWindow.NoProperties")
|
|
|
|
|
|
2014-04-04 07:30:37 +00:00
|
|
|
|
void OBSPropertiesView::RefreshProperties()
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2023-04-05 09:23:45 +00:00
|
|
|
|
int h, v, hend, vend;
|
|
|
|
|
GetScrollPos(h, v, hend, vend);
|
2015-02-04 09:59:12 +00:00
|
|
|
|
|
2014-04-04 07:30:37 +00:00
|
|
|
|
children.clear();
|
|
|
|
|
if (widget)
|
|
|
|
|
widget->deleteLater();
|
|
|
|
|
|
2014-03-23 08:07:54 +00:00
|
|
|
|
widget = new QWidget();
|
2022-08-07 03:28:16 +00:00
|
|
|
|
widget->setObjectName("PropertiesContainer");
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
|
|
|
|
QFormLayout *layout = new QFormLayout;
|
2014-04-25 04:28:56 +00:00
|
|
|
|
layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
2023-05-24 20:13:53 +00:00
|
|
|
|
QSizePolicy mainPolicy(QSizePolicy::MinimumExpanding,
|
|
|
|
|
QSizePolicy::MinimumExpanding);
|
2015-01-05 13:41:25 +00:00
|
|
|
|
|
2014-03-23 08:07:54 +00:00
|
|
|
|
layout->setLabelAlignment(Qt::AlignRight);
|
|
|
|
|
|
2014-09-30 13:32:50 +00:00
|
|
|
|
obs_property_t *property = obs_properties_first(properties.get());
|
2015-02-16 17:31:00 +00:00
|
|
|
|
bool hasNoProperties = !property;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
|
|
|
|
while (property) {
|
|
|
|
|
AddProperty(property, layout);
|
|
|
|
|
obs_property_next(&property);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 04:12:23 +00:00
|
|
|
|
setWidgetResizable(true);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
setWidget(widget);
|
2014-04-24 08:43:54 +00:00
|
|
|
|
setSizePolicy(mainPolicy);
|
2023-04-05 09:19:23 +00:00
|
|
|
|
adjustSize();
|
2023-04-05 09:23:45 +00:00
|
|
|
|
SetScrollPos(h, v, hend, vend);
|
2014-04-24 08:43:54 +00:00
|
|
|
|
|
2024-03-22 12:30:51 +00:00
|
|
|
|
if (disableScrolling)
|
|
|
|
|
setMinimumHeight(widget->minimumSizeHint().height());
|
|
|
|
|
|
2014-04-24 08:43:54 +00:00
|
|
|
|
lastFocused.clear();
|
|
|
|
|
if (lastWidget) {
|
|
|
|
|
lastWidget->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
lastWidget = nullptr;
|
|
|
|
|
}
|
2015-02-16 17:31:00 +00:00
|
|
|
|
|
|
|
|
|
if (hasNoProperties) {
|
|
|
|
|
QLabel *noPropertiesLabel = new QLabel(NO_PROPERTIES_STRING);
|
|
|
|
|
layout->addWidget(noPropertiesLabel);
|
|
|
|
|
}
|
2019-05-12 05:13:38 +00:00
|
|
|
|
|
|
|
|
|
emit PropertiesRefreshed();
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 09:23:45 +00:00
|
|
|
|
void OBSPropertiesView::SetScrollPos(int h, int v, int old_hend, int old_vend)
|
2015-02-04 09:59:12 +00:00
|
|
|
|
{
|
|
|
|
|
QScrollBar *scroll = horizontalScrollBar();
|
2023-04-05 09:23:45 +00:00
|
|
|
|
if (scroll) {
|
|
|
|
|
int hend = scroll->maximum() + scroll->pageStep();
|
|
|
|
|
scroll->setValue(h * hend / old_hend);
|
|
|
|
|
}
|
2015-02-04 09:59:12 +00:00
|
|
|
|
|
|
|
|
|
scroll = verticalScrollBar();
|
2023-04-05 09:23:45 +00:00
|
|
|
|
if (scroll) {
|
|
|
|
|
int vend = scroll->maximum() + scroll->pageStep();
|
|
|
|
|
scroll->setValue(v * vend / old_vend);
|
|
|
|
|
}
|
2015-02-04 09:59:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 09:23:45 +00:00
|
|
|
|
void OBSPropertiesView::GetScrollPos(int &h, int &v, int &hend, int &vend)
|
2015-02-04 09:59:12 +00:00
|
|
|
|
{
|
|
|
|
|
h = v = 0;
|
|
|
|
|
|
|
|
|
|
QScrollBar *scroll = horizontalScrollBar();
|
2023-04-05 09:23:45 +00:00
|
|
|
|
if (scroll) {
|
2015-02-04 09:59:12 +00:00
|
|
|
|
h = scroll->value();
|
2023-04-05 09:23:45 +00:00
|
|
|
|
hend = scroll->maximum() + scroll->pageStep();
|
|
|
|
|
}
|
2015-02-04 09:59:12 +00:00
|
|
|
|
|
|
|
|
|
scroll = verticalScrollBar();
|
2023-04-05 09:23:45 +00:00
|
|
|
|
if (scroll) {
|
2015-02-04 09:59:12 +00:00
|
|
|
|
v = scroll->value();
|
2023-04-05 09:23:45 +00:00
|
|
|
|
vend = scroll->maximum() + scroll->pageStep();
|
|
|
|
|
}
|
2015-02-04 09:59:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-08 19:07:23 +00:00
|
|
|
|
OBSPropertiesView::OBSPropertiesView(OBSData settings_, obs_object_t *obj,
|
|
|
|
|
PropertiesReloadCallback reloadCallback,
|
|
|
|
|
PropertiesUpdateCallback callback_,
|
2022-03-09 17:14:32 +00:00
|
|
|
|
PropertiesVisualUpdateCb visUpdateCb_,
|
|
|
|
|
int minSize_)
|
2022-02-08 19:07:23 +00:00
|
|
|
|
: VScrollArea(nullptr),
|
|
|
|
|
properties(nullptr, obs_properties_destroy),
|
|
|
|
|
settings(settings_),
|
|
|
|
|
weakObj(obs_object_get_weak_object(obj)),
|
|
|
|
|
reloadCallback(reloadCallback),
|
|
|
|
|
callback(callback_),
|
2022-03-09 17:14:32 +00:00
|
|
|
|
visUpdateCb(visUpdateCb_),
|
2022-02-08 19:07:23 +00:00
|
|
|
|
minSize(minSize_)
|
|
|
|
|
{
|
|
|
|
|
setFrameShape(QFrame::NoFrame);
|
|
|
|
|
QMetaObject::invokeMethod(this, "ReloadProperties",
|
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-03 06:01:08 +00:00
|
|
|
|
OBSPropertiesView::OBSPropertiesView(OBSData settings_, void *obj,
|
2014-09-30 13:36:50 +00:00
|
|
|
|
PropertiesReloadCallback reloadCallback,
|
2014-04-24 08:43:54 +00:00
|
|
|
|
PropertiesUpdateCallback callback_,
|
2022-03-09 17:14:32 +00:00
|
|
|
|
PropertiesVisualUpdateCb visUpdateCb_,
|
|
|
|
|
int minSize_)
|
2015-01-03 11:03:04 +00:00
|
|
|
|
: VScrollArea(nullptr),
|
2014-09-30 13:36:50 +00:00
|
|
|
|
properties(nullptr, obs_properties_destroy),
|
|
|
|
|
settings(settings_),
|
2022-02-08 19:07:23 +00:00
|
|
|
|
rawObj(obj),
|
2014-09-30 13:36:50 +00:00
|
|
|
|
reloadCallback(reloadCallback),
|
|
|
|
|
callback(callback_),
|
2022-03-09 17:14:32 +00:00
|
|
|
|
visUpdateCb(visUpdateCb_),
|
2015-02-04 04:48:29 +00:00
|
|
|
|
minSize(minSize_)
|
2014-04-04 07:30:37 +00:00
|
|
|
|
{
|
2014-04-24 08:43:54 +00:00
|
|
|
|
setFrameShape(QFrame::NoFrame);
|
2022-01-08 13:32:35 +00:00
|
|
|
|
QMetaObject::invokeMethod(this, "ReloadProperties",
|
|
|
|
|
Qt::QueuedConnection);
|
2014-04-04 07:30:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 04:50:37 +00:00
|
|
|
|
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);
|
2022-01-08 13:32:35 +00:00
|
|
|
|
QMetaObject::invokeMethod(this, "ReloadProperties",
|
|
|
|
|
Qt::QueuedConnection);
|
2015-02-04 04:50:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-28 01:18:26 +00:00
|
|
|
|
void OBSPropertiesView::resizeEvent(QResizeEvent *event)
|
|
|
|
|
{
|
|
|
|
|
emit PropertiesResized();
|
2015-01-03 15:26:27 +00:00
|
|
|
|
VScrollArea::resizeEvent(event);
|
2014-08-28 01:18:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-15 02:01:52 +00:00
|
|
|
|
template<typename Sender, typename SenderParent, typename... Args>
|
|
|
|
|
QWidget *OBSPropertiesView::NewWidget(obs_property_t *prop, Sender *widget,
|
|
|
|
|
void (SenderParent::*signal)(Args...))
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2016-09-11 10:17:18 +00:00
|
|
|
|
const char *long_desc = obs_property_long_description(prop);
|
|
|
|
|
|
2014-03-23 08:07:54 +00:00
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, widget);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
QObject::connect(widget, signal, info, &WidgetInfo::ControlChanged);
|
2015-05-08 23:12:40 +00:00
|
|
|
|
children.emplace_back(info);
|
2016-09-11 10:17:18 +00:00
|
|
|
|
|
|
|
|
|
widget->setToolTip(QT_UTF8(long_desc));
|
2014-03-23 08:07:54 +00:00
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 00:44:05 +00:00
|
|
|
|
QWidget *OBSPropertiesView::AddCheckbox(obs_property_t *prop)
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2014-03-23 13:41:54 +00:00
|
|
|
|
const char *name = obs_property_name(prop);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
const char *desc = obs_property_description(prop);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
bool val = obs_data_get_bool(settings, name);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
2014-03-23 13:41:54 +00:00
|
|
|
|
QCheckBox *checkbox = new QCheckBox(QT_UTF8(desc));
|
|
|
|
|
checkbox->setCheckState(val ? Qt::Checked : Qt::Unchecked);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
return NewWidget(prop, checkbox, &QCheckBox::stateChanged);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-25 05:24:26 +00:00
|
|
|
|
QWidget *OBSPropertiesView::AddText(obs_property_t *prop, QFormLayout *layout,
|
|
|
|
|
QLabel *&label)
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2014-04-02 07:42:12 +00:00
|
|
|
|
const char *name = obs_property_name(prop);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
const char *val = obs_data_get_string(settings, name);
|
2022-08-06 05:03:28 +00:00
|
|
|
|
bool monospace = obs_property_text_monospace(prop);
|
2018-02-22 03:22:53 +00:00
|
|
|
|
obs_text_type type = obs_property_text_type(prop);
|
2014-07-19 19:31:46 +00:00
|
|
|
|
|
|
|
|
|
if (type == OBS_TEXT_MULTILINE) {
|
2022-08-06 05:03:28 +00:00
|
|
|
|
OBSPlainTextEdit *edit = new OBSPlainTextEdit(this, monospace);
|
|
|
|
|
edit->setPlainText(QT_UTF8(val));
|
2019-12-29 08:49:42 +00:00
|
|
|
|
edit->setTabStopDistance(40);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
return NewWidget(prop, edit, &OBSPlainTextEdit::textChanged);
|
2014-07-19 19:31:46 +00:00
|
|
|
|
|
2015-05-25 05:24:26 +00:00
|
|
|
|
} else if (type == OBS_TEXT_PASSWORD) {
|
|
|
|
|
QLayout *subLayout = new QHBoxLayout();
|
|
|
|
|
QLineEdit *edit = new QLineEdit();
|
|
|
|
|
QPushButton *show = new QPushButton();
|
2014-04-02 07:42:12 +00:00
|
|
|
|
|
2015-05-25 05:24:26 +00:00
|
|
|
|
show->setText(QTStr("Show"));
|
|
|
|
|
show->setCheckable(true);
|
|
|
|
|
edit->setText(QT_UTF8(val));
|
2014-04-02 07:42:12 +00:00
|
|
|
|
edit->setEchoMode(QLineEdit::Password);
|
2014-03-23 13:41:54 +00:00
|
|
|
|
|
2015-05-25 05:24:26 +00:00
|
|
|
|
subLayout->addWidget(edit);
|
|
|
|
|
subLayout->addWidget(show);
|
|
|
|
|
|
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, edit);
|
|
|
|
|
connect(show, &QAbstractButton::toggled, info,
|
|
|
|
|
&WidgetInfo::TogglePasswordText);
|
2015-07-06 11:21:11 +00:00
|
|
|
|
connect(show, &QAbstractButton::toggled, [=](bool hide) {
|
|
|
|
|
show->setText(hide ? QTStr("Hide") : QTStr("Show"));
|
|
|
|
|
});
|
2015-05-25 05:24:26 +00:00
|
|
|
|
children.emplace_back(info);
|
|
|
|
|
|
|
|
|
|
label = new QLabel(QT_UTF8(obs_property_description(prop)));
|
|
|
|
|
layout->addRow(label, subLayout);
|
2015-05-30 10:13:41 +00:00
|
|
|
|
|
2016-09-11 10:17:18 +00:00
|
|
|
|
edit->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
|
|
|
|
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(edit, &QLineEdit::textEdited, info,
|
|
|
|
|
&WidgetInfo::ControlChanged);
|
2015-05-25 05:24:26 +00:00
|
|
|
|
return nullptr;
|
2022-01-13 10:44:41 +00:00
|
|
|
|
} else if (type == OBS_TEXT_INFO) {
|
|
|
|
|
QString desc = QT_UTF8(obs_property_description(prop));
|
|
|
|
|
const char *long_desc = obs_property_long_description(prop);
|
|
|
|
|
obs_text_info_type info_type =
|
|
|
|
|
obs_property_text_info_type(prop);
|
|
|
|
|
|
|
|
|
|
QLabel *info_label = new QLabel(QT_UTF8(val));
|
|
|
|
|
|
|
|
|
|
if (info_label->text().isEmpty() && long_desc == NULL) {
|
|
|
|
|
label = nullptr;
|
|
|
|
|
info_label->setText(desc);
|
|
|
|
|
} else
|
|
|
|
|
label = new QLabel(desc);
|
|
|
|
|
|
|
|
|
|
if (long_desc != NULL && !info_label->text().isEmpty()) {
|
|
|
|
|
QString file = !App()->IsThemeDark()
|
|
|
|
|
? ":/res/images/help.svg"
|
|
|
|
|
: ":/res/images/help_light.svg";
|
|
|
|
|
QString lStr = "<html>%1 <img src='%2' style=' \
|
|
|
|
|
vertical-align: bottom; ' /></html>";
|
|
|
|
|
|
|
|
|
|
info_label->setText(lStr.arg(info_label->text(), file));
|
|
|
|
|
info_label->setToolTip(QT_UTF8(long_desc));
|
|
|
|
|
} else if (long_desc != NULL) {
|
|
|
|
|
info_label->setText(QT_UTF8(long_desc));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info_label->setOpenExternalLinks(true);
|
|
|
|
|
info_label->setWordWrap(obs_property_text_info_word_wrap(prop));
|
|
|
|
|
|
|
|
|
|
if (info_type == OBS_TEXT_INFO_WARNING)
|
|
|
|
|
info_label->setObjectName("warningLabel");
|
|
|
|
|
else if (info_type == OBS_TEXT_INFO_ERROR)
|
|
|
|
|
info_label->setObjectName("errorLabel");
|
|
|
|
|
|
|
|
|
|
if (label)
|
|
|
|
|
label->setObjectName(info_label->objectName());
|
|
|
|
|
|
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, info_label);
|
|
|
|
|
children.emplace_back(info);
|
|
|
|
|
|
|
|
|
|
layout->addRow(label, info_label);
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
2015-05-25 05:24:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLineEdit *edit = new QLineEdit();
|
|
|
|
|
|
2014-03-23 13:41:54 +00:00
|
|
|
|
edit->setText(QT_UTF8(val));
|
2016-09-11 10:17:18 +00:00
|
|
|
|
edit->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
2014-03-23 13:41:54 +00:00
|
|
|
|
|
2023-03-15 02:01:52 +00:00
|
|
|
|
return NewWidget(prop, edit, &QLineEdit::textEdited);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 00:44:05 +00:00
|
|
|
|
void OBSPropertiesView::AddPath(obs_property_t *prop, QFormLayout *layout,
|
2014-06-28 02:55:47 +00:00
|
|
|
|
QLabel **label)
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2014-06-28 02:55:47 +00:00
|
|
|
|
const char *name = obs_property_name(prop);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
const char *val = obs_data_get_string(settings, name);
|
2014-06-28 02:55:47 +00:00
|
|
|
|
QLayout *subLayout = new QHBoxLayout();
|
|
|
|
|
QLineEdit *edit = new QLineEdit();
|
|
|
|
|
QPushButton *button = new QPushButton(QTStr("Browse"));
|
|
|
|
|
|
2017-04-01 20:32:26 +00:00
|
|
|
|
if (!obs_property_enabled(prop)) {
|
|
|
|
|
edit->setEnabled(false);
|
|
|
|
|
button->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 19:34:05 +00:00
|
|
|
|
button->setProperty("themeID", "settingsButtons");
|
2014-06-28 02:55:47 +00:00
|
|
|
|
edit->setText(QT_UTF8(val));
|
|
|
|
|
edit->setReadOnly(true);
|
2016-09-11 10:17:18 +00:00
|
|
|
|
edit->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
2014-06-28 02:55:47 +00:00
|
|
|
|
|
|
|
|
|
subLayout->addWidget(edit);
|
|
|
|
|
subLayout->addWidget(button);
|
|
|
|
|
|
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, edit);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(button, &QPushButton::clicked, info,
|
|
|
|
|
&WidgetInfo::ControlChanged);
|
2015-05-08 23:12:40 +00:00
|
|
|
|
children.emplace_back(info);
|
2014-06-28 02:55:47 +00:00
|
|
|
|
|
|
|
|
|
*label = new QLabel(QT_UTF8(obs_property_description(prop)));
|
|
|
|
|
layout->addRow(*label, subLayout);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-18 01:34:21 +00:00
|
|
|
|
void OBSPropertiesView::AddInt(obs_property_t *prop, QFormLayout *layout,
|
|
|
|
|
QLabel **label)
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2015-03-18 01:34:21 +00:00
|
|
|
|
obs_number_type type = obs_property_int_type(prop);
|
|
|
|
|
QLayout *subLayout = new QHBoxLayout();
|
|
|
|
|
|
2014-03-23 13:41:54 +00:00
|
|
|
|
const char *name = obs_property_name(prop);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
int val = (int)obs_data_get_int(settings, name);
|
2019-04-07 00:56:52 +00:00
|
|
|
|
QSpinBox *spin = new SpinBoxIgnoreScroll();
|
2014-03-23 13:41:54 +00:00
|
|
|
|
|
2020-12-02 02:59:09 +00:00
|
|
|
|
spin->setEnabled(obs_property_enabled(prop));
|
2017-04-01 20:32:26 +00:00
|
|
|
|
|
2015-03-18 01:34:21 +00:00
|
|
|
|
int minVal = obs_property_int_min(prop);
|
|
|
|
|
int maxVal = obs_property_int_max(prop);
|
|
|
|
|
int stepVal = obs_property_int_step(prop);
|
2019-04-30 14:31:30 +00:00
|
|
|
|
const char *suffix = obs_property_int_suffix(prop);
|
2015-03-18 01:34:21 +00:00
|
|
|
|
|
|
|
|
|
spin->setMinimum(minVal);
|
|
|
|
|
spin->setMaximum(maxVal);
|
|
|
|
|
spin->setSingleStep(stepVal);
|
2014-03-23 13:41:54 +00:00
|
|
|
|
spin->setValue(val);
|
2016-09-11 10:17:18 +00:00
|
|
|
|
spin->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
2019-04-30 14:31:30 +00:00
|
|
|
|
spin->setSuffix(QT_UTF8(suffix));
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
2015-03-18 01:34:21 +00:00
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, spin);
|
2015-05-08 23:12:40 +00:00
|
|
|
|
children.emplace_back(info);
|
2015-03-18 01:34:21 +00:00
|
|
|
|
|
|
|
|
|
if (type == OBS_NUMBER_SLIDER) {
|
2019-04-07 00:56:52 +00:00
|
|
|
|
QSlider *slider = new SliderIgnoreScroll();
|
2015-03-18 01:34:21 +00:00
|
|
|
|
slider->setMinimum(minVal);
|
|
|
|
|
slider->setMaximum(maxVal);
|
|
|
|
|
slider->setPageStep(stepVal);
|
|
|
|
|
slider->setValue(val);
|
|
|
|
|
slider->setOrientation(Qt::Horizontal);
|
2020-12-02 02:59:09 +00:00
|
|
|
|
slider->setEnabled(obs_property_enabled(prop));
|
2015-03-18 01:34:21 +00:00
|
|
|
|
subLayout->addWidget(slider);
|
|
|
|
|
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(slider, &QSlider::valueChanged, spin,
|
|
|
|
|
&QSpinBox::setValue);
|
|
|
|
|
connect(spin, &QSpinBox::valueChanged, slider,
|
|
|
|
|
&QSlider::setValue);
|
2015-03-18 01:34:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(spin, &QSpinBox::valueChanged, info,
|
|
|
|
|
&WidgetInfo::ControlChanged);
|
2015-03-18 01:34:21 +00:00
|
|
|
|
|
|
|
|
|
subLayout->addWidget(spin);
|
|
|
|
|
|
|
|
|
|
*label = new QLabel(QT_UTF8(obs_property_description(prop)));
|
|
|
|
|
layout->addRow(*label, subLayout);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-18 01:34:21 +00:00
|
|
|
|
void OBSPropertiesView::AddFloat(obs_property_t *prop, QFormLayout *layout,
|
|
|
|
|
QLabel **label)
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2015-03-18 01:34:21 +00:00
|
|
|
|
obs_number_type type = obs_property_float_type(prop);
|
|
|
|
|
QLayout *subLayout = new QHBoxLayout();
|
|
|
|
|
|
2014-03-23 13:41:54 +00:00
|
|
|
|
const char *name = obs_property_name(prop);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
double val = obs_data_get_double(settings, name);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
QDoubleSpinBox *spin = new QDoubleSpinBox();
|
2014-03-23 13:41:54 +00:00
|
|
|
|
|
2017-04-01 20:32:26 +00:00
|
|
|
|
if (!obs_property_enabled(prop))
|
|
|
|
|
spin->setEnabled(false);
|
|
|
|
|
|
2015-03-18 01:34:21 +00:00
|
|
|
|
double minVal = obs_property_float_min(prop);
|
|
|
|
|
double maxVal = obs_property_float_max(prop);
|
|
|
|
|
double stepVal = obs_property_float_step(prop);
|
2019-04-30 14:31:30 +00:00
|
|
|
|
const char *suffix = obs_property_float_suffix(prop);
|
2015-03-18 01:34:21 +00:00
|
|
|
|
|
2021-04-13 10:30:29 +00:00
|
|
|
|
if (stepVal < 1.0) {
|
|
|
|
|
constexpr int sane_limit = 8;
|
2021-09-18 05:09:37 +00:00
|
|
|
|
const int decimals =
|
|
|
|
|
std::min<int>(log10(1.0 / stepVal) + 0.99, sane_limit);
|
2021-04-13 10:30:29 +00:00
|
|
|
|
if (decimals > spin->decimals())
|
|
|
|
|
spin->setDecimals(decimals);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 16:38:41 +00:00
|
|
|
|
spin->setMinimum(minVal);
|
|
|
|
|
spin->setMaximum(maxVal);
|
|
|
|
|
spin->setSingleStep(stepVal);
|
|
|
|
|
spin->setValue(val);
|
|
|
|
|
spin->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
|
|
|
|
spin->setSuffix(QT_UTF8(suffix));
|
|
|
|
|
|
2015-03-18 01:34:21 +00:00
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, spin);
|
2015-05-08 23:12:40 +00:00
|
|
|
|
children.emplace_back(info);
|
2015-03-18 01:34:21 +00:00
|
|
|
|
|
|
|
|
|
if (type == OBS_NUMBER_SLIDER) {
|
|
|
|
|
DoubleSlider *slider = new DoubleSlider();
|
|
|
|
|
slider->setDoubleConstraints(minVal, maxVal, stepVal, val);
|
|
|
|
|
slider->setOrientation(Qt::Horizontal);
|
|
|
|
|
subLayout->addWidget(slider);
|
|
|
|
|
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(slider, &DoubleSlider::doubleValChanged, spin,
|
|
|
|
|
&QDoubleSpinBox::setValue);
|
|
|
|
|
connect(spin, &QDoubleSpinBox::valueChanged, slider,
|
|
|
|
|
&DoubleSlider::setDoubleVal);
|
2015-03-18 01:34:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(spin, &QDoubleSpinBox::valueChanged, info,
|
|
|
|
|
&WidgetInfo::ControlChanged);
|
2015-03-18 01:34:21 +00:00
|
|
|
|
|
|
|
|
|
subLayout->addWidget(spin);
|
|
|
|
|
|
|
|
|
|
*label = new QLabel(QT_UTF8(obs_property_description(prop)));
|
|
|
|
|
layout->addRow(*label, subLayout);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-20 01:32:05 +00:00
|
|
|
|
static QVariant propertyListToQVariant(obs_property_t *prop, size_t idx)
|
2014-04-04 07:30:37 +00:00
|
|
|
|
{
|
2022-11-20 01:32:05 +00:00
|
|
|
|
obs_combo_format format = obs_property_list_format(prop);
|
2014-04-04 07:30:37 +00:00
|
|
|
|
|
2022-11-20 01:32:05 +00:00
|
|
|
|
QVariant var;
|
2014-04-04 07:30:37 +00:00
|
|
|
|
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) {
|
2016-06-05 20:36:49 +00:00
|
|
|
|
var = QByteArray(obs_property_list_item_string(prop, idx));
|
2022-12-01 11:36:58 +00:00
|
|
|
|
} else if (format == OBS_COMBO_FORMAT_BOOL) {
|
|
|
|
|
bool val = obs_property_list_item_bool(prop, idx);
|
|
|
|
|
var = QVariant::fromValue<bool>(val);
|
2014-04-04 07:30:37 +00:00
|
|
|
|
}
|
2022-11-20 01:32:05 +00:00
|
|
|
|
return var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void AddComboItem(QComboBox *combo, obs_property_t *prop, size_t idx)
|
|
|
|
|
{
|
|
|
|
|
const char *name = obs_property_list_item_name(prop, idx);
|
|
|
|
|
QVariant var = propertyListToQVariant(prop, idx);
|
2014-04-04 07:30:37 +00:00
|
|
|
|
|
|
|
|
|
combo->addItem(QT_UTF8(name), var);
|
2014-06-12 00:01:47 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2014-04-04 07:30:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-20 01:32:05 +00:00
|
|
|
|
static void AddRadioItem(QButtonGroup *buttonGroup, QFormLayout *layout,
|
|
|
|
|
obs_property_t *prop, QVariant value, size_t idx)
|
|
|
|
|
{
|
|
|
|
|
const char *name = obs_property_list_item_name(prop, idx);
|
|
|
|
|
|
|
|
|
|
QVariant var = propertyListToQVariant(prop, idx);
|
|
|
|
|
QRadioButton *button = new QRadioButton(name);
|
|
|
|
|
button->setChecked(value == var);
|
|
|
|
|
button->setProperty("value", var);
|
|
|
|
|
buttonGroup->addButton(button);
|
|
|
|
|
layout->addRow(button);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 00:44:05 +00:00
|
|
|
|
template<long long get_int(obs_data_t *, const char *),
|
|
|
|
|
double get_double(obs_data_t *, const char *),
|
2022-12-01 11:36:58 +00:00
|
|
|
|
const char *get_string(obs_data_t *, const char *),
|
|
|
|
|
bool get_bool(obs_data_t *, const char *)>
|
2022-07-23 02:08:03 +00:00
|
|
|
|
static QVariant from_obs_data(obs_data_t *data, const char *name,
|
|
|
|
|
obs_combo_format format)
|
2014-06-15 05:05:50 +00:00
|
|
|
|
{
|
|
|
|
|
switch (format) {
|
|
|
|
|
case OBS_COMBO_FORMAT_INT:
|
2022-07-23 02:08:03 +00:00
|
|
|
|
return QVariant::fromValue(get_int(data, name));
|
2014-06-15 05:05:50 +00:00
|
|
|
|
case OBS_COMBO_FORMAT_FLOAT:
|
2022-07-23 02:08:03 +00:00
|
|
|
|
return QVariant::fromValue(get_double(data, name));
|
2014-06-15 05:05:50 +00:00
|
|
|
|
case OBS_COMBO_FORMAT_STRING:
|
2022-07-23 02:08:03 +00:00
|
|
|
|
return QByteArray(get_string(data, name));
|
2022-12-01 11:36:58 +00:00
|
|
|
|
case OBS_COMBO_FORMAT_BOOL:
|
|
|
|
|
return QVariant::fromValue(get_bool(data, name));
|
2014-06-15 05:05:50 +00:00
|
|
|
|
default:
|
2022-07-23 02:08:03 +00:00
|
|
|
|
return QVariant();
|
2014-06-15 05:05:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 02:08:03 +00:00
|
|
|
|
static QVariant from_obs_data(obs_data_t *data, const char *name,
|
|
|
|
|
obs_combo_format format)
|
2014-06-15 05:05:50 +00:00
|
|
|
|
{
|
2014-08-05 18:09:29 +00:00
|
|
|
|
return from_obs_data<obs_data_get_int, obs_data_get_double,
|
2022-12-01 11:36:58 +00:00
|
|
|
|
obs_data_get_string, obs_data_get_bool>(data, name,
|
|
|
|
|
format);
|
2014-06-15 05:05:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 02:08:03 +00:00
|
|
|
|
static QVariant from_obs_data_autoselect(obs_data_t *data, const char *name,
|
|
|
|
|
obs_combo_format format)
|
2014-06-15 05:05:50 +00:00
|
|
|
|
{
|
2022-12-01 11:36:58 +00:00
|
|
|
|
return from_obs_data<
|
|
|
|
|
obs_data_get_autoselect_int, obs_data_get_autoselect_double,
|
|
|
|
|
obs_data_get_autoselect_string, obs_data_get_autoselect_bool>(
|
|
|
|
|
data, name, format);
|
2014-06-15 05:05:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 00:44:05 +00:00
|
|
|
|
QWidget *OBSPropertiesView::AddList(obs_property_t *prop, bool &warning)
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2014-03-23 13:41:54 +00:00
|
|
|
|
const char *name = obs_property_name(prop);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
obs_combo_type type = obs_property_list_type(prop);
|
2014-03-23 13:41:54 +00:00
|
|
|
|
obs_combo_format format = obs_property_list_format(prop);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
size_t count = obs_property_list_item_count(prop);
|
2022-11-20 01:32:05 +00:00
|
|
|
|
|
|
|
|
|
QVariant value = from_obs_data(settings, name, format);
|
|
|
|
|
|
|
|
|
|
if (type == OBS_COMBO_TYPE_RADIO) {
|
|
|
|
|
QButtonGroup *buttonGroup = new QButtonGroup();
|
|
|
|
|
QFormLayout *subLayout = new QFormLayout();
|
|
|
|
|
subLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
for (size_t idx = 0; idx < count; idx++)
|
|
|
|
|
AddRadioItem(buttonGroup, subLayout, prop, value, idx);
|
|
|
|
|
|
2023-06-26 18:58:30 +00:00
|
|
|
|
if (count > 0) {
|
|
|
|
|
buttonGroup->setExclusive(true);
|
|
|
|
|
WidgetInfo *info = new WidgetInfo(
|
|
|
|
|
this, prop, buttonGroup->buttons()[0]);
|
|
|
|
|
children.emplace_back(info);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(buttonGroup, &QButtonGroup::buttonClicked, info,
|
|
|
|
|
&WidgetInfo::ControlChanged);
|
2023-06-26 18:58:30 +00:00
|
|
|
|
}
|
2022-11-20 01:32:05 +00:00
|
|
|
|
|
|
|
|
|
QWidget *widget = new QWidget();
|
|
|
|
|
widget->setLayout(subLayout);
|
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 13:41:54 +00:00
|
|
|
|
int idx = -1;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
2023-06-04 12:31:55 +00:00
|
|
|
|
QComboBox *combo = new QComboBox();
|
2014-04-04 07:30:37 +00:00
|
|
|
|
for (size_t i = 0; i < count; i++)
|
2022-11-20 01:32:05 +00:00
|
|
|
|
AddComboItem(combo, prop, i);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
2014-05-30 09:44:14 +00:00
|
|
|
|
if (type == OBS_COMBO_TYPE_EDITABLE)
|
|
|
|
|
combo->setEditable(true);
|
|
|
|
|
|
2016-05-26 14:36:32 +00:00
|
|
|
|
combo->setMaxVisibleItems(40);
|
2016-09-11 10:17:18 +00:00
|
|
|
|
combo->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
2016-05-26 14:36:32 +00:00
|
|
|
|
|
2014-06-15 05:05:50 +00:00
|
|
|
|
if (format == OBS_COMBO_FORMAT_STRING &&
|
2016-06-05 20:36:49 +00:00
|
|
|
|
type == OBS_COMBO_TYPE_EDITABLE) {
|
2022-07-23 02:08:03 +00:00
|
|
|
|
combo->lineEdit()->setText(value.toString());
|
2016-06-05 20:36:49 +00:00
|
|
|
|
} else {
|
2022-07-23 02:08:03 +00:00
|
|
|
|
idx = combo->findData(value);
|
2016-06-05 20:36:49 +00:00
|
|
|
|
}
|
2014-03-23 13:41:54 +00:00
|
|
|
|
|
2014-05-30 09:44:14 +00:00
|
|
|
|
if (type == OBS_COMBO_TYPE_EDITABLE)
|
2023-03-15 02:01:52 +00:00
|
|
|
|
return NewWidget(prop, combo, &QComboBox::editTextChanged);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
2014-03-23 13:41:54 +00:00
|
|
|
|
if (idx != -1)
|
|
|
|
|
combo->setCurrentIndex(idx);
|
2019-06-23 05:13:45 +00:00
|
|
|
|
|
2014-08-09 19:38:56 +00:00
|
|
|
|
if (obs_data_has_autoselect_value(settings, name)) {
|
2022-07-23 02:08:03 +00:00
|
|
|
|
QVariant autoselect =
|
2014-06-15 05:05:50 +00:00
|
|
|
|
from_obs_data_autoselect(settings, name, format);
|
2022-07-23 02:08:03 +00:00
|
|
|
|
int id = combo->findData(autoselect);
|
2014-06-15 05:05:50 +00:00
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-21 20:13:30 +00:00
|
|
|
|
QAbstractItemModel *model = combo->model();
|
|
|
|
|
warning = idx != -1 &&
|
|
|
|
|
model->flags(model->index(idx, 0)) == Qt::NoItemFlags;
|
|
|
|
|
|
2014-04-04 07:30:37 +00:00
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, combo);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(combo, &QComboBox::currentIndexChanged, info,
|
|
|
|
|
&WidgetInfo::ControlChanged);
|
2015-05-08 23:12:40 +00:00
|
|
|
|
children.emplace_back(info);
|
2014-04-04 07:30:37 +00:00
|
|
|
|
|
|
|
|
|
/* trigger a settings update if the index was not found */
|
2022-09-07 10:05:19 +00:00
|
|
|
|
if (count && idx == -1)
|
2014-04-04 07:30:37 +00:00
|
|
|
|
info->ControlChanged();
|
|
|
|
|
|
|
|
|
|
return combo;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-13 18:23:54 +00:00
|
|
|
|
static void NewButton(QLayout *layout, WidgetInfo *info, const char *themeIcon,
|
|
|
|
|
void (WidgetInfo::*method)())
|
|
|
|
|
{
|
|
|
|
|
QPushButton *button = new QPushButton();
|
|
|
|
|
button->setProperty("themeID", themeIcon);
|
|
|
|
|
button->setFlat(true);
|
2022-08-30 01:54:46 +00:00
|
|
|
|
button->setProperty("toolButton", true);
|
2015-04-13 18:23:54 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2021-11-26 09:25:39 +00:00
|
|
|
|
OBSDataArrayAutoRelease array = obs_data_get_array(settings, name);
|
2015-04-13 18:23:54 +00:00
|
|
|
|
QListWidget *list = new QListWidget();
|
|
|
|
|
size_t count = obs_data_array_count(array);
|
|
|
|
|
|
2017-04-01 20:32:26 +00:00
|
|
|
|
if (!obs_property_enabled(prop))
|
|
|
|
|
list->setEnabled(false);
|
|
|
|
|
|
2015-04-13 18:23:54 +00:00
|
|
|
|
list->setSortingEnabled(false);
|
|
|
|
|
list->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2016-09-11 10:17:18 +00:00
|
|
|
|
list->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
2022-08-30 00:48:12 +00:00
|
|
|
|
list->setSpacing(1);
|
2015-04-13 18:23:54 +00:00
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
2021-11-26 09:25:39 +00:00
|
|
|
|
OBSDataAutoRelease item = obs_data_array_item(array, i);
|
2015-04-13 18:23:54 +00:00
|
|
|
|
list->addItem(QT_UTF8(obs_data_get_string(item, "value")));
|
2019-12-01 00:05:50 +00:00
|
|
|
|
QListWidgetItem *const list_item = list->item((int)i);
|
|
|
|
|
list_item->setSelected(obs_data_get_bool(item, "selected"));
|
|
|
|
|
list_item->setHidden(obs_data_get_bool(item, "hidden"));
|
2015-04-13 18:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, list);
|
|
|
|
|
|
2020-05-19 05:07:14 +00:00
|
|
|
|
list->setDragDropMode(QAbstractItemView::InternalMove);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(list->model(), &QAbstractItemModel::rowsMoved,
|
|
|
|
|
[info]() { info->EditableListChanged(); });
|
2020-05-19 05:07:14 +00:00
|
|
|
|
|
2015-04-13 18:23:54 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 00:44:05 +00:00
|
|
|
|
QWidget *OBSPropertiesView::AddButton(obs_property_t *prop)
|
2014-05-30 09:44:14 +00:00
|
|
|
|
{
|
|
|
|
|
const char *desc = obs_property_description(prop);
|
|
|
|
|
|
|
|
|
|
QPushButton *button = new QPushButton(QT_UTF8(desc));
|
2017-06-13 19:34:05 +00:00
|
|
|
|
button->setProperty("themeID", "settingsButtons");
|
2014-05-30 09:44:14 +00:00
|
|
|
|
button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
return NewWidget(prop, button, &QPushButton::clicked);
|
2014-05-30 09:44:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-30 03:51:40 +00:00
|
|
|
|
void OBSPropertiesView::AddColorInternal(obs_property_t *prop,
|
|
|
|
|
QFormLayout *layout, QLabel *&label,
|
|
|
|
|
bool supportAlpha)
|
2014-07-19 19:00:14 +00:00
|
|
|
|
{
|
|
|
|
|
QPushButton *button = new QPushButton;
|
|
|
|
|
QLabel *colorLabel = new QLabel;
|
|
|
|
|
const char *name = obs_property_name(prop);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
long long val = obs_data_get_int(settings, name);
|
2014-07-19 19:00:14 +00:00
|
|
|
|
QColor color = color_from_int(val);
|
2020-12-30 03:51:40 +00:00
|
|
|
|
QColor::NameFormat format;
|
2014-07-19 19:00:14 +00:00
|
|
|
|
|
2017-04-01 20:32:26 +00:00
|
|
|
|
if (!obs_property_enabled(prop)) {
|
|
|
|
|
button->setEnabled(false);
|
|
|
|
|
colorLabel->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 19:34:05 +00:00
|
|
|
|
button->setProperty("themeID", "settingsButtons");
|
2014-07-19 19:00:14 +00:00
|
|
|
|
button->setText(QTStr("Basic.PropertiesWindow.SelectColor"));
|
2016-09-11 10:17:18 +00:00
|
|
|
|
button->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
2014-07-19 19:00:14 +00:00
|
|
|
|
|
2020-12-30 03:51:40 +00:00
|
|
|
|
if (supportAlpha) {
|
|
|
|
|
format = QColor::HexArgb;
|
|
|
|
|
} else {
|
|
|
|
|
format = QColor::HexRgb;
|
|
|
|
|
color.setAlpha(255);
|
|
|
|
|
}
|
2018-06-21 02:21:52 +00:00
|
|
|
|
|
2018-05-23 16:50:41 +00:00
|
|
|
|
QPalette palette = QPalette(color);
|
2014-07-19 19:00:14 +00:00
|
|
|
|
colorLabel->setFrameStyle(QFrame::Sunken | QFrame::Panel);
|
2020-12-30 03:51:40 +00:00
|
|
|
|
colorLabel->setText(color.name(format));
|
2018-05-23 16:50:41 +00:00
|
|
|
|
colorLabel->setPalette(palette);
|
|
|
|
|
colorLabel->setStyleSheet(
|
|
|
|
|
QString("background-color :%1; color: %2;")
|
2020-12-30 03:51:40 +00:00
|
|
|
|
.arg(palette.color(QPalette::Window).name(format))
|
|
|
|
|
.arg(palette.color(QPalette::WindowText).name(format)));
|
2014-07-19 19:00:14 +00:00
|
|
|
|
colorLabel->setAutoFillBackground(true);
|
|
|
|
|
colorLabel->setAlignment(Qt::AlignCenter);
|
2016-09-11 10:17:18 +00:00
|
|
|
|
colorLabel->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
2014-07-19 19:00:14 +00:00
|
|
|
|
|
|
|
|
|
QHBoxLayout *subLayout = new QHBoxLayout;
|
|
|
|
|
subLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
2018-06-21 02:16:57 +00:00
|
|
|
|
subLayout->addWidget(colorLabel);
|
2014-07-19 19:00:14 +00:00
|
|
|
|
subLayout->addWidget(button);
|
|
|
|
|
|
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, colorLabel);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(button, &QPushButton::clicked, info,
|
|
|
|
|
&WidgetInfo::ControlChanged);
|
2014-07-19 19:00:14 +00:00
|
|
|
|
children.emplace_back(info);
|
|
|
|
|
|
|
|
|
|
label = new QLabel(QT_UTF8(obs_property_description(prop)));
|
|
|
|
|
layout->addRow(label, subLayout);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-30 03:51:40 +00:00
|
|
|
|
void OBSPropertiesView::AddColor(obs_property_t *prop, QFormLayout *layout,
|
|
|
|
|
QLabel *&label)
|
|
|
|
|
{
|
|
|
|
|
AddColorInternal(prop, layout, label, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OBSPropertiesView::AddColorAlpha(obs_property_t *prop, QFormLayout *layout,
|
|
|
|
|
QLabel *&label)
|
|
|
|
|
{
|
|
|
|
|
AddColorInternal(prop, layout, label, true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-24 01:43:44 +00:00
|
|
|
|
void MakeQFont(obs_data_t *font_obj, QFont &font, bool limit = false)
|
2014-08-17 12:50:30 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-13 21:42:13 +00:00
|
|
|
|
if (size) {
|
|
|
|
|
if (limit) {
|
|
|
|
|
int max_size = font.pointSize();
|
|
|
|
|
if (max_size < 28)
|
|
|
|
|
max_size = 28;
|
|
|
|
|
if (size > max_size)
|
|
|
|
|
size = max_size;
|
|
|
|
|
}
|
2014-08-17 12:50:30 +00:00
|
|
|
|
font.setPointSize(size);
|
2016-09-13 21:42:13 +00:00
|
|
|
|
}
|
2014-08-17 12:50:30 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 00:44:05 +00:00
|
|
|
|
void OBSPropertiesView::AddFont(obs_property_t *prop, QFormLayout *layout,
|
2014-08-17 12:50:30 +00:00
|
|
|
|
QLabel *&label)
|
|
|
|
|
{
|
|
|
|
|
const char *name = obs_property_name(prop);
|
2021-11-26 09:25:39 +00:00
|
|
|
|
OBSDataAutoRelease font_obj = obs_data_get_obj(settings, name);
|
2014-08-17 12:50:30 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2017-04-01 20:32:26 +00:00
|
|
|
|
if (!obs_property_enabled(prop)) {
|
|
|
|
|
button->setEnabled(false);
|
|
|
|
|
fontLabel->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 12:50:30 +00:00
|
|
|
|
font = fontLabel->font();
|
2016-09-13 21:42:13 +00:00
|
|
|
|
MakeQFont(font_obj, font, true);
|
2014-08-17 12:50:30 +00:00
|
|
|
|
|
2017-06-13 19:34:05 +00:00
|
|
|
|
button->setProperty("themeID", "settingsButtons");
|
2014-08-17 12:50:30 +00:00
|
|
|
|
button->setText(QTStr("Basic.PropertiesWindow.SelectFont"));
|
2016-09-11 10:17:18 +00:00
|
|
|
|
button->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
2014-08-17 12:50:30 +00:00
|
|
|
|
|
|
|
|
|
fontLabel->setFrameStyle(QFrame::Sunken | QFrame::Panel);
|
|
|
|
|
fontLabel->setFont(font);
|
|
|
|
|
fontLabel->setText(QString("%1 %2").arg(face, style));
|
|
|
|
|
fontLabel->setAlignment(Qt::AlignCenter);
|
2016-09-11 10:17:18 +00:00
|
|
|
|
fontLabel->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
2014-08-17 12:50:30 +00:00
|
|
|
|
|
|
|
|
|
QHBoxLayout *subLayout = new QHBoxLayout;
|
|
|
|
|
subLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
subLayout->addWidget(fontLabel);
|
|
|
|
|
subLayout->addWidget(button);
|
|
|
|
|
|
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, fontLabel);
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(button, &QPushButton::clicked, info,
|
|
|
|
|
&WidgetInfo::ControlChanged);
|
2014-08-17 12:50:30 +00:00
|
|
|
|
children.emplace_back(info);
|
|
|
|
|
|
|
|
|
|
label = new QLabel(QT_UTF8(obs_property_description(prop)));
|
|
|
|
|
layout->addRow(label, subLayout);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 12:57:36 +00:00
|
|
|
|
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); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
|
|
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);
|
2022-08-13 02:27:41 +00:00
|
|
|
|
/*blog(LOG_INFO, "%lg <= %lg <= %lg? %s %s %s",
|
2015-08-18 12:57:36 +00:00
|
|
|
|
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[] = {
|
2023-08-11 12:25:01 +00:00
|
|
|
|
{"240", {240, 1}}, {"144", {144, 1}},
|
|
|
|
|
{"120", {120, 1}}, {"119.88", {120000, 1001}},
|
|
|
|
|
{"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}},
|
2015-08-18 12:57:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
2022-03-27 01:48:29 +00:00
|
|
|
|
auto combo = fpsProps->simpleFPS = new QComboBox();
|
2015-08-18 12:57:36 +00:00
|
|
|
|
|
|
|
|
|
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};
|
|
|
|
|
|
2022-03-27 01:48:29 +00:00
|
|
|
|
auto combo = fpsProps->fpsRange = new QComboBox();
|
2015-08-18 12:57:36 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layout->addRow(rlabel, combo);
|
|
|
|
|
|
2019-04-07 00:56:52 +00:00
|
|
|
|
auto num_edit = fpsProps->numEdit = new SpinBoxIgnoreScroll{};
|
|
|
|
|
auto den_edit = fpsProps->denEdit = new SpinBoxIgnoreScroll{};
|
2015-08-18 12:57:36 +00:00
|
|
|
|
|
|
|
|
|
num_edit->setRange(0, INT_MAX);
|
|
|
|
|
den_edit->setRange(0, INT_MAX);
|
|
|
|
|
|
|
|
|
|
if (current_fps) {
|
|
|
|
|
num_edit->setValue(current_fps->numerator);
|
|
|
|
|
den_edit->setValue(current_fps->denominator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layout->addRow(QTStr("Basic.Settings.Video.Numerator"), num_edit);
|
|
|
|
|
layout->addRow(QTStr("Basic.Settings.Video.Denominator"), den_edit);
|
|
|
|
|
|
|
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static OBSFrameRatePropertyWidget *
|
|
|
|
|
CreateFrameRateWidget(obs_property_t *prop, bool &warning, const char *option,
|
|
|
|
|
media_frames_per_second *current_fps,
|
|
|
|
|
frame_rate_ranges_t &fps_ranges)
|
|
|
|
|
{
|
|
|
|
|
auto widget = new OBSFrameRatePropertyWidget{};
|
|
|
|
|
auto hlayout = new QHBoxLayout{};
|
|
|
|
|
hlayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
swap(widget->fps_ranges, fps_ranges);
|
|
|
|
|
|
2022-03-27 01:48:29 +00:00
|
|
|
|
auto combo = widget->modeSelect = new QComboBox();
|
2015-08-18 12:57:36 +00:00
|
|
|
|
combo->addItem(QTStr("Basic.PropertiesView.FPS.Simple"),
|
|
|
|
|
QVariant::fromValue(frame_rate_tag::simple()));
|
|
|
|
|
combo->addItem(QTStr("Basic.PropertiesView.FPS.Rational"),
|
|
|
|
|
QVariant::fromValue(frame_rate_tag::rational()));
|
|
|
|
|
|
2016-09-11 10:17:18 +00:00
|
|
|
|
combo->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
|
|
|
|
|
2015-08-18 12:57:36 +00:00
|
|
|
|
auto num = obs_property_frame_rate_options_count(prop);
|
|
|
|
|
if (num)
|
|
|
|
|
combo->insertSeparator(combo->count());
|
|
|
|
|
|
|
|
|
|
bool option_found = false;
|
|
|
|
|
for (size_t i = 0; i < num; i++) {
|
|
|
|
|
auto name = obs_property_frame_rate_option_name(prop, i);
|
|
|
|
|
auto desc = obs_property_frame_rate_option_description(prop, i);
|
|
|
|
|
combo->addItem(desc, QVariant::fromValue(frame_rate_tag{name}));
|
|
|
|
|
|
|
|
|
|
if (!name || !option || string(name) != option)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
option_found = true;
|
|
|
|
|
combo->setCurrentIndex(combo->count() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hlayout->addWidget(combo, 0, Qt::AlignTop);
|
|
|
|
|
|
|
|
|
|
auto stack = widget->modeDisplay = new QStackedWidget{};
|
|
|
|
|
|
|
|
|
|
bool match_found = option_found;
|
|
|
|
|
auto AddWidget = [&](decltype(CreateRationalFPS) func) {
|
|
|
|
|
bool selected = false;
|
|
|
|
|
stack->addWidget(func(widget, selected, current_fps));
|
|
|
|
|
|
|
|
|
|
if (match_found || !selected)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
match_found = true;
|
|
|
|
|
|
|
|
|
|
stack->setCurrentIndex(stack->count() - 1);
|
|
|
|
|
combo->setCurrentIndex(stack->count() - 1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AddWidget(CreateSimpleFPSValues);
|
|
|
|
|
AddWidget(CreateRationalFPS);
|
|
|
|
|
stack->addWidget(new QWidget{});
|
|
|
|
|
|
|
|
|
|
if (option_found)
|
|
|
|
|
stack->setCurrentIndex(stack->count() - 1);
|
|
|
|
|
else if (!match_found) {
|
|
|
|
|
int idx = current_fps ? 1 : 0; // Rational for "unsupported"
|
|
|
|
|
// Simple as default
|
|
|
|
|
stack->setCurrentIndex(idx);
|
|
|
|
|
combo->setCurrentIndex(idx);
|
|
|
|
|
warning = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hlayout->addWidget(stack, 0, Qt::AlignTop);
|
|
|
|
|
|
|
|
|
|
auto label_area = widget->labels = new QWidget{};
|
|
|
|
|
label_area->setSizePolicy(QSizePolicy::Expanding,
|
|
|
|
|
QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
|
|
auto vlayout = new QVBoxLayout{};
|
|
|
|
|
vlayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
auto fps_label = widget->currentFPS = new QLabel{"FPS: 22"};
|
|
|
|
|
auto time_label = widget->timePerFrame =
|
|
|
|
|
new QLabel{"Frame Interval: 0.123 ms"};
|
|
|
|
|
auto min_label = widget->minLabel = new QLabel{"Min FPS: 1/1"};
|
|
|
|
|
auto max_label = widget->maxLabel = new QLabel{"Max FPS: 2/1"};
|
|
|
|
|
|
|
|
|
|
min_label->setHidden(true);
|
|
|
|
|
max_label->setHidden(true);
|
|
|
|
|
|
|
|
|
|
auto flags = Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard;
|
|
|
|
|
min_label->setTextInteractionFlags(flags);
|
|
|
|
|
max_label->setTextInteractionFlags(flags);
|
|
|
|
|
|
|
|
|
|
vlayout->addWidget(fps_label);
|
|
|
|
|
vlayout->addWidget(time_label);
|
|
|
|
|
vlayout->addWidget(min_label);
|
|
|
|
|
vlayout->addWidget(max_label);
|
|
|
|
|
label_area->setLayout(vlayout);
|
|
|
|
|
|
|
|
|
|
hlayout->addWidget(label_area, 0, Qt::AlignTop);
|
|
|
|
|
|
|
|
|
|
widget->setLayout(hlayout);
|
|
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void UpdateMinMaxLabels(OBSFrameRatePropertyWidget *w)
|
|
|
|
|
{
|
|
|
|
|
auto Hide = [&](bool hide) {
|
|
|
|
|
w->minLabel->setHidden(hide);
|
|
|
|
|
w->maxLabel->setHidden(hide);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto variant = w->modeSelect->currentData();
|
|
|
|
|
if (!variant.canConvert<frame_rate_tag>() ||
|
|
|
|
|
variant.value<frame_rate_tag>().type != frame_rate_tag::RATIONAL) {
|
|
|
|
|
Hide(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variant = w->fpsRange->currentData();
|
|
|
|
|
if (!variant.canConvert<size_t>()) {
|
|
|
|
|
Hide(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto idx = variant.value<size_t>();
|
|
|
|
|
if (idx >= w->fps_ranges.size()) {
|
|
|
|
|
Hide(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Hide(false);
|
|
|
|
|
|
|
|
|
|
auto min = w->fps_ranges[idx].first;
|
|
|
|
|
auto max = w->fps_ranges[idx].second;
|
|
|
|
|
|
|
|
|
|
w->minLabel->setText(QString("Min FPS: %1/%2")
|
|
|
|
|
.arg(min.numerator)
|
|
|
|
|
.arg(min.denominator));
|
|
|
|
|
w->maxLabel->setText(QString("Max FPS: %1/%2")
|
|
|
|
|
.arg(max.numerator)
|
|
|
|
|
.arg(max.denominator));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void UpdateFPSLabels(OBSFrameRatePropertyWidget *w)
|
|
|
|
|
{
|
|
|
|
|
UpdateMinMaxLabels(w);
|
|
|
|
|
|
|
|
|
|
unique_ptr<obs_data_item_t> obj{
|
|
|
|
|
obs_data_item_byname(w->settings, w->name)};
|
|
|
|
|
|
|
|
|
|
media_frames_per_second fps{};
|
|
|
|
|
media_frames_per_second *valid_fps = nullptr;
|
|
|
|
|
if (obs_data_item_get_autoselect_frames_per_second(obj.get(), &fps,
|
|
|
|
|
nullptr) ||
|
|
|
|
|
obs_data_item_get_frames_per_second(obj.get(), &fps, nullptr))
|
|
|
|
|
valid_fps = &fps;
|
|
|
|
|
|
|
|
|
|
const char *option = nullptr;
|
|
|
|
|
obs_data_item_get_frames_per_second(obj.get(), nullptr, &option);
|
|
|
|
|
|
|
|
|
|
if (!valid_fps) {
|
|
|
|
|
w->currentFPS->setHidden(true);
|
|
|
|
|
w->timePerFrame->setHidden(true);
|
|
|
|
|
if (!option)
|
2023-03-04 07:43:09 +00:00
|
|
|
|
w->warningLabel->setObjectName("errorLabel");
|
2015-08-18 12:57:36 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w->currentFPS->setHidden(false);
|
|
|
|
|
w->timePerFrame->setHidden(false);
|
|
|
|
|
|
|
|
|
|
media_frames_per_second match{};
|
|
|
|
|
if (!option && !matches_ranges(match, *valid_fps, w->fps_ranges, true))
|
2023-03-04 07:43:09 +00:00
|
|
|
|
w->warningLabel->setObjectName("errorLabel");
|
2015-08-18 12:57:36 +00:00
|
|
|
|
else
|
2023-03-04 07:43:09 +00:00
|
|
|
|
w->warningLabel->setObjectName("");
|
2015-08-18 12:57:36 +00:00
|
|
|
|
|
|
|
|
|
auto convert_to_fps = media_frames_per_second_to_fps;
|
|
|
|
|
auto convert_to_frame_interval =
|
|
|
|
|
media_frames_per_second_to_frame_interval;
|
|
|
|
|
|
|
|
|
|
w->currentFPS->setText(
|
|
|
|
|
QString("FPS: %1").arg(convert_to_fps(*valid_fps)));
|
|
|
|
|
w->timePerFrame->setText(
|
|
|
|
|
QString("Frame Interval: %1 ms")
|
|
|
|
|
.arg(convert_to_frame_interval(*valid_fps) * 1000));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OBSPropertiesView::AddFrameRate(obs_property_t *prop, bool &warning,
|
|
|
|
|
QFormLayout *layout, QLabel *&label)
|
|
|
|
|
{
|
|
|
|
|
const char *name = obs_property_name(prop);
|
|
|
|
|
bool enabled = obs_property_enabled(prop);
|
|
|
|
|
unique_ptr<obs_data_item_t> obj{obs_data_item_byname(settings, name)};
|
|
|
|
|
|
|
|
|
|
const char *option = nullptr;
|
|
|
|
|
obs_data_item_get_frames_per_second(obj.get(), nullptr, &option);
|
|
|
|
|
|
|
|
|
|
media_frames_per_second fps{};
|
|
|
|
|
media_frames_per_second *valid_fps = nullptr;
|
|
|
|
|
if (obs_data_item_get_frames_per_second(obj.get(), &fps, nullptr))
|
|
|
|
|
valid_fps = &fps;
|
|
|
|
|
|
|
|
|
|
frame_rate_ranges_t fps_ranges;
|
|
|
|
|
size_t num = obs_property_frame_rate_fps_ranges_count(prop);
|
|
|
|
|
fps_ranges.reserve(num);
|
|
|
|
|
for (size_t i = 0; i < num; i++)
|
|
|
|
|
fps_ranges.emplace_back(
|
|
|
|
|
obs_property_frame_rate_fps_range_min(prop, i),
|
|
|
|
|
obs_property_frame_rate_fps_range_max(prop, i));
|
|
|
|
|
|
|
|
|
|
auto widget = CreateFrameRateWidget(prop, warning, option, valid_fps,
|
|
|
|
|
fps_ranges);
|
|
|
|
|
auto info = new WidgetInfo(this, prop, widget);
|
|
|
|
|
|
2016-09-11 10:17:18 +00:00
|
|
|
|
widget->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
|
|
|
|
|
2015-08-18 12:57:36 +00:00
|
|
|
|
widget->name = name;
|
|
|
|
|
widget->settings = settings;
|
|
|
|
|
|
|
|
|
|
widget->modeSelect->setEnabled(enabled);
|
|
|
|
|
widget->simpleFPS->setEnabled(enabled);
|
|
|
|
|
widget->fpsRange->setEnabled(enabled);
|
|
|
|
|
widget->numEdit->setEnabled(enabled);
|
|
|
|
|
widget->denEdit->setEnabled(enabled);
|
|
|
|
|
|
|
|
|
|
label = widget->warningLabel =
|
|
|
|
|
new QLabel{obs_property_description(prop)};
|
|
|
|
|
|
|
|
|
|
layout->addRow(label, widget);
|
|
|
|
|
|
|
|
|
|
children.emplace_back(info);
|
|
|
|
|
|
|
|
|
|
UpdateFPSLabels(widget);
|
|
|
|
|
|
|
|
|
|
auto stack = widget->modeDisplay;
|
|
|
|
|
auto combo = widget->modeSelect;
|
|
|
|
|
|
2016-09-11 10:17:18 +00:00
|
|
|
|
stack->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
|
|
|
|
combo->setToolTip(QT_UTF8(obs_property_long_description(prop)));
|
|
|
|
|
|
2015-08-18 12:57:36 +00:00
|
|
|
|
auto comboIndexChanged = static_cast<void (QComboBox::*)(int)>(
|
|
|
|
|
&QComboBox::currentIndexChanged);
|
|
|
|
|
connect(combo, comboIndexChanged, stack, [=](int index) {
|
|
|
|
|
bool out_of_bounds = index >= stack->count();
|
|
|
|
|
auto idx = out_of_bounds ? stack->count() - 1 : index;
|
|
|
|
|
stack->setCurrentIndex(idx);
|
|
|
|
|
|
|
|
|
|
if (widget->updating)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
UpdateFPSLabels(widget);
|
|
|
|
|
emit info->ControlChanged();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(widget->simpleFPS, comboIndexChanged, [=](int) {
|
|
|
|
|
if (widget->updating)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
emit info->ControlChanged();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(widget->fpsRange, comboIndexChanged, [=](int) {
|
|
|
|
|
if (widget->updating)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
UpdateFPSLabels(widget);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto sbValueChanged =
|
|
|
|
|
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged);
|
|
|
|
|
connect(widget->numEdit, sbValueChanged, [=](int) {
|
|
|
|
|
if (widget->updating)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
emit info->ControlChanged();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(widget->denEdit, sbValueChanged, [=](int) {
|
|
|
|
|
if (widget->updating)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
emit info->ControlChanged();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 16:48:10 +00:00
|
|
|
|
void OBSPropertiesView::AddGroup(obs_property_t *prop, QFormLayout *layout)
|
|
|
|
|
{
|
|
|
|
|
const char *name = obs_property_name(prop);
|
|
|
|
|
bool val = obs_data_get_bool(settings, name);
|
|
|
|
|
const char *desc = obs_property_description(prop);
|
|
|
|
|
enum obs_group_type type = obs_property_group_type(prop);
|
|
|
|
|
|
|
|
|
|
// Create GroupBox
|
|
|
|
|
QGroupBox *groupBox = new QGroupBox(QT_UTF8(desc));
|
|
|
|
|
groupBox->setCheckable(type == OBS_GROUP_CHECKABLE);
|
|
|
|
|
groupBox->setChecked(groupBox->isCheckable() ? val : true);
|
|
|
|
|
groupBox->setAccessibleName("group");
|
|
|
|
|
groupBox->setEnabled(obs_property_enabled(prop));
|
|
|
|
|
|
|
|
|
|
// Create Layout and build content
|
|
|
|
|
QFormLayout *subLayout = new QFormLayout();
|
|
|
|
|
subLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
|
|
|
|
groupBox->setLayout(subLayout);
|
|
|
|
|
|
|
|
|
|
obs_properties_t *content = obs_property_group_content(prop);
|
|
|
|
|
obs_property_t *el = obs_properties_first(content);
|
|
|
|
|
while (el != nullptr) {
|
|
|
|
|
AddProperty(el, subLayout);
|
|
|
|
|
obs_property_next(&el);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Insert into UI
|
|
|
|
|
layout->setWidget(layout->rowCount(),
|
|
|
|
|
QFormLayout::ItemRole::SpanningRole, groupBox);
|
|
|
|
|
|
|
|
|
|
// Register Group Widget
|
|
|
|
|
WidgetInfo *info = new WidgetInfo(this, prop, groupBox);
|
|
|
|
|
children.emplace_back(info);
|
|
|
|
|
|
|
|
|
|
// Signals
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(groupBox, &QGroupBox::toggled, info,
|
|
|
|
|
&WidgetInfo::ControlChanged);
|
2019-02-14 16:48:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 00:44:05 +00:00
|
|
|
|
void OBSPropertiesView::AddProperty(obs_property_t *property,
|
2014-03-23 08:07:54 +00:00
|
|
|
|
QFormLayout *layout)
|
|
|
|
|
{
|
2014-04-24 08:43:54 +00:00
|
|
|
|
const char *name = obs_property_name(property);
|
|
|
|
|
obs_property_type type = obs_property_get_type(property);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
2014-04-04 07:30:37 +00:00
|
|
|
|
if (!obs_property_visible(property))
|
|
|
|
|
return;
|
|
|
|
|
|
2014-06-28 02:55:47 +00:00
|
|
|
|
QLabel *label = nullptr;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
QWidget *widget = nullptr;
|
2014-06-21 20:13:30 +00:00
|
|
|
|
bool warning = false;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case OBS_PROPERTY_INVALID:
|
|
|
|
|
return;
|
|
|
|
|
case OBS_PROPERTY_BOOL:
|
|
|
|
|
widget = AddCheckbox(property);
|
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_INT:
|
2015-03-18 01:34:21 +00:00
|
|
|
|
AddInt(property, layout, &label);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_FLOAT:
|
2015-03-18 01:34:21 +00:00
|
|
|
|
AddFloat(property, layout, &label);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_TEXT:
|
2015-05-25 05:24:26 +00:00
|
|
|
|
widget = AddText(property, layout, label);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_PATH:
|
2014-06-28 02:55:47 +00:00
|
|
|
|
AddPath(property, layout, &label);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_LIST:
|
2014-06-21 20:13:30 +00:00
|
|
|
|
widget = AddList(property, warning);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_COLOR:
|
2014-07-19 19:00:14 +00:00
|
|
|
|
AddColor(property, layout, label);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
break;
|
2014-08-17 12:50:30 +00:00
|
|
|
|
case OBS_PROPERTY_FONT:
|
|
|
|
|
AddFont(property, layout, label);
|
|
|
|
|
break;
|
2014-05-30 09:44:14 +00:00
|
|
|
|
case OBS_PROPERTY_BUTTON:
|
|
|
|
|
widget = AddButton(property);
|
|
|
|
|
break;
|
2015-04-13 18:23:54 +00:00
|
|
|
|
case OBS_PROPERTY_EDITABLE_LIST:
|
|
|
|
|
AddEditableList(property, layout, label);
|
|
|
|
|
break;
|
2015-08-18 12:57:36 +00:00
|
|
|
|
case OBS_PROPERTY_FRAME_RATE:
|
|
|
|
|
AddFrameRate(property, warning, layout, label);
|
|
|
|
|
break;
|
2019-02-14 16:48:10 +00:00
|
|
|
|
case OBS_PROPERTY_GROUP:
|
|
|
|
|
AddGroup(property, layout);
|
2020-12-30 03:51:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_COLOR_ALPHA:
|
|
|
|
|
AddColorAlpha(property, layout, label);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 01:21:22 +00:00
|
|
|
|
if (!widget && !label)
|
|
|
|
|
return;
|
2014-04-04 07:30:37 +00:00
|
|
|
|
|
2014-06-28 02:55:47 +00:00
|
|
|
|
if (!label && type != OBS_PROPERTY_BOOL &&
|
2019-02-14 16:48:10 +00:00
|
|
|
|
type != OBS_PROPERTY_BUTTON && type != OBS_PROPERTY_GROUP)
|
2014-03-23 08:07:54 +00:00
|
|
|
|
label = new QLabel(QT_UTF8(obs_property_description(property)));
|
|
|
|
|
|
2022-01-24 01:21:22 +00:00
|
|
|
|
if (label) {
|
2023-03-04 07:43:09 +00:00
|
|
|
|
if (warning)
|
|
|
|
|
label->setObjectName("errorLabel");
|
2014-06-21 20:13:30 +00:00
|
|
|
|
|
2022-01-24 01:21:22 +00:00
|
|
|
|
if (minSize) {
|
|
|
|
|
label->setMinimumWidth(minSize);
|
|
|
|
|
label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
|
}
|
2014-04-24 08:43:54 +00:00
|
|
|
|
|
2022-01-24 01:21:22 +00:00
|
|
|
|
if (!obs_property_enabled(property))
|
|
|
|
|
label->setEnabled(false);
|
|
|
|
|
}
|
2017-04-01 20:32:26 +00:00
|
|
|
|
|
2014-06-28 02:55:47 +00:00
|
|
|
|
if (!widget)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-01-24 01:21:22 +00:00
|
|
|
|
if (!obs_property_enabled(property))
|
|
|
|
|
widget->setEnabled(false);
|
|
|
|
|
|
2020-03-01 03:29:42 +00:00
|
|
|
|
if (obs_property_long_description(property)) {
|
2022-06-25 04:46:05 +00:00
|
|
|
|
QString file = !App()->IsThemeDark()
|
|
|
|
|
? ":/res/images/help.svg"
|
|
|
|
|
: ":/res/images/help_light.svg";
|
2020-03-01 03:29:42 +00:00
|
|
|
|
if (label) {
|
2020-07-21 12:26:25 +00:00
|
|
|
|
QString lStr = "<html>%1 <img src='%2' style=' \
|
|
|
|
|
vertical-align: bottom; \
|
|
|
|
|
' /></html>";
|
|
|
|
|
|
2020-03-01 03:29:42 +00:00
|
|
|
|
label->setText(lStr.arg(label->text(), file));
|
|
|
|
|
label->setToolTip(
|
|
|
|
|
obs_property_long_description(property));
|
|
|
|
|
} else if (type == OBS_PROPERTY_BOOL) {
|
2020-07-21 12:26:25 +00:00
|
|
|
|
|
|
|
|
|
QString bStr = "<html> <img src='%1' style=' \
|
|
|
|
|
vertical-align: bottom; \
|
|
|
|
|
' /></html>";
|
|
|
|
|
|
|
|
|
|
const char *desc = obs_property_description(property);
|
|
|
|
|
|
2020-03-01 03:29:42 +00:00
|
|
|
|
QWidget *newWidget = new QWidget();
|
2020-07-21 12:26:25 +00:00
|
|
|
|
|
2020-03-01 03:29:42 +00:00
|
|
|
|
QHBoxLayout *boxLayout = new QHBoxLayout(newWidget);
|
|
|
|
|
boxLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
boxLayout->setAlignment(Qt::AlignLeft);
|
2023-10-25 18:43:55 +00:00
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
/* TODO: This fixes the issue of tooltip not aligning
|
|
|
|
|
* correcty on macOS, the root cause needs further
|
|
|
|
|
* investigation. */
|
|
|
|
|
boxLayout->setSpacing(10);
|
|
|
|
|
#else
|
2020-07-21 12:26:25 +00:00
|
|
|
|
boxLayout->setSpacing(0);
|
2023-10-25 18:43:55 +00:00
|
|
|
|
#endif
|
2020-03-01 03:29:42 +00:00
|
|
|
|
QCheckBox *check = qobject_cast<QCheckBox *>(widget);
|
2020-07-21 12:26:25 +00:00
|
|
|
|
check->setText(desc);
|
|
|
|
|
check->setToolTip(
|
|
|
|
|
obs_property_long_description(property));
|
|
|
|
|
|
|
|
|
|
QLabel *help = new QLabel(check);
|
|
|
|
|
help->setText(bStr.arg(file));
|
2020-03-01 03:29:42 +00:00
|
|
|
|
help->setToolTip(
|
|
|
|
|
obs_property_long_description(property));
|
2020-07-21 12:26:25 +00:00
|
|
|
|
|
2020-03-01 03:29:42 +00:00
|
|
|
|
boxLayout->addWidget(check);
|
|
|
|
|
boxLayout->addWidget(help);
|
|
|
|
|
widget = newWidget;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 08:07:54 +00:00
|
|
|
|
layout->addRow(label, widget);
|
2014-04-24 08:43:54 +00:00
|
|
|
|
|
|
|
|
|
if (!lastFocused.empty())
|
|
|
|
|
if (lastFocused.compare(name) == 0)
|
|
|
|
|
lastWidget = widget;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 04:53:37 +00:00
|
|
|
|
void OBSPropertiesView::SignalChanged()
|
|
|
|
|
{
|
|
|
|
|
emit Changed();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 12:57:36 +00:00
|
|
|
|
static bool FrameRateChangedVariant(const QVariant &variant,
|
|
|
|
|
media_frames_per_second &fps,
|
|
|
|
|
obs_data_item_t *&obj,
|
|
|
|
|
const media_frames_per_second *valid_fps)
|
|
|
|
|
{
|
|
|
|
|
if (!variant.canConvert<media_frames_per_second>())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
fps = variant.value<media_frames_per_second>();
|
|
|
|
|
if (valid_fps && fps == *valid_fps)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
obs_data_item_set_frames_per_second(&obj, fps, nullptr);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool FrameRateChangedCommon(OBSFrameRatePropertyWidget *w,
|
|
|
|
|
obs_data_item_t *&obj,
|
|
|
|
|
const media_frames_per_second *valid_fps)
|
|
|
|
|
{
|
|
|
|
|
media_frames_per_second fps{};
|
|
|
|
|
if (!FrameRateChangedVariant(w->simpleFPS->currentData(), fps, obj,
|
|
|
|
|
valid_fps))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
UpdateRationalFPSWidgets(w, &fps);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool FrameRateChangedRational(OBSFrameRatePropertyWidget *w,
|
|
|
|
|
obs_data_item_t *&obj,
|
|
|
|
|
const media_frames_per_second *valid_fps)
|
|
|
|
|
{
|
|
|
|
|
auto num = w->numEdit->value();
|
|
|
|
|
auto den = w->denEdit->value();
|
|
|
|
|
|
|
|
|
|
auto fps = make_fps(num, den);
|
|
|
|
|
if (valid_fps && media_frames_per_second_is_valid(fps) &&
|
|
|
|
|
fps == *valid_fps)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
obs_data_item_set_frames_per_second(&obj, fps, nullptr);
|
|
|
|
|
UpdateSimpleFPSSelection(w, &fps);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool FrameRateChanged(QWidget *widget, const char *name,
|
|
|
|
|
OBSData &settings)
|
|
|
|
|
{
|
|
|
|
|
auto w = qobject_cast<OBSFrameRatePropertyWidget *>(widget);
|
|
|
|
|
if (!w)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
auto variant = w->modeSelect->currentData();
|
|
|
|
|
if (!variant.canConvert<frame_rate_tag>())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
auto StopUpdating = [&](void *) {
|
|
|
|
|
w->updating = false;
|
|
|
|
|
};
|
|
|
|
|
unique_ptr<void, decltype(StopUpdating)> signalGuard(
|
|
|
|
|
static_cast<void *>(w), StopUpdating);
|
|
|
|
|
w->updating = true;
|
|
|
|
|
|
|
|
|
|
if (!obs_data_has_user_value(settings, name))
|
|
|
|
|
obs_data_set_obj(settings, name, nullptr);
|
|
|
|
|
|
|
|
|
|
unique_ptr<obs_data_item_t> obj{obs_data_item_byname(settings, name)};
|
|
|
|
|
auto obj_ptr = obj.get();
|
|
|
|
|
auto CheckObj = [&]() {
|
|
|
|
|
if (!obj_ptr)
|
|
|
|
|
obj.release();
|
|
|
|
|
};
|
2019-06-23 05:13:45 +00:00
|
|
|
|
|
2015-08-18 12:57:36 +00:00
|
|
|
|
const char *option = nullptr;
|
|
|
|
|
obs_data_item_get_frames_per_second(obj.get(), nullptr, &option);
|
|
|
|
|
|
|
|
|
|
media_frames_per_second fps{};
|
|
|
|
|
media_frames_per_second *valid_fps = nullptr;
|
|
|
|
|
if (obs_data_item_get_frames_per_second(obj.get(), &fps, nullptr))
|
|
|
|
|
valid_fps = &fps;
|
|
|
|
|
|
|
|
|
|
auto tag = variant.value<frame_rate_tag>();
|
|
|
|
|
switch (tag.type) {
|
|
|
|
|
case frame_rate_tag::SIMPLE:
|
|
|
|
|
if (!FrameRateChangedCommon(w, obj_ptr, valid_fps))
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case frame_rate_tag::RATIONAL:
|
|
|
|
|
if (!FrameRateChangedRational(w, obj_ptr, valid_fps))
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case frame_rate_tag::USER:
|
|
|
|
|
if (tag.val && option && strcmp(tag.val, option) == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
obs_data_item_set_frames_per_second(&obj_ptr, {}, tag.val);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateFPSLabels(w);
|
|
|
|
|
CheckObj();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 08:07:54 +00:00
|
|
|
|
void WidgetInfo::BoolChanged(const char *setting)
|
|
|
|
|
{
|
|
|
|
|
QCheckBox *checkbox = static_cast<QCheckBox *>(widget);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_bool(view->settings, setting,
|
2014-03-23 08:07:54 +00:00
|
|
|
|
checkbox->checkState() == Qt::Checked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::IntChanged(const char *setting)
|
|
|
|
|
{
|
|
|
|
|
QSpinBox *spin = static_cast<QSpinBox *>(widget);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_int(view->settings, setting, spin->value());
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::FloatChanged(const char *setting)
|
|
|
|
|
{
|
|
|
|
|
QDoubleSpinBox *spin = static_cast<QDoubleSpinBox *>(widget);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_double(view->settings, setting, spin->value());
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::TextChanged(const char *setting)
|
|
|
|
|
{
|
2018-02-22 03:22:53 +00:00
|
|
|
|
obs_text_type type = obs_property_text_type(property);
|
2014-07-19 19:31:46 +00:00
|
|
|
|
|
|
|
|
|
if (type == OBS_TEXT_MULTILINE) {
|
2022-08-06 05:03:28 +00:00
|
|
|
|
OBSPlainTextEdit *edit =
|
|
|
|
|
static_cast<OBSPlainTextEdit *>(widget);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_string(view->settings, setting,
|
2014-07-19 19:31:46 +00:00
|
|
|
|
QT_TO_UTF8(edit->toPlainText()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 08:07:54 +00:00
|
|
|
|
QLineEdit *edit = static_cast<QLineEdit *>(widget);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_string(view->settings, setting, QT_TO_UTF8(edit->text()));
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 02:55:47 +00:00
|
|
|
|
bool WidgetInfo::PathChanged(const char *setting)
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2014-06-28 02:55:47 +00:00
|
|
|
|
const char *desc = obs_property_description(property);
|
|
|
|
|
obs_path_type type = obs_property_path_type(property);
|
|
|
|
|
const char *filter = obs_property_path_filter(property);
|
|
|
|
|
const char *default_path = obs_property_path_default_path(property);
|
2024-04-06 00:56:17 +00:00
|
|
|
|
|
|
|
|
|
QLineEdit *edit = static_cast<QLineEdit *>(widget);
|
|
|
|
|
|
|
|
|
|
QString startDir = edit->text();
|
|
|
|
|
if (startDir.isEmpty())
|
|
|
|
|
startDir = default_path;
|
|
|
|
|
|
2014-06-28 02:55:47 +00:00
|
|
|
|
QString path;
|
|
|
|
|
|
|
|
|
|
if (type == OBS_PATH_DIRECTORY)
|
2024-04-06 00:56:17 +00:00
|
|
|
|
path = SelectDirectory(view, QT_UTF8(desc), startDir);
|
2014-06-28 02:55:47 +00:00
|
|
|
|
else if (type == OBS_PATH_FILE)
|
2024-04-06 00:56:17 +00:00
|
|
|
|
path = OpenFile(view, QT_UTF8(desc), startDir, QT_UTF8(filter));
|
2016-01-31 17:37:16 +00:00
|
|
|
|
else if (type == OBS_PATH_FILE_SAVE)
|
2024-04-06 00:56:17 +00:00
|
|
|
|
path = SaveFile(view, QT_UTF8(desc), startDir, QT_UTF8(filter));
|
2014-06-28 02:55:47 +00:00
|
|
|
|
|
2023-01-22 01:20:42 +00:00
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
// TODO: Revisit when QTBUG-42661 is fixed
|
|
|
|
|
widget->window()->raise();
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-06-28 02:55:47 +00:00
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
edit->setText(path);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_string(view->settings, setting, QT_TO_UTF8(path));
|
2014-06-28 02:55:47 +00:00
|
|
|
|
return true;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::ListChanged(const char *setting)
|
|
|
|
|
{
|
|
|
|
|
obs_combo_format format = obs_property_list_format(property);
|
|
|
|
|
obs_combo_type type = obs_property_list_type(property);
|
2014-04-04 07:30:37 +00:00
|
|
|
|
QVariant data;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
|
2022-11-20 01:32:05 +00:00
|
|
|
|
if (type == OBS_COMBO_TYPE_RADIO) {
|
|
|
|
|
QButtonGroup *group =
|
|
|
|
|
static_cast<QAbstractButton *>(widget)->group();
|
|
|
|
|
QAbstractButton *button = group->checkedButton();
|
|
|
|
|
data = button->property("value");
|
|
|
|
|
} else if (type == OBS_COMBO_TYPE_EDITABLE) {
|
|
|
|
|
data = static_cast<QComboBox *>(widget)->currentText().toUtf8();
|
2014-03-23 08:07:54 +00:00
|
|
|
|
} else {
|
2022-11-20 01:32:05 +00:00
|
|
|
|
QComboBox *combo = static_cast<QComboBox *>(widget);
|
2014-03-23 08:07:54 +00:00
|
|
|
|
int index = combo->currentIndex();
|
2014-04-04 07:30:37 +00:00
|
|
|
|
if (index != -1)
|
|
|
|
|
data = combo->itemData(index);
|
|
|
|
|
else
|
|
|
|
|
return;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
|
case OBS_COMBO_FORMAT_INVALID:
|
|
|
|
|
return;
|
|
|
|
|
case OBS_COMBO_FORMAT_INT:
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_int(view->settings, setting,
|
2014-04-04 07:30:37 +00:00
|
|
|
|
data.value<long long>());
|
2014-03-23 08:07:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case OBS_COMBO_FORMAT_FLOAT:
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_double(view->settings, setting,
|
2014-04-04 07:30:37 +00:00
|
|
|
|
data.value<double>());
|
2014-03-23 08:07:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case OBS_COMBO_FORMAT_STRING:
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_string(view->settings, setting,
|
2016-06-05 20:36:49 +00:00
|
|
|
|
data.toByteArray().constData());
|
2014-03-23 08:07:54 +00:00
|
|
|
|
break;
|
2022-12-01 11:36:58 +00:00
|
|
|
|
case OBS_COMBO_FORMAT_BOOL:
|
|
|
|
|
obs_data_set_bool(view->settings, setting,
|
|
|
|
|
data.value<double>());
|
|
|
|
|
break;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-30 03:51:40 +00:00
|
|
|
|
bool WidgetInfo::ColorChangedInternal(const char *setting, bool supportAlpha)
|
2014-03-23 08:07:54 +00:00
|
|
|
|
{
|
2014-07-19 19:00:14 +00:00
|
|
|
|
const char *desc = obs_property_description(property);
|
2014-08-05 18:09:29 +00:00
|
|
|
|
long long val = obs_data_get_int(view->settings, setting);
|
2014-07-19 19:00:14 +00:00
|
|
|
|
QColor color = color_from_int(val);
|
2020-12-30 03:51:40 +00:00
|
|
|
|
QColor::NameFormat format;
|
2014-07-19 19:00:14 +00:00
|
|
|
|
|
2020-06-07 22:31:13 +00:00
|
|
|
|
QColorDialog::ColorDialogOptions options;
|
2014-07-19 19:00:14 +00:00
|
|
|
|
|
2020-12-30 03:51:40 +00:00
|
|
|
|
if (supportAlpha) {
|
|
|
|
|
options |= QColorDialog::ShowAlphaChannel;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 14:11:59 +00:00
|
|
|
|
#ifdef __linux__
|
|
|
|
|
// TODO: Revisit hang on Ubuntu with native dialog
|
2014-07-19 19:00:14 +00:00
|
|
|
|
options |= QColorDialog::DontUseNativeDialog;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
color = QColorDialog::getColor(color, view, QT_UTF8(desc), options);
|
2023-01-25 14:11:59 +00:00
|
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
// TODO: Revisit when QTBUG-42661 is fixed
|
|
|
|
|
widget->window()->raise();
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-07-19 19:00:14 +00:00
|
|
|
|
if (!color.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-12-30 03:51:40 +00:00
|
|
|
|
if (supportAlpha) {
|
|
|
|
|
format = QColor::HexArgb;
|
|
|
|
|
} else {
|
|
|
|
|
color.setAlpha(255);
|
|
|
|
|
format = QColor::HexRgb;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-19 19:00:14 +00:00
|
|
|
|
QLabel *label = static_cast<QLabel *>(widget);
|
2020-12-30 03:51:40 +00:00
|
|
|
|
label->setText(color.name(format));
|
2018-05-23 16:50:41 +00:00
|
|
|
|
QPalette palette = QPalette(color);
|
|
|
|
|
label->setPalette(palette);
|
2020-12-30 03:51:40 +00:00
|
|
|
|
label->setStyleSheet(
|
|
|
|
|
QString("background-color :%1; color: %2;")
|
|
|
|
|
.arg(palette.color(QPalette::Window).name(format))
|
|
|
|
|
.arg(palette.color(QPalette::WindowText).name(format)));
|
2014-07-19 19:00:14 +00:00
|
|
|
|
|
2014-08-05 18:09:29 +00:00
|
|
|
|
obs_data_set_int(view->settings, setting, color_to_int(color));
|
2014-07-19 19:00:14 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-30 03:51:40 +00:00
|
|
|
|
bool WidgetInfo::ColorChanged(const char *setting)
|
|
|
|
|
{
|
|
|
|
|
return ColorChangedInternal(setting, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WidgetInfo::ColorAlphaChanged(const char *setting)
|
|
|
|
|
{
|
|
|
|
|
return ColorChangedInternal(setting, true);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 12:50:30 +00:00
|
|
|
|
bool WidgetInfo::FontChanged(const char *setting)
|
|
|
|
|
{
|
2021-11-26 09:25:39 +00:00
|
|
|
|
OBSDataAutoRelease font_obj = obs_data_get_obj(view->settings, setting);
|
2014-08-17 12:50:30 +00:00
|
|
|
|
bool success;
|
|
|
|
|
uint32_t flags;
|
|
|
|
|
QFont font;
|
|
|
|
|
|
2018-08-23 02:23:00 +00:00
|
|
|
|
QFontDialog::FontDialogOptions options;
|
|
|
|
|
|
2020-03-28 12:15:25 +00:00
|
|
|
|
#ifndef _WIN32
|
2018-08-23 02:23:00 +00:00
|
|
|
|
options = QFontDialog::DontUseNativeDialog;
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-08-17 12:50:30 +00:00
|
|
|
|
if (!font_obj) {
|
2018-08-23 02:23:00 +00:00
|
|
|
|
QFont initial;
|
2023-07-12 09:57:42 +00:00
|
|
|
|
font = QFontDialog::getFont(
|
|
|
|
|
&success, initial, view,
|
|
|
|
|
QTStr("Basic.PropertiesWindow.SelectFont.WindowTitle"),
|
|
|
|
|
options);
|
2014-08-17 12:50:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
MakeQFont(font_obj, font);
|
2023-07-12 09:57:42 +00:00
|
|
|
|
font = QFontDialog::getFont(
|
|
|
|
|
&success, font, view,
|
|
|
|
|
QTStr("Basic.PropertiesWindow.SelectFont.WindowTitle"),
|
|
|
|
|
options);
|
2014-08-17 12:50:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-22 22:48:19 +00:00
|
|
|
|
if (!success)
|
2014-08-17 12:50:30 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2014-08-22 22:48:19 +00:00
|
|
|
|
font_obj = obs_data_create();
|
2014-08-17 12:50:30 +00:00
|
|
|
|
|
|
|
|
|
obs_data_set_string(font_obj, "face", QT_TO_UTF8(font.family()));
|
|
|
|
|
obs_data_set_string(font_obj, "style", QT_TO_UTF8(font.styleName()));
|
|
|
|
|
obs_data_set_int(font_obj, "size", font.pointSize());
|
|
|
|
|
flags = font.bold() ? OBS_FONT_BOLD : 0;
|
|
|
|
|
flags |= font.italic() ? OBS_FONT_ITALIC : 0;
|
|
|
|
|
flags |= font.underline() ? OBS_FONT_UNDERLINE : 0;
|
|
|
|
|
flags |= font.strikeOut() ? OBS_FONT_STRIKEOUT : 0;
|
|
|
|
|
obs_data_set_int(font_obj, "flags", flags);
|
|
|
|
|
|
|
|
|
|
QLabel *label = static_cast<QLabel *>(widget);
|
2016-09-13 21:42:13 +00:00
|
|
|
|
QFont labelFont;
|
|
|
|
|
MakeQFont(font_obj, labelFont, true);
|
|
|
|
|
label->setFont(labelFont);
|
2014-08-17 12:50:30 +00:00
|
|
|
|
label->setText(QString("%1 %2").arg(font.family(), font.styleName()));
|
|
|
|
|
|
2014-08-22 22:48:19 +00:00
|
|
|
|
obs_data_set_obj(view->settings, setting, font_obj);
|
2014-08-17 12:50:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 16:48:10 +00:00
|
|
|
|
void WidgetInfo::GroupChanged(const char *setting)
|
|
|
|
|
{
|
|
|
|
|
QGroupBox *groupbox = static_cast<QGroupBox *>(widget);
|
|
|
|
|
obs_data_set_bool(view->settings, setting,
|
|
|
|
|
groupbox->isCheckable() ? groupbox->isChecked()
|
|
|
|
|
: true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-13 18:23:54 +00:00
|
|
|
|
void WidgetInfo::EditableListChanged()
|
|
|
|
|
{
|
|
|
|
|
const char *setting = obs_property_name(property);
|
|
|
|
|
QListWidget *list = reinterpret_cast<QListWidget *>(widget);
|
2021-11-26 09:25:39 +00:00
|
|
|
|
OBSDataArrayAutoRelease array = obs_data_array_create();
|
2015-04-13 18:23:54 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < list->count(); i++) {
|
|
|
|
|
QListWidgetItem *item = list->item(i);
|
2021-11-26 09:25:39 +00:00
|
|
|
|
OBSDataAutoRelease arrayItem = obs_data_create();
|
2015-04-13 18:23:54 +00:00
|
|
|
|
obs_data_set_string(arrayItem, "value",
|
|
|
|
|
QT_TO_UTF8(item->text()));
|
2018-02-14 18:58:43 +00:00
|
|
|
|
obs_data_set_bool(arrayItem, "selected", item->isSelected());
|
|
|
|
|
obs_data_set_bool(arrayItem, "hidden", item->isHidden());
|
2015-04-13 18:23:54 +00:00
|
|
|
|
obs_data_array_push_back(array, arrayItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
obs_data_set_array(view->settings, setting, array);
|
2016-05-23 13:56:41 +00:00
|
|
|
|
|
|
|
|
|
ControlChanged();
|
2015-04-13 18:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-30 09:44:14 +00:00
|
|
|
|
void WidgetInfo::ButtonClicked()
|
|
|
|
|
{
|
2020-10-14 01:58:41 +00:00
|
|
|
|
obs_button_type type = obs_property_button_type(property);
|
|
|
|
|
const char *savedUrl = obs_property_button_url(property);
|
|
|
|
|
|
|
|
|
|
if (type == OBS_BUTTON_URL && strcmp(savedUrl, "") != 0) {
|
|
|
|
|
QUrl url(savedUrl, QUrl::StrictMode);
|
|
|
|
|
if (url.isValid() && (url.scheme().compare("http") == 0 ||
|
|
|
|
|
url.scheme().compare("https") == 0)) {
|
|
|
|
|
QString msg(
|
|
|
|
|
QTStr("Basic.PropertiesView.UrlButton.Text"));
|
|
|
|
|
msg += "\n\n";
|
|
|
|
|
msg += QString(QTStr("Basic.PropertiesView.UrlButton.Text.Url"))
|
|
|
|
|
.arg(savedUrl);
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton button = OBSMessageBox::question(
|
|
|
|
|
view->window(),
|
|
|
|
|
QTStr("Basic.PropertiesView.UrlButton.OpenUrl"),
|
|
|
|
|
msg, QMessageBox::Yes | QMessageBox::No,
|
|
|
|
|
QMessageBox::No);
|
|
|
|
|
|
|
|
|
|
if (button == QMessageBox::Yes)
|
|
|
|
|
QDesktopServices::openUrl(url);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-15 10:12:07 +00:00
|
|
|
|
|
|
|
|
|
OBSObject strongObj = view->GetObject();
|
|
|
|
|
void *obj = strongObj ? strongObj.Get() : view->rawObj;
|
|
|
|
|
if (obs_property_button_clicked(property, obj)) {
|
|
|
|
|
QMetaObject::invokeMethod(view, "RefreshProperties",
|
|
|
|
|
Qt::QueuedConnection);
|
2015-01-04 04:49:26 +00:00
|
|
|
|
}
|
2014-05-30 09:44:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-25 05:24:26 +00:00
|
|
|
|
void WidgetInfo::TogglePasswordText(bool show)
|
|
|
|
|
{
|
|
|
|
|
reinterpret_cast<QLineEdit *>(widget)->setEchoMode(
|
|
|
|
|
show ? QLineEdit::Normal : QLineEdit::Password);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 08:07:54 +00:00
|
|
|
|
void WidgetInfo::ControlChanged()
|
|
|
|
|
{
|
|
|
|
|
const char *setting = obs_property_name(property);
|
|
|
|
|
obs_property_type type = obs_property_get_type(property);
|
|
|
|
|
|
2021-03-22 05:47:19 +00:00
|
|
|
|
if (!recently_updated) {
|
|
|
|
|
old_settings_cache = obs_data_create();
|
|
|
|
|
obs_data_apply(old_settings_cache, view->settings);
|
|
|
|
|
obs_data_release(old_settings_cache);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 08:07:54 +00:00
|
|
|
|
switch (type) {
|
|
|
|
|
case OBS_PROPERTY_INVALID:
|
|
|
|
|
return;
|
|
|
|
|
case OBS_PROPERTY_BOOL:
|
|
|
|
|
BoolChanged(setting);
|
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_INT:
|
|
|
|
|
IntChanged(setting);
|
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_FLOAT:
|
|
|
|
|
FloatChanged(setting);
|
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_TEXT:
|
|
|
|
|
TextChanged(setting);
|
|
|
|
|
break;
|
|
|
|
|
case OBS_PROPERTY_LIST:
|
|
|
|
|
ListChanged(setting);
|
|
|
|
|
break;
|
2014-05-30 09:44:14 +00:00
|
|
|
|
case OBS_PROPERTY_BUTTON:
|
|
|
|
|
ButtonClicked();
|
|
|
|
|
return;
|
2014-07-19 19:00:14 +00:00
|
|
|
|
case OBS_PROPERTY_COLOR:
|
|
|
|
|
if (!ColorChanged(setting))
|
|
|
|
|
return;
|
|
|
|
|
break;
|
2014-08-17 12:50:30 +00:00
|
|
|
|
case OBS_PROPERTY_FONT:
|
|
|
|
|
if (!FontChanged(setting))
|
|
|
|
|
return;
|
|
|
|
|
break;
|
2014-06-28 02:55:47 +00:00
|
|
|
|
case OBS_PROPERTY_PATH:
|
|
|
|
|
if (!PathChanged(setting))
|
|
|
|
|
return;
|
2015-06-21 10:54:00 +00:00
|
|
|
|
break;
|
2016-05-23 13:56:41 +00:00
|
|
|
|
case OBS_PROPERTY_EDITABLE_LIST:
|
|
|
|
|
break;
|
2015-08-18 12:57:36 +00:00
|
|
|
|
case OBS_PROPERTY_FRAME_RATE:
|
|
|
|
|
if (!FrameRateChanged(widget, setting, view->settings))
|
|
|
|
|
return;
|
|
|
|
|
break;
|
2019-02-14 16:48:10 +00:00
|
|
|
|
case OBS_PROPERTY_GROUP:
|
|
|
|
|
GroupChanged(setting);
|
2019-10-16 05:25:50 +00:00
|
|
|
|
break;
|
2020-12-30 03:51:40 +00:00
|
|
|
|
case OBS_PROPERTY_COLOR_ALPHA:
|
|
|
|
|
if (!ColorAlphaChanged(setting))
|
|
|
|
|
return;
|
|
|
|
|
break;
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 05:47:19 +00:00
|
|
|
|
if (!recently_updated) {
|
|
|
|
|
recently_updated = true;
|
|
|
|
|
update_timer = new QTimer;
|
|
|
|
|
connect(update_timer, &QTimer::timeout,
|
|
|
|
|
[this, &ru = recently_updated]() {
|
2022-02-08 19:07:23 +00:00
|
|
|
|
OBSObject strongObj = view->GetObject();
|
|
|
|
|
void *obj = strongObj ? strongObj.Get()
|
|
|
|
|
: view->rawObj;
|
2022-02-03 06:01:08 +00:00
|
|
|
|
if (obj && view->callback &&
|
|
|
|
|
!view->deferUpdate) {
|
|
|
|
|
view->callback(obj, old_settings_cache,
|
2021-03-22 05:47:19 +00:00
|
|
|
|
view->settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ru = false;
|
|
|
|
|
});
|
|
|
|
|
connect(update_timer, &QTimer::timeout, &QTimer::deleteLater);
|
|
|
|
|
update_timer->setSingleShot(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (update_timer) {
|
|
|
|
|
update_timer->stop();
|
|
|
|
|
update_timer->start(500);
|
|
|
|
|
} else {
|
|
|
|
|
blog(LOG_DEBUG, "No update timer or no callback!");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 17:14:32 +00:00
|
|
|
|
if (view->visUpdateCb && !view->deferUpdate) {
|
2022-02-08 19:07:23 +00:00
|
|
|
|
OBSObject strongObj = view->GetObject();
|
|
|
|
|
void *obj = strongObj ? strongObj.Get() : view->rawObj;
|
2022-02-03 06:01:08 +00:00
|
|
|
|
if (obj)
|
2022-03-09 17:14:32 +00:00
|
|
|
|
view->visUpdateCb(obj, view->settings);
|
2022-02-03 06:01:08 +00:00
|
|
|
|
}
|
2015-02-04 04:50:37 +00:00
|
|
|
|
|
2015-02-04 04:53:37 +00:00
|
|
|
|
view->SignalChanged();
|
|
|
|
|
|
2014-04-24 08:43:54 +00:00
|
|
|
|
if (obs_property_modified(property, view->settings)) {
|
|
|
|
|
view->lastFocused = setting;
|
|
|
|
|
QMetaObject::invokeMethod(view, "RefreshProperties",
|
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
|
}
|
2014-03-23 08:07:54 +00:00
|
|
|
|
}
|
2015-04-13 18:23:54 +00:00
|
|
|
|
|
|
|
|
|
class EditableItemDialog : public QDialog {
|
|
|
|
|
QLineEdit *edit;
|
|
|
|
|
QString filter;
|
|
|
|
|
QString default_path;
|
|
|
|
|
|
|
|
|
|
void BrowseClicked()
|
|
|
|
|
{
|
|
|
|
|
QString curPath = QFileInfo(edit->text()).absoluteDir().path();
|
|
|
|
|
|
|
|
|
|
if (curPath.isEmpty())
|
|
|
|
|
curPath = default_path;
|
|
|
|
|
|
2020-07-17 11:32:38 +00:00
|
|
|
|
QString path = OpenFile(App()->GetMainWindow(), QTStr("Browse"),
|
|
|
|
|
curPath, filter);
|
2015-04-13 18:23:54 +00:00
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
edit->setText(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
EditableItemDialog(QWidget *parent, const QString &text, bool browse,
|
|
|
|
|
const char *filter_ = nullptr,
|
|
|
|
|
const char *default_path_ = nullptr)
|
|
|
|
|
: QDialog(parent),
|
|
|
|
|
filter(QT_UTF8(filter_)),
|
|
|
|
|
default_path(QT_UTF8(default_path_))
|
|
|
|
|
{
|
|
|
|
|
QHBoxLayout *topLayout = new QHBoxLayout();
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
edit = new QLineEdit();
|
|
|
|
|
edit->setText(text);
|
|
|
|
|
topLayout->addWidget(edit);
|
|
|
|
|
topLayout->setAlignment(edit, Qt::AlignVCenter);
|
|
|
|
|
|
|
|
|
|
if (browse) {
|
|
|
|
|
QPushButton *browseButton =
|
|
|
|
|
new QPushButton(QTStr("Browse"));
|
2017-06-13 19:34:05 +00:00
|
|
|
|
browseButton->setProperty("themeID", "settingsButtons");
|
2015-04-13 18:23:54 +00:00
|
|
|
|
topLayout->addWidget(browseButton);
|
|
|
|
|
topLayout->setAlignment(browseButton, Qt::AlignVCenter);
|
|
|
|
|
|
|
|
|
|
connect(browseButton, &QPushButton::clicked, this,
|
|
|
|
|
&EditableItemDialog::BrowseClicked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButtons buttons =
|
|
|
|
|
QDialogButtonBox::Ok | QDialogButtonBox::Cancel;
|
|
|
|
|
|
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(buttons);
|
|
|
|
|
buttonBox->setCenterButtons(true);
|
|
|
|
|
|
|
|
|
|
mainLayout->addLayout(topLayout);
|
|
|
|
|
mainLayout->addWidget(buttonBox);
|
|
|
|
|
|
|
|
|
|
setLayout(mainLayout);
|
|
|
|
|
resize(QSize(400, 80));
|
|
|
|
|
|
2023-03-15 02:01:52 +00:00
|
|
|
|
connect(buttonBox, &QDialogButtonBox::accepted, this,
|
|
|
|
|
&EditableItemDialog::accept);
|
|
|
|
|
connect(buttonBox, &QDialogButtonBox::rejected, this,
|
|
|
|
|
&EditableItemDialog::reject);
|
2015-04-13 18:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline QString GetText() const { return edit->text(); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::EditListAdd()
|
|
|
|
|
{
|
2016-05-26 17:48:07 +00:00
|
|
|
|
enum obs_editable_list_type type =
|
|
|
|
|
obs_property_editable_list_type(property);
|
|
|
|
|
|
|
|
|
|
if (type == OBS_EDITABLE_LIST_TYPE_STRINGS) {
|
2015-04-13 18:23:54 +00:00
|
|
|
|
EditListAddText();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-26 17:48:07 +00:00
|
|
|
|
/* Files and URLs */
|
2015-04-13 18:23:54 +00:00
|
|
|
|
QMenu popup(view->window());
|
|
|
|
|
|
|
|
|
|
QAction *action;
|
|
|
|
|
|
|
|
|
|
action = new QAction(QTStr("Basic.PropertiesWindow.AddFiles"), this);
|
|
|
|
|
connect(action, &QAction::triggered, this,
|
|
|
|
|
&WidgetInfo::EditListAddFiles);
|
|
|
|
|
popup.addAction(action);
|
|
|
|
|
|
2016-06-15 23:19:25 +00:00
|
|
|
|
action = new QAction(QTStr("Basic.PropertiesWindow.AddDir"), this);
|
2015-04-13 18:23:54 +00:00
|
|
|
|
connect(action, &QAction::triggered, this, &WidgetInfo::EditListAddDir);
|
|
|
|
|
popup.addAction(action);
|
|
|
|
|
|
2016-06-15 23:19:25 +00:00
|
|
|
|
if (type == OBS_EDITABLE_LIST_TYPE_FILES_AND_URLS) {
|
|
|
|
|
action = new QAction(QTStr("Basic.PropertiesWindow.AddURL"),
|
|
|
|
|
this);
|
|
|
|
|
connect(action, &QAction::triggered, this,
|
|
|
|
|
&WidgetInfo::EditListAddText);
|
|
|
|
|
popup.addAction(action);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-13 18:23:54 +00:00
|
|
|
|
popup.exec(QCursor::pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::EditListAddText()
|
|
|
|
|
{
|
|
|
|
|
QListWidget *list = reinterpret_cast<QListWidget *>(widget);
|
|
|
|
|
const char *desc = obs_property_description(property);
|
|
|
|
|
|
|
|
|
|
EditableItemDialog dialog(widget->window(), QString(), false);
|
|
|
|
|
auto title = QTStr("Basic.PropertiesWindow.AddEditableListEntry")
|
|
|
|
|
.arg(QT_UTF8(desc));
|
|
|
|
|
dialog.setWindowTitle(title);
|
|
|
|
|
if (dialog.exec() == QDialog::Rejected)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString text = dialog.GetText();
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
list->addItem(text);
|
|
|
|
|
EditableListChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::EditListAddFiles()
|
|
|
|
|
{
|
|
|
|
|
QListWidget *list = reinterpret_cast<QListWidget *>(widget);
|
|
|
|
|
const char *desc = obs_property_description(property);
|
|
|
|
|
const char *filter = obs_property_editable_list_filter(property);
|
|
|
|
|
const char *default_path =
|
|
|
|
|
obs_property_editable_list_default_path(property);
|
|
|
|
|
|
|
|
|
|
QString title = QTStr("Basic.PropertiesWindow.AddEditableListFiles")
|
|
|
|
|
.arg(QT_UTF8(desc));
|
|
|
|
|
|
2020-07-17 11:32:38 +00:00
|
|
|
|
QStringList files = OpenFiles(App()->GetMainWindow(), title,
|
|
|
|
|
QT_UTF8(default_path), QT_UTF8(filter));
|
2023-01-22 01:20:42 +00:00
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
// TODO: Revisit when QTBUG-42661 is fixed
|
|
|
|
|
widget->window()->raise();
|
|
|
|
|
#endif
|
2015-04-13 18:23:54 +00:00
|
|
|
|
|
|
|
|
|
if (files.count() == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
list->addItems(files);
|
|
|
|
|
EditableListChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 23:19:25 +00:00
|
|
|
|
void WidgetInfo::EditListAddDir()
|
|
|
|
|
{
|
|
|
|
|
QListWidget *list = reinterpret_cast<QListWidget *>(widget);
|
|
|
|
|
const char *desc = obs_property_description(property);
|
|
|
|
|
const char *default_path =
|
|
|
|
|
obs_property_editable_list_default_path(property);
|
|
|
|
|
|
|
|
|
|
QString title = QTStr("Basic.PropertiesWindow.AddEditableListDir")
|
|
|
|
|
.arg(QT_UTF8(desc));
|
|
|
|
|
|
2020-07-17 11:32:38 +00:00
|
|
|
|
QString dir = SelectDirectory(App()->GetMainWindow(), title,
|
|
|
|
|
QT_UTF8(default_path));
|
2023-01-22 01:20:42 +00:00
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
// TODO: Revisit when QTBUG-42661 is fixed
|
|
|
|
|
widget->window()->raise();
|
|
|
|
|
#endif
|
2016-06-15 23:19:25 +00:00
|
|
|
|
|
|
|
|
|
if (dir.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
list->addItem(dir);
|
|
|
|
|
EditableListChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-13 18:23:54 +00:00
|
|
|
|
void WidgetInfo::EditListRemove()
|
|
|
|
|
{
|
|
|
|
|
QListWidget *list = reinterpret_cast<QListWidget *>(widget);
|
|
|
|
|
QList<QListWidgetItem *> items = list->selectedItems();
|
|
|
|
|
|
|
|
|
|
for (QListWidgetItem *item : items)
|
|
|
|
|
delete item;
|
|
|
|
|
EditableListChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::EditListEdit()
|
|
|
|
|
{
|
|
|
|
|
QListWidget *list = reinterpret_cast<QListWidget *>(widget);
|
2016-05-26 17:48:07 +00:00
|
|
|
|
enum obs_editable_list_type type =
|
|
|
|
|
obs_property_editable_list_type(property);
|
2015-04-13 18:23:54 +00:00
|
|
|
|
const char *desc = obs_property_description(property);
|
|
|
|
|
const char *filter = obs_property_editable_list_filter(property);
|
|
|
|
|
QList<QListWidgetItem *> selectedItems = list->selectedItems();
|
|
|
|
|
|
|
|
|
|
if (!selectedItems.count())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QListWidgetItem *item = selectedItems[0];
|
2016-05-26 17:48:07 +00:00
|
|
|
|
|
|
|
|
|
if (type == OBS_EDITABLE_LIST_TYPE_FILES) {
|
2019-03-31 11:35:48 +00:00
|
|
|
|
QDir pathDir(item->text());
|
|
|
|
|
QString path;
|
|
|
|
|
|
|
|
|
|
if (pathDir.exists())
|
2020-07-17 11:32:38 +00:00
|
|
|
|
path = SelectDirectory(App()->GetMainWindow(),
|
|
|
|
|
QTStr("Browse"), item->text());
|
2019-03-31 11:35:48 +00:00
|
|
|
|
else
|
2020-07-17 11:32:38 +00:00
|
|
|
|
path = OpenFile(App()->GetMainWindow(), QTStr("Browse"),
|
|
|
|
|
item->text(), QT_UTF8(filter));
|
2019-03-31 11:35:48 +00:00
|
|
|
|
|
2016-05-26 17:48:07 +00:00
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
item->setText(path);
|
|
|
|
|
EditableListChanged();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EditableItemDialog dialog(widget->window(), item->text(),
|
|
|
|
|
type != OBS_EDITABLE_LIST_TYPE_STRINGS,
|
|
|
|
|
filter);
|
2015-04-13 18:23:54 +00:00
|
|
|
|
auto title = QTStr("Basic.PropertiesWindow.EditEditableListEntry")
|
|
|
|
|
.arg(QT_UTF8(desc));
|
|
|
|
|
dialog.setWindowTitle(title);
|
|
|
|
|
if (dialog.exec() == QDialog::Rejected)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString text = dialog.GetText();
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
item->setText(text);
|
|
|
|
|
EditableListChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::EditListUp()
|
|
|
|
|
{
|
|
|
|
|
QListWidget *list = reinterpret_cast<QListWidget *>(widget);
|
|
|
|
|
int lastItemRow = -1;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < list->count(); i++) {
|
|
|
|
|
QListWidgetItem *item = list->item(i);
|
|
|
|
|
if (!item->isSelected())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
int row = list->row(item);
|
|
|
|
|
|
|
|
|
|
if ((row - 1) != lastItemRow) {
|
|
|
|
|
lastItemRow = row - 1;
|
|
|
|
|
list->takeItem(row);
|
|
|
|
|
list->insertItem(lastItemRow, item);
|
|
|
|
|
item->setSelected(true);
|
|
|
|
|
} else {
|
|
|
|
|
lastItemRow = row;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EditableListChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WidgetInfo::EditListDown()
|
|
|
|
|
{
|
|
|
|
|
QListWidget *list = reinterpret_cast<QListWidget *>(widget);
|
|
|
|
|
int lastItemRow = list->count();
|
|
|
|
|
|
|
|
|
|
for (int i = list->count() - 1; i >= 0; i--) {
|
|
|
|
|
QListWidgetItem *item = list->item(i);
|
|
|
|
|
if (!item->isSelected())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
int row = list->row(item);
|
|
|
|
|
|
|
|
|
|
if ((row + 1) != lastItemRow) {
|
|
|
|
|
lastItemRow = row + 1;
|
|
|
|
|
list->takeItem(row);
|
|
|
|
|
list->insertItem(lastItemRow, item);
|
|
|
|
|
item->setSelected(true);
|
|
|
|
|
} else {
|
|
|
|
|
lastItemRow = row;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EditableListChanged();
|
|
|
|
|
}
|