Merge branch 'work/adridg/improve-log-window' into calamares
This commit is contained in:
commit
05468016a1
@ -94,7 +94,12 @@ ExecutionViewStep::ExecutionViewStep( QObject* parent )
|
||||
bottomLayout->addWidget( m_label );
|
||||
|
||||
QToolBar* toolBar = new QToolBar;
|
||||
auto toggleLogAction = toolBar->addAction( QIcon::fromTheme( "utilities-terminal" ), "Toggle log" );
|
||||
const auto logButtonIcon = QIcon::fromTheme( "utilities-terminal" );
|
||||
auto toggleLogAction = toolBar->addAction(
|
||||
Branding::instance()->image(
|
||||
{ "utilities-log-viewer", "utilities-terminal", "text-x-log", "text-x-changelog", "preferences-log" },
|
||||
QSize( 32, 32 ) ),
|
||||
"Toggle log" );
|
||||
auto toggleLogButton = dynamic_cast< QToolButton* >( toolBar->widgetForAction( toggleLogAction ) );
|
||||
connect( toggleLogButton, &QToolButton::clicked, this, &ExecutionViewStep::toggleLog );
|
||||
|
||||
@ -228,12 +233,22 @@ ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message )
|
||||
void
|
||||
ExecutionViewStep::toggleLog()
|
||||
{
|
||||
m_tab_widget->setCurrentIndex( ( m_tab_widget->currentIndex() + 1 ) % m_tab_widget->count() );
|
||||
const bool logBecomesVisible = m_tab_widget->currentIndex() == 0; // ie. is not visible right now
|
||||
if ( logBecomesVisible )
|
||||
{
|
||||
m_log_widget->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log_widget->stop();
|
||||
}
|
||||
m_tab_widget->setCurrentIndex( logBecomesVisible ? 1 : 0 );
|
||||
}
|
||||
|
||||
void
|
||||
ExecutionViewStep::onLeave()
|
||||
{
|
||||
m_log_widget->stop();
|
||||
m_slideshow->changeSlideShowState( Slideshow::Stop );
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,18 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2022 Bob van der Linden <bobvanderlinden@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "LogWidget.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QScrollBar>
|
||||
#include <QStackedLayout>
|
||||
#include <QTextStream>
|
||||
#include <QThread>
|
||||
@ -61,6 +73,7 @@ LogWidget::LogWidget( QWidget* parent )
|
||||
setLayout( layout );
|
||||
|
||||
m_text->setReadOnly( true );
|
||||
m_text->setVerticalScrollBarPolicy( Qt::ScrollBarPolicy::ScrollBarAlwaysOn );
|
||||
|
||||
QFont monospaceFont( "monospace" );
|
||||
monospaceFont.setStyleHint( QFont::Monospace );
|
||||
@ -70,6 +83,7 @@ LogWidget::LogWidget( QWidget* parent )
|
||||
|
||||
connect( &m_log_thread, &LogThread::onLogChunk, this, &LogWidget::handleLogChunk );
|
||||
|
||||
m_log_thread.setPriority( QThread::LowestPriority );
|
||||
m_log_thread.start();
|
||||
}
|
||||
|
||||
@ -77,8 +91,23 @@ void
|
||||
LogWidget::handleLogChunk( const QString& logChunk )
|
||||
{
|
||||
m_text->appendPlainText( logChunk );
|
||||
m_text->moveCursor( QTextCursor::End );
|
||||
m_text->ensureCursorVisible();
|
||||
}
|
||||
|
||||
void
|
||||
LogWidget::start()
|
||||
{
|
||||
if ( !m_log_thread.isRunning() )
|
||||
{
|
||||
m_text->clear();
|
||||
m_log_thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LogWidget::stop()
|
||||
{
|
||||
m_log_thread.requestInterruption();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Calamares
|
||||
|
@ -1,3 +1,12 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2022 Bob van der Linden <bobvanderlinden@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LIBCALAMARESUI_LOGWIDGET_H
|
||||
#define LIBCALAMARESUI_LOGWIDGET_H
|
||||
|
||||
@ -18,7 +27,7 @@ public:
|
||||
explicit LogThread( QObject* parent = nullptr );
|
||||
~LogThread() override;
|
||||
|
||||
signals:
|
||||
Q_SIGNALS:
|
||||
void onLogChunk( const QString& logChunk );
|
||||
};
|
||||
|
||||
@ -32,7 +41,14 @@ class LogWidget : public QWidget
|
||||
public:
|
||||
explicit LogWidget( QWidget* parent = nullptr );
|
||||
|
||||
public Q_SLOTS:
|
||||
/// @brief Called by the thread when there is new data
|
||||
void handleLogChunk( const QString& logChunk );
|
||||
|
||||
/// @brief Stop watching for log data
|
||||
void stop();
|
||||
/// @brief Start watching for new log data
|
||||
void start();
|
||||
};
|
||||
|
||||
} // namespace Calamares
|
||||
|
Loading…
Reference in New Issue
Block a user