瀏覽代碼

UI: Store dock titles in BrowserDock instead of relying on Qt

Attempting to set the window title of a BrowserDock that is closed, then
opening the BrowserDock, would show that BrowserDock with an incorrect
title. We can handle this by overriding the showEvent of BrowserDock and
manually setting the window title after the showEvent is called,
hopefully ensuring that we are only setting the window title on a window
that exists.
Ryan Foster 2 年之前
父節點
當前提交
f049d04af4
共有 5 個文件被更改,包括 21 次插入1 次删除
  1. 6 0
      UI/window-dock-browser.cpp
  2. 8 1
      UI/window-dock-browser.hpp
  3. 5 0
      UI/window-dock.cpp
  4. 1 0
      UI/window-dock.hpp
  5. 1 0
      UI/window-extra-browsers.cpp

+ 6 - 0
UI/window-dock-browser.cpp

@@ -18,3 +18,9 @@ void BrowserDock::closeEvent(QCloseEvent *event)
 		cefWidget->closeBrowser();
 	}
 }
+
+void BrowserDock::showEvent(QShowEvent *event)
+{
+	OBSDock::showEvent(event);
+	setWindowTitle(title);
+}

+ 8 - 1
UI/window-dock-browser.hpp

@@ -8,10 +8,14 @@ extern QCef *cef;
 extern QCefCookieManager *panel_cookies;
 
 class BrowserDock : public OBSDock {
+private:
+	QString title;
+
 public:
 	inline BrowserDock() : OBSDock() { setAttribute(Qt::WA_NativeWindow); }
-	inline BrowserDock(const QString &title) : OBSDock(title)
+	inline BrowserDock(const QString &title_) : OBSDock(title_)
 	{
+		title = title_;
 		setAttribute(Qt::WA_NativeWindow);
 	}
 
@@ -23,5 +27,8 @@ public:
 		cefWidget.reset(widget_);
 	}
 
+	inline void setTitle(const QString &title_) { title = title_; }
+
 	void closeEvent(QCloseEvent *event) override;
+	void showEvent(QShowEvent *event) override;
 };

+ 5 - 0
UI/window-dock.cpp

@@ -34,3 +34,8 @@ void OBSDock::closeEvent(QCloseEvent *event)
 
 	QDockWidget::closeEvent(event);
 }
+
+void OBSDock::showEvent(QShowEvent *event)
+{
+	QDockWidget::showEvent(event);
+}

+ 1 - 0
UI/window-dock.hpp

@@ -13,4 +13,5 @@ public:
 	}
 
 	virtual void closeEvent(QCloseEvent *event);
+	virtual void showEvent(QShowEvent *event);
 };

+ 1 - 0
UI/window-extra-browsers.cpp

@@ -181,6 +181,7 @@ void ExtraBrowsersModel::UpdateItem(Item &item)
 	if (main->extraBrowserDockNames[idx] != item.title) {
 		main->extraBrowserDockNames[idx] = item.title;
 		dock->toggleViewAction()->setText(item.title);
+		dock->setTitle(item.title);
 	}
 
 	if (main->extraBrowserDockTargets[idx] != item.url) {