Skip to content

Commit

Permalink
Refactor UI components and fix URL source callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Apr 11, 2024
1 parent 79852bd commit 592b209
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 68 deletions.
6 changes: 3 additions & 3 deletions src/ui/RequestBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data,
setModal(true);

// set a minimum width for the dialog
setMinimumWidth(500);
setMinimumWidth(400);

if (request_data->url_or_file == "url") {
ui->urlRadioButton->setChecked(true);
Expand Down Expand Up @@ -305,12 +305,12 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data,

// populate headers in ui->tableView_headers from request_data->headers
addHeaders(request_data->headers, ui->tableView_headers);
connect(ui->pushButton_addHeader, &QPushButton::clicked, this, [=]() {
connect(ui->toolButton_addHeader, &QPushButton::clicked, this, [=]() {
// add a new row
((QStandardItemModel *)ui->tableView_headers->model())
->appendRow({new QStandardItem(""), new QStandardItem("")});
});
connect(ui->pushButton_removeHeader, &QPushButton::clicked, this, [=]() {
connect(ui->toolButton_removeHeader, &QPushButton::clicked, this, [=]() {
// remove the selected row
ui->tableView_headers->model()->removeRow(
ui->tableView_headers->selectionModel()->currentIndex().row());
Expand Down
16 changes: 13 additions & 3 deletions src/ui/outputmapping.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "plugin-support.h"
#include "outputmapping.h"
#include "ui_outputmapping.h"

Expand All @@ -10,7 +11,7 @@

namespace {
// add_sources_to_list is a helper function that adds all text and media sources to the list
bool add_sources_to_list(void *list_property, obs_source_t *source)
bool add_sources_to_combobox(void *list_property, obs_source_t *source)
{
// add all text and media sources to the list
auto source_id = obs_source_get_id(source);
Expand Down Expand Up @@ -119,9 +120,18 @@ OutputMapping::OutputMapping(output_mapping_data *mapping_data_in,
<< new QStandardItem(""));
QComboBox *comboBox = createSourcesComboBox();
if (!mapping.output_source.empty()) {
// find the index of the output_source in the comboBox, use EndsWith to match the prefix
const auto index = comboBox->findText(mapping.output_source.c_str(),
Qt::MatchEndsWith);
if (index == -1) {
obs_log(LOG_WARNING, "Output source '%s' not found in combo box",
mapping.output_source.c_str());
continue;
}

// select the output_source of the mapping in the comboBox
comboBox->blockSignals(true);
comboBox->setCurrentText(mapping.output_source.c_str());
comboBox->setCurrentIndex(index);
comboBox->blockSignals(false);
}
// add a row to the model with the data and output_source of the mapping
Expand Down Expand Up @@ -152,7 +162,7 @@ QComboBox *OutputMapping::createSourcesComboBox()
// add "Internal Renderer" to the comboBox
comboBox->addItem(QString::fromStdString(none_internal_rendering));
// add all text and media sources to the comboBox
obs_enum_sources(add_sources_to_list, comboBox);
obs_enum_sources(add_sources_to_combobox, comboBox);
// connect comboBox to update_handler
connect(comboBox, &QComboBox::currentIndexChanged, [this, comboBox]() {
// get the selected row
Expand Down
6 changes: 2 additions & 4 deletions src/ui/outputmapping.ui
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Use {{body}} variable for unparsed object/array representation of the entire res
<bool>false</bool>
</property>
<property name="plainText">
<string>{{output}}</string>
<string/>
</property>
</widget>
</item>
Expand All @@ -133,9 +133,7 @@ Use {{body}} variable for unparsed object/array representation of the entire res
<bool>false</bool>
</property>
<property name="plainText">
<string>background-color: transparent;
color: #FFFFFF;
font-size: 48px;</string>
<string/>
</property>
</widget>
</item>
Expand Down
70 changes: 34 additions & 36 deletions src/ui/requestbuilder.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>602</width>
<height>971</height>
<width>493</width>
<height>809</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
Expand Down Expand Up @@ -121,7 +127,7 @@
<widget class="QLineEdit" name="urlLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="urlOrFileButton">
<widget class="QToolButton" name="urlOrFileButton">
<property name="text">
<string>...</string>
</property>
Expand All @@ -136,7 +142,7 @@
<item>
<widget class="QGroupBox" name="urlRequestOptionsGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand All @@ -151,6 +157,9 @@
<property name="verticalSpacing">
<number>3</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
Expand Down Expand Up @@ -290,7 +299,7 @@
<item>
<widget class="QTableView" name="tableView_headers">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down Expand Up @@ -331,16 +340,16 @@
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_addHeader">
<widget class="QToolButton" name="toolButton_addHeader">
<property name="text">
<string>+</string>
<string></string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_removeHeader">
<widget class="QToolButton" name="toolButton_removeHeader">
<property name="text">
<string>-</string>
<string></string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -395,12 +404,6 @@
</property>
<item>
<widget class="QComboBox" name="obsTextSourceComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&quot;Select a OBS text source to use its current text in the querystring or request body as `{{input}}` or `{{imageb64}}`.&quot;</string>
</property>
Expand Down Expand Up @@ -494,6 +497,19 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="aggToTarget">
<property name="toolTip">
Expand Down Expand Up @@ -559,12 +575,6 @@
</item>
<item row="9" column="1">
<widget class="QTextEdit" name="bodyTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
Expand Down Expand Up @@ -640,7 +650,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="sslCertFileButton">
<widget class="QToolButton" name="sslCertFileButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand Down Expand Up @@ -687,7 +697,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="sslKeyFileButton">
<widget class="QToolButton" name="sslKeyFileButton">
<property name="text">
<string>...</string>
</property>
Expand Down Expand Up @@ -719,7 +729,7 @@
<item>
<widget class="QGroupBox" name="outputGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand All @@ -743,12 +753,6 @@
</item>
<item row="0" column="1">
<widget class="QComboBox" name="outputTypeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Text</string>
Expand Down Expand Up @@ -917,12 +921,6 @@
</item>
<item>
<widget class="QLabel" name="errorMessageLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">QLabel { color : red; }</string>
</property>
Expand Down
35 changes: 13 additions & 22 deletions src/url-source-callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ void render_internal(const std::string &text, struct url_source_data *usd,
uint32_t width = usd->render_width;
uint32_t height = 0;

if (usd->frame.data[0] != nullptr) {
// Free the old render buffer
bfree(usd->frame.data[0]);
usd->frame.data[0] = nullptr;
}

// render the text with QTextDocument
render_text_with_qtextdocument(text, width, height, &renderBuffer, mapping.css_props);
// Update the frame
Expand Down Expand Up @@ -190,13 +196,9 @@ void output_with_mapping(const request_data_handler_response &response, struct u
return;
}

obs_log(LOG_INFO, "Output with mapping");

bool any_internal_rendering = false;
// iterate over the mappings and output the text with each one
for (const auto &mapping : usd->output_mapping_data.mappings) {
obs_log(LOG_INFO, "Output with mapping: %s %s", mapping.name.c_str(),
mapping.output_source.c_str());

if (usd->request_data.output_type == "Audio (data)") {
if (!is_valid_output_source_name(mapping.output_source.c_str())) {
obs_log(LOG_ERROR, "Must select an output source for audio output");
Expand All @@ -218,29 +220,18 @@ void output_with_mapping(const request_data_handler_response &response, struct u
}
}

if (usd->frame.data[0] != nullptr) {
// Free the old render buffer
bfree(usd->frame.data[0]);
usd->frame.data[0] = nullptr;
}

if (is_valid_output_source_name(mapping.output_source.c_str()) &&
mapping.output_source != none_internal_rendering) {
obs_log(LOG_INFO, "Output to text source: %s",
mapping.output_source.c_str());
// If an output source is selected - use it for rendering
setTextCallback(text, mapping);

// Update the frame with an empty buffer of 1x1 pixels
usd->frame.data[0] = (uint8_t *)bzalloc(4);
usd->frame.linesize[0] = 4;
usd->frame.width = 1;
usd->frame.height = 1;

// Send the frame
obs_source_output_video(usd->source, &usd->frame);
} else {
any_internal_rendering = true;
render_internal(text, usd, mapping);
} // end if not text source
}

if (!any_internal_rendering) {
// Send a null frame to hide the source
obs_source_output_video(usd->source, nullptr);
}
}

0 comments on commit 592b209

Please sign in to comment.