From ab7f6abf026d5480fbf699846c8428767b6430d7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 5 Mar 2021 13:20:47 +0100 Subject: [PATCH] [calamares] Decouple debug-window button - Provide slots and signals for managing the debug-window, so it can be used from QML as well. --- src/calamares/CalamaresWindow.cpp | 43 ++++++++++++++++++------------- src/calamares/CalamaresWindow.h | 13 +++++++++- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 0d425d929..08a75094e 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -103,24 +103,8 @@ CalamaresWindow::getWidgetSidebar( QWidget* parent, int desiredWidth ) sideLayout->addWidget( debugWindowBtn ); debugWindowBtn->setFlat( true ); debugWindowBtn->setCheckable( true ); - connect( debugWindowBtn, &QPushButton::clicked, this, [=]( bool checked ) { - if ( checked ) - { - m_debugWindow = new Calamares::DebugWindow(); - m_debugWindow->show(); - connect( m_debugWindow.data(), &Calamares::DebugWindow::closed, this, [=]() { - m_debugWindow->deleteLater(); - debugWindowBtn->setChecked( false ); - } ); - } - else - { - if ( m_debugWindow ) - { - m_debugWindow->deleteLater(); - } - } - } ); + connect( debugWindowBtn, &QPushButton::clicked, this, &CalamaresWindow::showDebugWindow ); + connect( this, &CalamaresWindow::debugWindowShown, debugWindowBtn, &QPushButton::setChecked ); } CalamaresUtils::unmarginLayout( sideLayout ); @@ -430,6 +414,29 @@ CalamaresWindow::ensureSize( QSize size ) resize( w, h ); } +void +CalamaresWindow::showDebugWindow( bool show ) +{ + if ( show ) + { + m_debugWindow = new Calamares::DebugWindow(); + m_debugWindow->show(); + connect( m_debugWindow.data(), &Calamares::DebugWindow::closed, this, [=]() { + m_debugWindow->deleteLater(); + emit debugWindowShown( false ); + } ); + emit debugWindowShown( true ); + } + else + { + if ( m_debugWindow ) + { + m_debugWindow->deleteLater(); + } + emit debugWindowShown( false ); + } +} + void CalamaresWindow::closeEvent( QCloseEvent* event ) { diff --git a/src/calamares/CalamaresWindow.h b/src/calamares/CalamaresWindow.h index 009425aae..4c7972f26 100644 --- a/src/calamares/CalamaresWindow.h +++ b/src/calamares/CalamaresWindow.h @@ -30,7 +30,7 @@ public: CalamaresWindow( QWidget* parent = nullptr ); ~CalamaresWindow() override {} -public slots: +public Q_SLOTS: /** * This asks the main window to grow to accomodate @p size pixels, to accomodate * larger-than-expected window contents. The enlargement may be silently @@ -38,6 +38,17 @@ public slots: */ void ensureSize( QSize size ); + /** @brief Set visibility of debug window + * + * Shows or hides the debug window, depending on @p show. + * If Calamares is not in debug mode, nothing happens and the debug + * window remains hidden. + */ + void showDebugWindow( bool show ); + +Q_SIGNALS: + void debugWindowShown( bool show ); + protected: virtual void closeEvent( QCloseEvent* e ) override;