From 592b2093fd36e2fcc567c32c95916f4ab982845c Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Thu, 11 Apr 2024 00:15:45 -0400 Subject: [PATCH] Refactor UI components and fix URL source callbacks --- src/ui/RequestBuilder.cpp | 6 ++-- src/ui/outputmapping.cpp | 16 +++++++-- src/ui/outputmapping.ui | 6 ++-- src/ui/requestbuilder.ui | 70 ++++++++++++++++++------------------ src/url-source-callbacks.cpp | 35 +++++++----------- 5 files changed, 65 insertions(+), 68 deletions(-) diff --git a/src/ui/RequestBuilder.cpp b/src/ui/RequestBuilder.cpp index af658eb..7b91f4f 100644 --- a/src/ui/RequestBuilder.cpp +++ b/src/ui/RequestBuilder.cpp @@ -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); @@ -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()); diff --git a/src/ui/outputmapping.cpp b/src/ui/outputmapping.cpp index 8e1ac2f..6d8e83b 100644 --- a/src/ui/outputmapping.cpp +++ b/src/ui/outputmapping.cpp @@ -1,3 +1,4 @@ +#include "plugin-support.h" #include "outputmapping.h" #include "ui_outputmapping.h" @@ -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); @@ -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 @@ -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 diff --git a/src/ui/outputmapping.ui b/src/ui/outputmapping.ui index e064c47..7be141d 100644 --- a/src/ui/outputmapping.ui +++ b/src/ui/outputmapping.ui @@ -123,7 +123,7 @@ Use {{body}} variable for unparsed object/array representation of the entire res false - {{output}} + @@ -133,9 +133,7 @@ Use {{body}} variable for unparsed object/array representation of the entire res false - background-color: transparent; -color: #FFFFFF; -font-size: 48px; + diff --git a/src/ui/requestbuilder.ui b/src/ui/requestbuilder.ui index 8a4f591..bdb475d 100644 --- a/src/ui/requestbuilder.ui +++ b/src/ui/requestbuilder.ui @@ -6,10 +6,16 @@ 0 0 - 602 - 971 + 493 + 809 + + + 0 + 0 + + Dialog @@ -121,7 +127,7 @@ - + ... @@ -136,7 +142,7 @@ - + 0 0 @@ -151,6 +157,9 @@ 3 + + 0 + @@ -290,7 +299,7 @@ - + 0 0 @@ -331,16 +340,16 @@ 0 - + - + + - + - - + @@ -395,12 +404,6 @@ - - - 0 - 0 - - "Select a OBS text source to use its current text in the querystring or request body as `{{input}}` or `{{imageb64}}`." @@ -494,6 +497,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -559,12 +575,6 @@ - - - 0 - 1 - - false @@ -640,7 +650,7 @@ - + 0 @@ -687,7 +697,7 @@ - + ... @@ -719,7 +729,7 @@ - + 0 0 @@ -743,12 +753,6 @@ - - - 0 - 0 - - Text @@ -917,12 +921,6 @@ - - - 0 - 0 - - QLabel { color : red; } diff --git a/src/url-source-callbacks.cpp b/src/url-source-callbacks.cpp index 2722cc7..eda3216 100644 --- a/src/url-source-callbacks.cpp +++ b/src/url-source-callbacks.cpp @@ -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 @@ -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"); @@ -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); + } }