[calamares] Decouple debug-window button

- Provide slots and signals for managing the debug-window,
  so it can be used from QML as well.
This commit is contained in:
Adriaan de Groot 2021-03-05 13:20:47 +01:00
parent 473576991d
commit ab7f6abf02
2 changed files with 37 additions and 19 deletions

View File

@ -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 )
{

View File

@ -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;