Răsfoiți Sursa

UI,docs: Send a custom event to the dock widget when closing

tytan652 1 an în urmă
părinte
comite
3b266fec22
3 a modificat fișierele cu 13 adăugiri și 0 ștergeri
  1. 2 0
      UI/window-basic-main.cpp
  2. 5 0
      UI/window-dock.cpp
  3. 6 0
      docs/sphinx/reference-frontend-api.rst

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

@@ -329,6 +329,8 @@ OBSBasic::OBSBasic(QWidget *parent)
 
 	setContextMenuPolicy(Qt::CustomContextMenu);
 
+	QEvent::registerEventType(QEvent::User + QEvent::Close);
+
 	api = InitializeAPIInterface(this);
 
 	ui->setupUi(this);

+ 5 - 0
UI/window-dock.cpp

@@ -34,6 +34,11 @@ void OBSDock::closeEvent(QCloseEvent *event)
 	}
 
 	QDockWidget::closeEvent(event);
+
+	if (widget() && event->isAccepted()) {
+		QEvent widgetEvent(QEvent::Type(QEvent::User + QEvent::Close));
+		qApp->sendEvent(widget(), &widgetEvent);
+	}
 }
 
 void OBSDock::showEvent(QShowEvent *event)

+ 6 - 0
docs/sphinx/reference-frontend-api.rst

@@ -480,6 +480,12 @@ Functions
    Adds a dock with the widget to the UI with a toggle in the Docks
    menu.
 
+   When the dock is closed, a custom QEvent of type `QEvent::User + QEvent::Close`
+   is sent to the widget to enable it to react to the event (e.g., unload elements
+   to save resources).
+   A generic QShowEvent is already sent by default when the widget is being
+   shown (e.g., dock opened).
+
    Note: Use :c:func:`obs_frontend_remove_dock` to remove the dock
          and the id from the UI.