Parcourir la source

UI: Make scenes serializable via QDataStream

This minimal implementation should be enough to drag&drop scenes between UI
elements in the same process in the future
Palana il y a 10 ans
Parent
commit
363b887cad
3 fichiers modifiés avec 25 ajouts et 1 suppressions
  1. 18 0
      obs/qt-wrappers.cpp
  2. 5 1
      obs/qt-wrappers.hpp
  3. 2 0
      obs/window-basic-main.cpp

+ 18 - 0
obs/qt-wrappers.cpp

@@ -19,6 +19,7 @@
 #include <graphics/graphics.h>
 #include <QWidget>
 #include <QMessageBox>
+#include <QDataStream>
 
 #if !defined(_WIN32) && !defined(__APPLE__)
 #include <QX11Info>
@@ -77,3 +78,20 @@ uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods)
 
 	return obsModifiers;
 }
+
+QDataStream &operator<<(QDataStream &out, const OBSScene &scene)
+{
+	return out << QString(obs_source_get_name(obs_scene_get_source(scene)));
+}
+
+QDataStream &operator>>(QDataStream &in, OBSScene &scene)
+{
+	QString sceneName;
+
+	in >> sceneName;
+
+	obs_source_t *source = obs_get_source_by_name(QT_TO_UTF8(sceneName));
+	scene = obs_scene_from_source(source);
+
+	return in;
+}

+ 5 - 1
obs/qt-wrappers.hpp

@@ -18,11 +18,12 @@
 #pragma once
 
 #include <QWidget>
-#include <obs.h>
+#include <obs.hpp>
 
 #define QT_UTF8(str) QString::fromUtf8(str)
 #define QT_TO_UTF8(str) str.toUtf8().constData()
 
+class QDataStream;
 class QWidget;
 struct gs_window;
 
@@ -31,3 +32,6 @@ void OBSErrorBox(QWidget *parent, const char *msg, ...);
 void QTToGSWindow(WId windowId, gs_window &gswindow);
 
 uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods);
+
+QDataStream &operator<<(QDataStream &out, const OBSScene &scene);
+QDataStream &operator>>(QDataStream &in, OBSScene &scene);

+ 2 - 0
obs/window-basic-main.cpp

@@ -133,6 +133,8 @@ OBSBasic::OBSBasic(QWidget *parent)
 	qRegisterMetaType<OBSSource>   ("OBSSource");
 	qRegisterMetaType<obs_hotkey_id>("obs_hotkey_id");
 
+	qRegisterMetaTypeStreamOperators<OBSScene>("OBSScene");
+
 	ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);
 	ui->sources->setAttribute(Qt::WA_MacShowFocusRect, false);