refactor: New LogWidget to handle log output in the mainwindow
This commit is contained in:
parent
a6dc455477
commit
204a6b5a44
6 changed files with 81 additions and 49 deletions
|
|
@ -114,6 +114,8 @@ add_library(${target} STATIC
|
|||
widgets/FingerprintPreview.h
|
||||
widgets/KeySequenceWidget.cpp
|
||||
widgets/KeySequenceWidget.h
|
||||
widgets/LogWidget.h
|
||||
widgets/LogWidget.cpp
|
||||
widgets/NewScreenWidget.cpp
|
||||
widgets/NewScreenWidget.h
|
||||
widgets/ScreenSetupView.cpp
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@
|
|||
#include "base/String.h"
|
||||
#include "common/Settings.h"
|
||||
#include "common/UrlConstants.h"
|
||||
#include "gui/Logger.h"
|
||||
#include "gui/Messages.h"
|
||||
#include "gui/Styles.h"
|
||||
#include "gui/core/CoreProcess.h"
|
||||
#include "gui/ipc/DaemonIpcClient.h"
|
||||
#include "gui/widgets/LogWidget.h"
|
||||
#include "net/FingerprintDatabase.h"
|
||||
#include "platform/Wayland.h"
|
||||
|
||||
|
|
@ -33,6 +33,7 @@
|
|||
#include "Config.h"
|
||||
#endif
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QLocalServer>
|
||||
|
|
@ -45,6 +46,7 @@
|
|||
#include <QPushButton>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionValidator>
|
||||
#include <QScreen>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <memory>
|
||||
|
|
@ -68,6 +70,7 @@ MainWindow::MainWindow()
|
|||
m_trayIcon{new QSystemTrayIcon(this)},
|
||||
m_guiDupeChecker{new QLocalServer(this)},
|
||||
m_daemonIpcClient{new ipc::DaemonIpcClient(this)},
|
||||
m_logWidget{new LogWidget(this)},
|
||||
m_lblSecurityStatus{new QLabel(this)},
|
||||
m_lblStatus{new QLabel(this)},
|
||||
m_btnFingerprint{new QToolButton(this)},
|
||||
|
|
@ -88,13 +91,7 @@ MainWindow::MainWindow()
|
|||
|
||||
setWindowIcon(QIcon::fromTheme(QStringLiteral("deskflow")));
|
||||
|
||||
// setup the log font
|
||||
ui->textLog->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
|
||||
#ifdef Q_OS_MAC
|
||||
auto f = ui->textLog->font();
|
||||
f.setPixelSize(12);
|
||||
ui->textLog->setFont(f);
|
||||
#endif
|
||||
ui->frameLog->layout()->addWidget(m_logWidget);
|
||||
|
||||
// Setup Actions
|
||||
m_actionAbout->setText(tr("About %1...").arg(kAppName));
|
||||
|
|
@ -231,10 +228,10 @@ void MainWindow::setupControls()
|
|||
ui->btnToggleLog->setStyleSheet(kStyleFlatButton);
|
||||
if (Settings::value(Settings::Gui::LogExpanded).toBool()) {
|
||||
ui->btnToggleLog->setArrowType(Qt::DownArrow);
|
||||
ui->textLog->setVisible(true);
|
||||
m_logWidget->setVisible(true);
|
||||
ui->btnToggleLog->click();
|
||||
} else {
|
||||
ui->textLog->setVisible(false);
|
||||
m_logWidget->setVisible(false);
|
||||
}
|
||||
|
||||
ui->serverOptions->setVisible(false);
|
||||
|
|
@ -294,8 +291,6 @@ void MainWindow::setupControls()
|
|||
// signal is emitted from the thread that owns the receiver's object.
|
||||
void MainWindow::connectSlots()
|
||||
{
|
||||
connect(&Logger::instance(), &Logger::newLine, this, &MainWindow::handleLogLine);
|
||||
|
||||
connect(Settings::instance(), &Settings::serverSettingsChanged, this, &MainWindow::serverConfigSaving);
|
||||
connect(Settings::instance(), &Settings::settingsChanged, this, &MainWindow::settingsChanged);
|
||||
|
||||
|
|
@ -371,7 +366,7 @@ void MainWindow::toggleLogVisible(bool visible)
|
|||
ui->btnToggleLog->setArrowType(Qt::RightArrow);
|
||||
m_expandedSize = size();
|
||||
}
|
||||
ui->textLog->setVisible(visible);
|
||||
m_logWidget->setVisible(visible);
|
||||
Settings::setValue(Settings::Gui::LogExpanded, visible);
|
||||
// 15 ms delay is to make sure we have left the function before calling updateSize
|
||||
QTimer::singleShot(15, this, &MainWindow::updateSize);
|
||||
|
|
@ -810,21 +805,7 @@ void MainWindow::setIcon()
|
|||
|
||||
void MainWindow::handleLogLine(const QString &line)
|
||||
{
|
||||
const int kScrollBottomThreshold = 2;
|
||||
|
||||
QScrollBar *verticalScroll = ui->textLog->verticalScrollBar();
|
||||
int currentScroll = verticalScroll->value();
|
||||
int maxScroll = verticalScroll->maximum();
|
||||
const auto scrollAtBottom = qAbs(currentScroll - maxScroll) <= kScrollBottomThreshold;
|
||||
|
||||
// Never trim the log line; doing so would hide underlying bugs where newlines and space is added unintentionally.
|
||||
ui->textLog->appendPlainText(line);
|
||||
|
||||
if (scrollAtBottom) {
|
||||
verticalScroll->setValue(verticalScroll->maximum());
|
||||
ui->textLog->horizontalScrollBar()->setValue(0);
|
||||
}
|
||||
|
||||
m_logWidget->appendLine(line);
|
||||
updateFromLogLine(line);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ class QAbstractButton;
|
|||
class QLocalServer;
|
||||
|
||||
class DeskflowApplication;
|
||||
class LogWidget;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
|
@ -185,6 +186,7 @@ private:
|
|||
QLocalServer *m_guiDupeChecker = nullptr;
|
||||
deskflow::gui::ipc::DaemonIpcClient *m_daemonIpcClient = nullptr;
|
||||
|
||||
LogWidget *m_logWidget = nullptr;
|
||||
QLabel *m_lblSecurityStatus = nullptr;
|
||||
QLabel *m_lblStatus = nullptr;
|
||||
QToolButton *m_btnFingerprint = nullptr;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>758</width>
|
||||
<height>466</height>
|
||||
<height>259</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
|
@ -523,25 +523,6 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="textLog">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QPlainTextEdit::LineWrapMode::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="maximumBlockCount">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -551,7 +532,6 @@
|
|||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>btnToggleLog</tabstop>
|
||||
<tabstop>textLog</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
|||
41
src/lib/gui/widgets/LogWidget.cpp
Normal file
41
src/lib/gui/widgets/LogWidget.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "LogWidget.h"
|
||||
|
||||
#include <gui/Logger.h>
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
LogWidget::LogWidget(QWidget *parent) : QWidget{parent}, m_textLog{new QPlainTextEdit(this)}
|
||||
{
|
||||
m_textLog->setReadOnly(true);
|
||||
m_textLog->setMaximumBlockCount(10000);
|
||||
m_textLog->setLineWrapMode(QPlainTextEdit::NoWrap);
|
||||
|
||||
// setup the log font
|
||||
m_textLog->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
|
||||
#ifdef Q_OS_MAC
|
||||
auto f = m_textLog->font();
|
||||
f.setPixelSize(12);
|
||||
m_textLog->setFont(f);
|
||||
#endif
|
||||
auto layout = new QVBoxLayout;
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(m_textLog);
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
connect(
|
||||
&deskflow::gui::Logger::instance(), &deskflow::gui::Logger::newLine, m_textLog, &QPlainTextEdit::appendPlainText
|
||||
);
|
||||
}
|
||||
|
||||
void LogWidget::appendLine(const QString &msg)
|
||||
{
|
||||
m_textLog->appendPlainText(msg);
|
||||
}
|
||||
26
src/lib/gui/widgets/LogWidget.h
Normal file
26
src/lib/gui/widgets/LogWidget.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
class QPlainTextEdit;
|
||||
class QTemporaryFile;
|
||||
|
||||
class LogWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LogWidget(QWidget *parent = nullptr);
|
||||
void appendLine(const QString &msg);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
private:
|
||||
QPlainTextEdit *m_textLog = nullptr;
|
||||
};
|
||||
Loading…
Reference in a new issue