Skip to content

Commit 592b209

Browse files
committed
Refactor UI components and fix URL source callbacks
1 parent 79852bd commit 592b209

File tree

5 files changed

+65
-68
lines changed

5 files changed

+65
-68
lines changed

src/ui/RequestBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data,
106106
setModal(true);
107107

108108
// set a minimum width for the dialog
109-
setMinimumWidth(500);
109+
setMinimumWidth(400);
110110

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

306306
// populate headers in ui->tableView_headers from request_data->headers
307307
addHeaders(request_data->headers, ui->tableView_headers);
308-
connect(ui->pushButton_addHeader, &QPushButton::clicked, this, [=]() {
308+
connect(ui->toolButton_addHeader, &QPushButton::clicked, this, [=]() {
309309
// add a new row
310310
((QStandardItemModel *)ui->tableView_headers->model())
311311
->appendRow({new QStandardItem(""), new QStandardItem("")});
312312
});
313-
connect(ui->pushButton_removeHeader, &QPushButton::clicked, this, [=]() {
313+
connect(ui->toolButton_removeHeader, &QPushButton::clicked, this, [=]() {
314314
// remove the selected row
315315
ui->tableView_headers->model()->removeRow(
316316
ui->tableView_headers->selectionModel()->currentIndex().row());

src/ui/outputmapping.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "plugin-support.h"
12
#include "outputmapping.h"
23
#include "ui_outputmapping.h"
34

@@ -10,7 +11,7 @@
1011

1112
namespace {
1213
// add_sources_to_list is a helper function that adds all text and media sources to the list
13-
bool add_sources_to_list(void *list_property, obs_source_t *source)
14+
bool add_sources_to_combobox(void *list_property, obs_source_t *source)
1415
{
1516
// add all text and media sources to the list
1617
auto source_id = obs_source_get_id(source);
@@ -119,9 +120,18 @@ OutputMapping::OutputMapping(output_mapping_data *mapping_data_in,
119120
<< new QStandardItem(""));
120121
QComboBox *comboBox = createSourcesComboBox();
121122
if (!mapping.output_source.empty()) {
123+
// find the index of the output_source in the comboBox, use EndsWith to match the prefix
124+
const auto index = comboBox->findText(mapping.output_source.c_str(),
125+
Qt::MatchEndsWith);
126+
if (index == -1) {
127+
obs_log(LOG_WARNING, "Output source '%s' not found in combo box",
128+
mapping.output_source.c_str());
129+
continue;
130+
}
131+
122132
// select the output_source of the mapping in the comboBox
123133
comboBox->blockSignals(true);
124-
comboBox->setCurrentText(mapping.output_source.c_str());
134+
comboBox->setCurrentIndex(index);
125135
comboBox->blockSignals(false);
126136
}
127137
// add a row to the model with the data and output_source of the mapping
@@ -152,7 +162,7 @@ QComboBox *OutputMapping::createSourcesComboBox()
152162
// add "Internal Renderer" to the comboBox
153163
comboBox->addItem(QString::fromStdString(none_internal_rendering));
154164
// add all text and media sources to the comboBox
155-
obs_enum_sources(add_sources_to_list, comboBox);
165+
obs_enum_sources(add_sources_to_combobox, comboBox);
156166
// connect comboBox to update_handler
157167
connect(comboBox, &QComboBox::currentIndexChanged, [this, comboBox]() {
158168
// get the selected row

src/ui/outputmapping.ui

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Use {{body}} variable for unparsed object/array representation of the entire res
123123
<bool>false</bool>
124124
</property>
125125
<property name="plainText">
126-
<string>{{output}}</string>
126+
<string/>
127127
</property>
128128
</widget>
129129
</item>
@@ -133,9 +133,7 @@ Use {{body}} variable for unparsed object/array representation of the entire res
133133
<bool>false</bool>
134134
</property>
135135
<property name="plainText">
136-
<string>background-color: transparent;
137-
color: #FFFFFF;
138-
font-size: 48px;</string>
136+
<string/>
139137
</property>
140138
</widget>
141139
</item>

src/ui/requestbuilder.ui

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>602</width>
10-
<height>971</height>
9+
<width>493</width>
10+
<height>809</height>
1111
</rect>
1212
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
15+
<horstretch>0</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
1319
<property name="windowTitle">
1420
<string>Dialog</string>
1521
</property>
@@ -121,7 +127,7 @@
121127
<widget class="QLineEdit" name="urlLineEdit"/>
122128
</item>
123129
<item>
124-
<widget class="QPushButton" name="urlOrFileButton">
130+
<widget class="QToolButton" name="urlOrFileButton">
125131
<property name="text">
126132
<string>...</string>
127133
</property>
@@ -136,7 +142,7 @@
136142
<item>
137143
<widget class="QGroupBox" name="urlRequestOptionsGroup">
138144
<property name="sizePolicy">
139-
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
145+
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
140146
<horstretch>0</horstretch>
141147
<verstretch>0</verstretch>
142148
</sizepolicy>
@@ -151,6 +157,9 @@
151157
<property name="verticalSpacing">
152158
<number>3</number>
153159
</property>
160+
<property name="topMargin">
161+
<number>0</number>
162+
</property>
154163
<item row="4" column="0">
155164
<widget class="QLabel" name="label_3">
156165
<property name="text">
@@ -290,7 +299,7 @@
290299
<item>
291300
<widget class="QTableView" name="tableView_headers">
292301
<property name="sizePolicy">
293-
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
302+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
294303
<horstretch>0</horstretch>
295304
<verstretch>0</verstretch>
296305
</sizepolicy>
@@ -331,16 +340,16 @@
331340
<number>0</number>
332341
</property>
333342
<item>
334-
<widget class="QPushButton" name="pushButton_addHeader">
343+
<widget class="QToolButton" name="toolButton_addHeader">
335344
<property name="text">
336-
<string>+</string>
345+
<string></string>
337346
</property>
338347
</widget>
339348
</item>
340349
<item>
341-
<widget class="QPushButton" name="pushButton_removeHeader">
350+
<widget class="QToolButton" name="toolButton_removeHeader">
342351
<property name="text">
343-
<string>-</string>
352+
<string></string>
344353
</property>
345354
</widget>
346355
</item>
@@ -395,12 +404,6 @@
395404
</property>
396405
<item>
397406
<widget class="QComboBox" name="obsTextSourceComboBox">
398-
<property name="sizePolicy">
399-
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
400-
<horstretch>0</horstretch>
401-
<verstretch>0</verstretch>
402-
</sizepolicy>
403-
</property>
404407
<property name="toolTip">
405408
<string>&quot;Select a OBS text source to use its current text in the querystring or request body as `{{input}}` or `{{imageb64}}`.&quot;</string>
406409
</property>
@@ -494,6 +497,19 @@
494497
</property>
495498
</widget>
496499
</item>
500+
<item>
501+
<spacer name="horizontalSpacer_2">
502+
<property name="orientation">
503+
<enum>Qt::Horizontal</enum>
504+
</property>
505+
<property name="sizeHint" stdset="0">
506+
<size>
507+
<width>40</width>
508+
<height>20</height>
509+
</size>
510+
</property>
511+
</spacer>
512+
</item>
497513
<item>
498514
<widget class="QCheckBox" name="aggToTarget">
499515
<property name="toolTip">
@@ -559,12 +575,6 @@
559575
</item>
560576
<item row="9" column="1">
561577
<widget class="QTextEdit" name="bodyTextEdit">
562-
<property name="sizePolicy">
563-
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
564-
<horstretch>0</horstretch>
565-
<verstretch>1</verstretch>
566-
</sizepolicy>
567-
</property>
568578
<property name="acceptRichText">
569579
<bool>false</bool>
570580
</property>
@@ -640,7 +650,7 @@
640650
</widget>
641651
</item>
642652
<item>
643-
<widget class="QPushButton" name="sslCertFileButton">
653+
<widget class="QToolButton" name="sslCertFileButton">
644654
<property name="sizePolicy">
645655
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
646656
<horstretch>0</horstretch>
@@ -687,7 +697,7 @@
687697
</widget>
688698
</item>
689699
<item>
690-
<widget class="QPushButton" name="sslKeyFileButton">
700+
<widget class="QToolButton" name="sslKeyFileButton">
691701
<property name="text">
692702
<string>...</string>
693703
</property>
@@ -719,7 +729,7 @@
719729
<item>
720730
<widget class="QGroupBox" name="outputGroupBox">
721731
<property name="sizePolicy">
722-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
732+
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
723733
<horstretch>0</horstretch>
724734
<verstretch>0</verstretch>
725735
</sizepolicy>
@@ -743,12 +753,6 @@
743753
</item>
744754
<item row="0" column="1">
745755
<widget class="QComboBox" name="outputTypeComboBox">
746-
<property name="sizePolicy">
747-
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
748-
<horstretch>0</horstretch>
749-
<verstretch>0</verstretch>
750-
</sizepolicy>
751-
</property>
752756
<item>
753757
<property name="text">
754758
<string>Text</string>
@@ -917,12 +921,6 @@
917921
</item>
918922
<item>
919923
<widget class="QLabel" name="errorMessageLabel">
920-
<property name="sizePolicy">
921-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
922-
<horstretch>0</horstretch>
923-
<verstretch>0</verstretch>
924-
</sizepolicy>
925-
</property>
926924
<property name="styleSheet">
927925
<string notr="true">QLabel { color : red; }</string>
928926
</property>

src/url-source-callbacks.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ void render_internal(const std::string &text, struct url_source_data *usd,
128128
uint32_t width = usd->render_width;
129129
uint32_t height = 0;
130130

131+
if (usd->frame.data[0] != nullptr) {
132+
// Free the old render buffer
133+
bfree(usd->frame.data[0]);
134+
usd->frame.data[0] = nullptr;
135+
}
136+
131137
// render the text with QTextDocument
132138
render_text_with_qtextdocument(text, width, height, &renderBuffer, mapping.css_props);
133139
// Update the frame
@@ -190,13 +196,9 @@ void output_with_mapping(const request_data_handler_response &response, struct u
190196
return;
191197
}
192198

193-
obs_log(LOG_INFO, "Output with mapping");
194-
199+
bool any_internal_rendering = false;
195200
// iterate over the mappings and output the text with each one
196201
for (const auto &mapping : usd->output_mapping_data.mappings) {
197-
obs_log(LOG_INFO, "Output with mapping: %s %s", mapping.name.c_str(),
198-
mapping.output_source.c_str());
199-
200202
if (usd->request_data.output_type == "Audio (data)") {
201203
if (!is_valid_output_source_name(mapping.output_source.c_str())) {
202204
obs_log(LOG_ERROR, "Must select an output source for audio output");
@@ -218,29 +220,18 @@ void output_with_mapping(const request_data_handler_response &response, struct u
218220
}
219221
}
220222

221-
if (usd->frame.data[0] != nullptr) {
222-
// Free the old render buffer
223-
bfree(usd->frame.data[0]);
224-
usd->frame.data[0] = nullptr;
225-
}
226-
227223
if (is_valid_output_source_name(mapping.output_source.c_str()) &&
228224
mapping.output_source != none_internal_rendering) {
229-
obs_log(LOG_INFO, "Output to text source: %s",
230-
mapping.output_source.c_str());
231225
// If an output source is selected - use it for rendering
232226
setTextCallback(text, mapping);
233-
234-
// Update the frame with an empty buffer of 1x1 pixels
235-
usd->frame.data[0] = (uint8_t *)bzalloc(4);
236-
usd->frame.linesize[0] = 4;
237-
usd->frame.width = 1;
238-
usd->frame.height = 1;
239-
240-
// Send the frame
241-
obs_source_output_video(usd->source, &usd->frame);
242227
} else {
228+
any_internal_rendering = true;
243229
render_internal(text, usd, mapping);
244230
} // end if not text source
245231
}
232+
233+
if (!any_internal_rendering) {
234+
// Send a null frame to hide the source
235+
obs_source_output_video(usd->source, nullptr);
236+
}
246237
}

0 commit comments

Comments
 (0)