From cde5545f8f6c882187124a880403f0df48bef33c Mon Sep 17 00:00:00 2001 From: tytan652 Date: Sat, 22 Oct 2022 10:36:53 +0200 Subject: [PATCH] obs-frontend-api,UI,docs: Add dock API that ask for unique object name obs_frontend_add_dock() is deprecated in favor of obs_frontend_add_dock_by_id() --- UI/api-interface.cpp | 29 +++++++++++++++++++ UI/obs-frontend-api/obs-frontend-api.cpp | 14 +++++++++ UI/obs-frontend-api/obs-frontend-api.h | 7 +++++ UI/obs-frontend-api/obs-frontend-internal.hpp | 5 ++++ docs/sphinx/reference-frontend-api.rst | 27 +++++++++++++++++ 5 files changed, 82 insertions(+) diff --git a/UI/api-interface.cpp b/UI/api-interface.cpp index e6f376174..31e9a9632 100644 --- a/UI/api-interface.cpp +++ b/UI/api-interface.cpp @@ -398,6 +398,35 @@ struct OBSStudioAPI : obs_frontend_callbacks { return (void *)main->AddDockWidget(d); } + bool obs_frontend_add_dock_by_id(const char *id, const char *title, + void *widget) override + { + if (main->IsDockObjectNameUsed(QT_UTF8(id))) { + blog(LOG_WARNING, + "Dock id '%s' already used! " + "Duplicate library?", + id); + return false; + } + + OBSDock *dock = new OBSDock(main); + dock->setWidget((QWidget *)widget); + dock->setWindowTitle(QT_UTF8(title)); + dock->setObjectName(QT_UTF8(id)); + + main->AddDockWidget(dock, Qt::RightDockWidgetArea); + + dock->setFloating(true); + dock->setVisible(false); + + return true; + } + + void obs_frontend_remove_dock(const char *id) override + { + main->RemoveDockWidget(QT_UTF8(id)); + } + void obs_frontend_add_event_callback(obs_frontend_event_cb callback, void *private_data) override { diff --git a/UI/obs-frontend-api/obs-frontend-api.cpp b/UI/obs-frontend-api/obs-frontend-api.cpp index 56b349da4..15e1ac685 100644 --- a/UI/obs-frontend-api/obs-frontend-api.cpp +++ b/UI/obs-frontend-api/obs-frontend-api.cpp @@ -330,6 +330,20 @@ void *obs_frontend_add_dock(void *dock) return !!callbacks_valid() ? c->obs_frontend_add_dock(dock) : nullptr; } +bool obs_frontend_add_dock_by_id(const char *id, const char *title, + void *widget) +{ + return !!callbacks_valid() + ? c->obs_frontend_add_dock_by_id(id, title, widget) + : false; +} + +void obs_frontend_remove_dock(const char *id) +{ + if (callbacks_valid()) + c->obs_frontend_remove_dock(id); +} + void obs_frontend_add_event_callback(obs_frontend_event_cb callback, void *private_data) { diff --git a/UI/obs-frontend-api/obs-frontend-api.h b/UI/obs-frontend-api/obs-frontend-api.h index df00024c2..4102ea3f1 100644 --- a/UI/obs-frontend-api/obs-frontend-api.h +++ b/UI/obs-frontend-api/obs-frontend-api.h @@ -138,8 +138,15 @@ EXPORT void obs_frontend_add_tools_menu_item(const char *name, void *private_data); /* takes QDockWidget and returns QAction */ +OBS_DEPRECATED EXPORT void *obs_frontend_add_dock(void *dock); +/* takes QWidget for widget */ +EXPORT bool obs_frontend_add_dock_by_id(const char *id, const char *title, + void *widget); + +EXPORT void obs_frontend_remove_dock(const char *id); + typedef void (*obs_frontend_event_cb)(enum obs_frontend_event event, void *private_data); diff --git a/UI/obs-frontend-api/obs-frontend-internal.hpp b/UI/obs-frontend-api/obs-frontend-internal.hpp index e0cd9a7b7..58ba51ae9 100644 --- a/UI/obs-frontend-api/obs-frontend-internal.hpp +++ b/UI/obs-frontend-api/obs-frontend-internal.hpp @@ -66,6 +66,11 @@ struct obs_frontend_callbacks { virtual void *obs_frontend_add_dock(void *dock) = 0; + virtual bool obs_frontend_add_dock_by_id(const char *id, + const char *title, + void *widget) = 0; + virtual void obs_frontend_remove_dock(const char *id) = 0; + virtual void obs_frontend_add_event_callback(obs_frontend_event_cb callback, void *private_data) = 0; diff --git a/docs/sphinx/reference-frontend-api.rst b/docs/sphinx/reference-frontend-api.rst index 4e5e89118..b4ed0f4d4 100644 --- a/docs/sphinx/reference-frontend-api.rst +++ b/docs/sphinx/reference-frontend-api.rst @@ -447,6 +447,33 @@ Functions :param dock: QDockWidget to add/create :return: A pointer to the added QAction +.. deprecated:: 29.1 + Prefer :c:func:`obs_frontend_add_dock_by_id()` instead. + +--------------------------------------- + +.. function:: bool obs_frontend_add_dock_by_id(const char *id, const char *title, void *widget) + + Adds a dock with the widget to the UI with a toggle in the Docks + menu. + + Note: Use :c:func:`obs_frontend_remove_dock` to remove the dock + and the id from the UI. + + :param id: Unique identifier of the dock + :param title: Window title of the dock + :param widget: QWidget to insert in the dock + :return: *true* if the dock was added, *false* if the id was already + used + +--------------------------------------- + +.. function:: void obs_frontend_remove_dock(const char *id) + + Removes the dock with this id from the UI. + + :param id: Unique identifier of the dock to remove. + --------------------------------------- .. function:: void obs_frontend_add_event_callback(obs_frontend_event_cb callback, void *private_data)