From 0b8ef49e7e05812690e58271505b16dbfc41a622 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 6 Mar 2021 23:11:41 +0100 Subject: [PATCH] [calamares] Make debug-window available to QML - Add a toggle() to the debug-window manager, for convenience - Make the manager available to QML - Use the debug-window manager (code imported from KaOS) --- src/calamares/CalamaresWindow.cpp | 15 +++++++++++++-- src/calamares/DebugWindow.cpp | 6 ++++++ src/calamares/DebugWindow.h | 1 + src/calamares/calamares-sidebar.qml | 25 +++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 0a5014fef..c37ad97d7 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -32,6 +32,8 @@ #include #include #ifdef WITH_QML +#include +#include #include #include #endif @@ -240,7 +242,7 @@ setDimension( QQuickWidget* w, Qt::Orientation o, int desiredWidth ) static QWidget* -getQmlSidebar( Calamares::DebugWindowManager*, +getQmlSidebar( Calamares::DebugWindowManager* debug, Calamares::ViewManager*, QWidget* parent, Qt::Orientation o, @@ -248,6 +250,11 @@ getQmlSidebar( Calamares::DebugWindowManager*, { CalamaresUtils::registerQmlModels(); QQuickWidget* w = new QQuickWidget( parent ); + if ( debug ) + { + w->engine()->rootContext()->setContextProperty( "debug", debug ); + } + w->setSource( QUrl( CalamaresUtils::searchQmlFile( CalamaresUtils::QmlSearch::Both, QStringLiteral( "calamares-sidebar" ) ) ) ); setDimension( w, o, desiredWidth ); @@ -255,7 +262,7 @@ getQmlSidebar( Calamares::DebugWindowManager*, } static QWidget* -getQmlNavigation( Calamares::DebugWindowManager*, +getQmlNavigation( Calamares::DebugWindowManager* debug, Calamares::ViewManager*, QWidget* parent, Qt::Orientation o, @@ -263,6 +270,10 @@ getQmlNavigation( Calamares::DebugWindowManager*, { CalamaresUtils::registerQmlModels(); QQuickWidget* w = new QQuickWidget( parent ); + if ( debug ) + { + w->engine()->rootContext()->setContextProperty( "debug", debug ); + } w->setSource( QUrl( CalamaresUtils::searchQmlFile( CalamaresUtils::QmlSearch::Both, QStringLiteral( "calamares-navigation" ) ) ) ); setDimension( w, o, desiredWidth ); diff --git a/src/calamares/DebugWindow.cpp b/src/calamares/DebugWindow.cpp index 21a044f66..ba5171437 100644 --- a/src/calamares/DebugWindow.cpp +++ b/src/calamares/DebugWindow.cpp @@ -274,5 +274,11 @@ DebugWindowManager::show( bool visible ) } } +void +DebugWindowManager::toggle() +{ + show( !m_visible ); +} + } // namespace Calamares diff --git a/src/calamares/DebugWindow.h b/src/calamares/DebugWindow.h index 7bf18364c..41d92588d 100644 --- a/src/calamares/DebugWindow.h +++ b/src/calamares/DebugWindow.h @@ -77,6 +77,7 @@ public Q_SLOTS: bool enabled() const; bool visible() const { return m_visible; } void show( bool visible ); + void toggle(); signals: void visibleChanged( bool visible ); diff --git a/src/calamares/calamares-sidebar.qml b/src/calamares/calamares-sidebar.qml index c12dd6e34..5c94fb6b2 100644 --- a/src/calamares/calamares-sidebar.qml +++ b/src/calamares/calamares-sidebar.qml @@ -1,6 +1,7 @@ /* Sample of QML progress tree. SPDX-FileCopyrightText: 2020 Adriaan de Groot + SPDX-FileCopyrightText: 2021 Anke Boersma SPDX-License-Identifier: GPL-3.0-or-later @@ -59,5 +60,29 @@ Rectangle { Item { Layout.fillHeight: true; } + + Rectangle { + Layout.fillWidth: true; + height: 35 + Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom + color: Branding.styleString( mouseArea.containsMouse ? Branding.SidebarTextHighlight : Branding.SidebarBackground); + visible: debug.enabled + + MouseArea { + id: mouseArea + anchors.fill: parent; + cursorShape: Qt.PointingHandCursor + hoverEnabled: true + Text { + anchors.verticalCenter: parent.verticalCenter; + x: parent.x + 4; + text: qsTr("Show debug information") + color: Branding.styleString( mouseArea.containsMouse ? Branding.SidebarTextSelect : Branding.SidebarBackground ); + font.pointSize : 9 + } + + onClicked: debug.toggle() + } + } } }