Selaa lähdekoodia

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.

Peter "Marenthyu" Fredebold 4 vuotta sitten
vanhempi
sitoutus
2a87543d82
1 muutettua tiedostoa jossa 15 lisäystä ja 0 poistoa
  1. 15 0
      UI/window-basic-main-dropfiles.cpp

+ 15 - 0
UI/window-basic-main-dropfiles.cpp

@@ -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()));