Skip to content

Commit

Permalink
Merge branch 'master' into webrtc-plus-selector
Browse files Browse the repository at this point in the history
solve merge conflict
  • Loading branch information
lucaspontoexe committed Mar 2, 2024
2 parents 5569c5a + ff25e9e commit aec02f6
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 38 deletions.
117 changes: 99 additions & 18 deletions src/edit-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "obs.hpp"
#include <QMenu>
#include <QTabWidget>
#include <QScrollBar>
#include <qevent.h>
#include <QComboBox>

#include "obs-properties-widget.h"
Expand Down Expand Up @@ -56,8 +58,25 @@ static obs_properties* AddBF(obs_properties* p) {
}


class EditOutputWidgetImpl : public EditOutputWidget
template<class T>
class EventFilter: public QObject {
T lambda_;
public:
bool eventFilter(QObject *watched, QEvent *event) override {
return lambda_(watched, event);
}

EventFilter(QObject* parent, T&& lambda): lambda_(std::move(lambda)) {
setParent(parent);
}
};


class EditOutputWidgetImpl: public EditOutputWidget
{
QWidget* container_;
QScrollArea* scroll_;

std::string targetid_;
OutputTargetConfigPtr config_ = nullptr;

Expand Down Expand Up @@ -256,18 +275,22 @@ class EditOutputWidgetImpl : public EditOutputWidget

// service
{
serviceSettings_ = new PropertiesWidget(this);
serviceSettings_ = new PropertiesWidget(tab);
updateServiceTab();
tab->addTab(serviceSettings_, obs_module_text("Tab.Service"));
}

// output
{
outputSettings_ = new PropertiesWidget(this);
outputSettings_ = new PropertiesWidget(tab);
updateOutputTab();
tab->addTab(outputSettings_, obs_module_text("Tab.Output"));
}

QObject::connect(tab, &QTabWidget::currentChanged, [tab](int index) {
tab->adjustSize();
});

tab->setCurrentIndex(0);

return tab;
Expand Down Expand Up @@ -318,23 +341,31 @@ class EditOutputWidgetImpl : public EditOutputWidget
: QDialog(parent)
, targetid_(targetid)
{

setWindowTitle(obs_module_text("StreamingSettings"));

auto& global = GlobalMultiOutputConfig();
config_ = FindById(global.targets, targetid_);
if (config_ == nullptr) {
return;
}
config_ = std::make_shared<OutputTargetConfig>(*config_);

auto layout = new QVBoxLayout(this);
setWindowTitle(obs_module_text("StreamingSettings"));

scroll_ = new QScrollArea(this);
scroll_->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
scroll_->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
scroll_->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding);
scroll_->setSizeAdjustPolicy(QScrollArea::SizeAdjustPolicy::AdjustToContents);

container_ = new QWidget(scroll_);
container_->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding);

auto layout = new QVBoxLayout(container_);

int currow = 0;
{
auto sublayout = new QHBoxLayout(this);
sublayout->addWidget(new QLabel(obs_module_text("StreamingName"), this));
sublayout->addWidget(name_ = new QLineEdit("", this), 1);
auto sublayout = new QHBoxLayout(container_);
sublayout->addWidget(new QLabel(obs_module_text("StreamingName"), container_));
sublayout->addWidget(name_ = new QLineEdit("", container_), 1);
layout->addLayout(sublayout);
}
++currow;
Expand All @@ -346,7 +377,7 @@ class EditOutputWidgetImpl : public EditOutputWidget
++currow;

{
auto w = CreateOutputSettingsWidget(this);
auto w = CreateOutputSettingsWidget(container_);
layout->addWidget(w);
}
++currow;
Expand All @@ -356,7 +387,7 @@ class EditOutputWidgetImpl : public EditOutputWidget
sub_grid->setColumnStretch(1, 0);
{
{
auto gp = new QGroupBox(obs_module_text("VideoSettings"), this);
auto gp = new QGroupBox(obs_module_text("VideoSettings"), container_);
sub_grid->addWidget(gp, 0, 0, 2, 1);
auto encLayout = new QGridLayout();
int currow = 0;
Expand Down Expand Up @@ -403,13 +434,13 @@ class EditOutputWidgetImpl : public EditOutputWidget
++currow;
{
encLayout->addWidget(videoEncoderSettings_ = new PropertiesWidget(gp), currow, 0, 1, 2);
videoEncoderSettings_->setMinimumHeight(180);
// videoEncoderSettings_->setMinimumHeight(180);
}
gp->setLayout(encLayout);
}

{
auto gp = new QGroupBox(obs_module_text("AudioSettings"), this);
auto gp = new QGroupBox(obs_module_text("AudioSettings"), container_);
sub_grid->addWidget(gp, 0, 1, 1, 1);
auto encLayout = new QGridLayout();
int currow = 0;
Expand Down Expand Up @@ -451,7 +482,7 @@ class EditOutputWidgetImpl : public EditOutputWidget
}

{
auto gp = new QGroupBox(obs_module_text("OtherSettings"), this);
auto gp = new QGroupBox(obs_module_text("OtherSettings"), container_);
sub_grid->addWidget(gp, 1, 1, 1, 1);
auto otherLayout = new QGridLayout();
otherLayout->addWidget(syncStart_ = new QCheckBox(obs_module_text("SyncStart"), gp), 0, 0);
Expand All @@ -463,7 +494,7 @@ class EditOutputWidgetImpl : public EditOutputWidget
}
++currow;
{
auto okbtn = new QPushButton(obs_module_text("OK"), this);
auto okbtn = new QPushButton(obs_module_text("OK"), container_);
QObject::connect(okbtn, &QPushButton::clicked, [this]() {
SaveConfig();
auto& global = GlobalMultiOutputConfig();
Expand All @@ -476,8 +507,18 @@ class EditOutputWidgetImpl : public EditOutputWidget
layout->addWidget(okbtn);
}

// layout->setSizeConstraint(QLayout::SetFixedSize);
setLayout(layout);
layout->setSizeConstraint(QLayout::SetFixedSize);
container_->setLayout(layout);

scroll_->setWidget(container_);
scroll_->setWidgetResizable(true);

auto fullLayout = new QGridLayout(this);
fullLayout->setContentsMargins(0, 0, 0, 0);
fullLayout->addWidget(scroll_, 0, 0);
fullLayout->setRowStretch(0, 1);
fullLayout->setColumnStretch(0, 1);
setLayout(fullLayout);

LoadFPSDenumerator();
LoadEncoders();
Expand All @@ -486,6 +527,45 @@ class EditOutputWidgetImpl : public EditOutputWidget
LoadConfig();
ConnectWidgetSignals();
UpdateUI();

auto resizeCount = std::make_shared<int>(0);
container_->installEventFilter(new EventFilter(container_, [this, resizeCount](QObject* watched, QEvent* ev) {
if (watched == container_ && ev->type() == QEvent::Resize) {
++*resizeCount;
if (*resizeCount == 2) { // why 2? I don't know
auto frameGeo = frameGeometry();
auto clientGeo = geometry();

auto sizehint = container_->layout()->sizeHint();
// add frame size
sizehint = sizehint.grownBy(QMargins(
frameGeo.width() - clientGeo.width(),
frameGeo.height() - clientGeo.height(),
0, 0
));
auto vs = scroll_->verticalScrollBar();
auto hs = scroll_->horizontalScrollBar();
sizehint = sizehint.grownBy(QMargins(
vs ? vs->width() / 2 : 0, hs ? hs->height() / 2 : 0,
vs ? vs->width() / 2 : 0, hs ? hs->height() / 2 : 0
));
auto parentCenter = parentWidget()->geometry().center();
QRect g;
g.setSize(sizehint);
g.moveCenter(parentCenter);
auto avail = screen()->availableGeometry();
g = avail.intersected(g);

// remove frame size
g.setTop(g.top() + (clientGeo.top() - frameGeo.top()));
g.setBottom(g.bottom() - (frameGeo.bottom() - clientGeo.bottom()));
g.setLeft(g.left() + (clientGeo.left() - frameGeo.left()));
g.setRight(g.right() - (frameGeo.right() - clientGeo.right()));
setGeometry(g);
}
}
return false;
}));
}

void ConnectWidgetSignals()
Expand Down Expand Up @@ -845,6 +925,7 @@ class EditOutputWidgetImpl : public EditOutputWidget
}
};


EditOutputWidget* createEditOutputWidget(const std::string& targetid, QWidget* parent) {
return new EditOutputWidgetImpl(targetid, parent);
}
26 changes: 7 additions & 19 deletions src/obs-properties-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ namespace {


class QLineEditWithFocus : public QLineEdit {
UpdateHandler* updater;
public:
template<class ...Args>
QLineEditWithFocus(UpdateHandler* updater, QWidget* parent)
: updater(updater)
, QLineEdit(parent)
{
}

UpdateHandler* updater;
}

void focusOutEvent(QFocusEvent* e) override {
QLineEdit::focusOutEvent(e);
Expand Down Expand Up @@ -65,6 +64,8 @@ namespace {

layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);

setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Fixed);
}

QLineEdit* edit() const { return edit_; }
Expand Down Expand Up @@ -255,8 +256,6 @@ namespace {


class QPropertiesWidgetImpl: virtual public QWidget, public QPropertiesWidget, public UpdateHandler {
QScrollArea scroll_;
QWidget* container_;
std::unordered_map<std::string, std::shared_ptr<PropertyWidget>> propwids;
obs_properties* props;
OBSData settings;
Expand All @@ -268,8 +267,6 @@ namespace {
, props(props)
, orig_settings(p_settings)
{
container_ = new QWidget(this);

obs_data_release(p_settings);

settings = obs_data_create();
Expand All @@ -283,15 +280,6 @@ namespace {
obs_data_apply(settings, orig_settings);

UpdateUI();

scroll_.setWidgetResizable(true);
scroll_.setWidget(container_);

auto layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setRowStretch(0, 1);
layout->setColumnStretch(0, 1);
layout->addWidget(&scroll_, 0, 0);
}

~QPropertiesWidgetImpl()
Expand All @@ -304,7 +292,7 @@ namespace {
std::unordered_map<std::string, std::shared_ptr<PropertyWidget>> oldpropwids;
oldpropwids.swap(propwids);

auto oldLayout = container_->layout();
auto oldLayout = layout();
if (oldLayout) {
for (auto& x : oldpropwids) {
if (x.second->label)
Expand All @@ -327,7 +315,7 @@ namespace {
auto name = obs_property_name(x);
auto it = oldpropwids.find(name);
if (it == oldpropwids.end()) {
auto newwid = std::make_shared<PropertyWidget>(container_, this, x);
auto newwid = std::make_shared<PropertyWidget>(this, this, x);
propwids.insert(std::make_pair(newwid->name, newwid));
layout->addWidget(newwid->label, currow, 0);
layout->addWidget(newwid->ctrl, currow, 1);
Expand All @@ -341,7 +329,7 @@ namespace {

if (oldLayout)
delete oldLayout;
container_->setLayout(layout);
setLayout(layout);
}

bool isUpdating = false;
Expand Down
3 changes: 2 additions & 1 deletion src/push-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder
{
auto width = std::stoi(match[1].str());
auto height = std::stoi(match[2].str());
obs_encoder_set_gpu_scale_type(venc, obs_scale_type::OBS_SCALE_BICUBIC);
obs_encoder_set_scaled_size(venc, width, height);
}
}
Expand Down Expand Up @@ -676,7 +677,7 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder

bool ShowEditDlg() override
{
std::unique_ptr<EditOutputWidget> dlg{ createEditOutputWidget(targetid_, this) };
std::unique_ptr<EditOutputWidget> dlg{ createEditOutputWidget(targetid_, (QMainWindow*)obs_frontend_get_main_window()) };

if (dlg->exec() == QDialog::DialogCode::Accepted)
{
Expand Down

0 comments on commit aec02f6

Please sign in to comment.