UI: Add css on Drag and Drop

Adds parsing for the "layer-css" query param of URLs dragged into the main window, similarly to the other layer-* parameters already used.
This commit is contained in:
Peter "Marenthyu" Fredebold 2021-02-24 21:37:18 +01:00 committed by Jim
parent 7d5430f4ea
commit 2a87543d82

View File

@ -72,6 +72,20 @@ void OBSBasic::AddDropURL(const char *url, QString &name, obs_data_t *settings,
cx = query.queryItemValue("layer-width").toInt();
if (query.hasQueryItem("layer-height"))
cy = query.queryItemValue("layer-height").toInt();
if (query.hasQueryItem("layer-css")) {
// QUrl::FullyDecoded does NOT properly decode a
// application/x-www-form-urlencoded space represented as '+'
// Thus, this is manually filtered out before QUrl's
// decoding kicks in again. This is to allow JavaScript's
// default searchParams.append function to simply append css
// to the query parameters, which is the intended usecase for this.
QString fullyEncoded =
query.queryItemValue("layer-css", QUrl::FullyEncoded);
fullyEncoded = fullyEncoded.replace("+", "%20");
QString decoded = QUrl::fromPercentEncoding(
QByteArray::fromStdString(QT_TO_UTF8(fullyEncoded)));
obs_data_set_string(settings, "css", QT_TO_UTF8(decoded));
}
obs_data_set_int(settings, "width", cx);
obs_data_set_int(settings, "height", cy);
@ -83,6 +97,7 @@ void OBSBasic::AddDropURL(const char *url, QString &name, obs_data_t *settings,
query.removeQueryItem("layer-width");
query.removeQueryItem("layer-height");
query.removeQueryItem("layer-name");
query.removeQueryItem("layer-css");
path.setQuery(query);
obs_data_set_string(settings, "url", QT_TO_UTF8(path.url()));