From 0ee64a32f6aafcf800c4d6cd133617614a2dd410 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Thu, 31 Dec 2020 13:30:59 -0800 Subject: [PATCH] console: Add a mechanism to allow components to add pages Add a MainWindow signal that is emitted when a debug console is created. Relay that signal to the Application. Add an AddPage method to the Console class that allows components to populate pages when they receive the signal. --- src/core/application.h | 3 +++ src/ui/console.cpp | 4 ++++ src/ui/console.h | 2 ++ src/ui/mainwindow.cpp | 10 +++++++++- src/ui/mainwindow.h | 2 ++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/application.h b/src/core/application.h index 6b5663228..d5be1dde9 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -32,6 +32,7 @@ class QSettings; class AlbumCoverLoader; class Appearance; class ApplicationImpl; +class Console; class CoverProviders; class CurrentArtLoader; class Database; @@ -121,6 +122,8 @@ class Application : public QObject { void SaveSettings(QSettings* settings); void SettingsDialogRequested(SettingsDialog::Page page); + void NewDebugConsole(Console* console); + private slots: void SaveSettings_(); diff --git a/src/ui/console.cpp b/src/ui/console.cpp index 4b5113e88..bebd9864b 100644 --- a/src/ui/console.cpp +++ b/src/ui/console.cpp @@ -77,3 +77,7 @@ QObject* Console::FindTopLevelObject(QString& name) { if (obj->objectName() == name) return obj; return nullptr; } + +void Console::AddPage(QWidget* page, const QString& label) { + ui_.tabWidget->addTab(page, label); +} diff --git a/src/ui/console.h b/src/ui/console.h index 31e0d2179..243535e9c 100644 --- a/src/ui/console.h +++ b/src/ui/console.h @@ -12,6 +12,8 @@ class Console : public QDialog { public: Console(Application* app, QWidget* parent = nullptr); + void AddPage(QWidget* page, const QString& label); + private slots: // Database void RunQuery(); diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index c5db3fb4e..e9a927ef9 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -487,6 +487,10 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd, connect(ui_->action_view_stream_details, SIGNAL(triggered()), SLOT(DiscoverStreamDetails())); + // Relay this signal to the Application + connect(this, SIGNAL(NewDebugConsole(Console*)), app_, + SIGNAL(NewDebugConsole(Console*))); + background_streams_->AddAction("Rain", ui_->action_rain); background_streams_->AddAction("Hypnotoad", ui_->action_hypnotoad); background_streams_->AddAction("Make it so!", ui_->action_enterprise); @@ -2741,7 +2745,11 @@ StreamDiscoverer* MainWindow::CreateStreamDiscoverer() { return discoverer; } -Console* MainWindow::CreateDebugConsole() { return new Console(app_, this); } +Console* MainWindow::CreateDebugConsole() { + Console* console = new Console(app_, this); + emit NewDebugConsole(console); + return console; +} void MainWindow::ShowAboutDialog() { about_dialog_->show(); } diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 1f032b938..c18e00c8a 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -152,6 +152,8 @@ class MainWindow : public QMainWindow, public PlatformInterface { void StopAfterToggled(bool stop); void IntroPointReached(); + + void NewDebugConsole(Console* console); private slots: void FilePathChanged(const QString& path);