From 638970d65e5009de00a12f346596e15e52cbaf6b Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Thu, 5 Dec 2024 16:32:01 -0500 Subject: [PATCH] feat: Visiblity toggle for the log on the main window --- src/apps/deskflow-gui/MainWindow.cpp | 56 ++++++++- src/apps/deskflow-gui/MainWindow.h | 3 + src/apps/deskflow-gui/MainWindow.ui | 167 ++++++++++++++++----------- src/lib/gui/config/AppConfig.cpp | 15 +++ src/lib/gui/config/AppConfig.h | 4 + 5 files changed, 174 insertions(+), 71 deletions(-) diff --git a/src/apps/deskflow-gui/MainWindow.cpp b/src/apps/deskflow-gui/MainWindow.cpp index 88680029b..f59903cb7 100644 --- a/src/apps/deskflow-gui/MainWindow.cpp +++ b/src/apps/deskflow-gui/MainWindow.cpp @@ -112,6 +112,16 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig) m_actionStartCore->setShortcut(QKeySequence(tr("Ctrl+S"))); m_actionStopCore->setShortcut(QKeySequence(tr("Ctrl+T"))); +#ifdef Q_OS_MAC + ui->btnToggleLog->setFixedHeight(ui->lblLog->font().pixelSize()); +#endif + + ui->btnToggleLog->setStyleSheet(QStringLiteral("background:rgba(0,0,0,0);")); + if (m_AppConfig.logExpanded()) + ui->btnToggleLog->click(); + + toggleLogVisible(m_AppConfig.logExpanded()); + createMenuBar(); setupControls(); connectSlots(); @@ -127,6 +137,8 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig) restoreWindow(); qDebug().noquote() << "active settings path:" << m_ConfigScopes.activeFilePath(); + + updateSize(); } MainWindow::~MainWindow() @@ -306,6 +318,8 @@ void MainWindow::connectSlots() connect(ui->rbModeServer, &QRadioButton::clicked, this, &MainWindow::setModeServer); connect(ui->rbModeClient, &QRadioButton::clicked, this, &MainWindow::setModeClient); + + connect(ui->btnToggleLog, &QAbstractButton::toggled, this, &MainWindow::toggleLogVisible); } void MainWindow::onAppAboutToQuit() @@ -315,6 +329,22 @@ void MainWindow::onAppAboutToQuit() } } +void MainWindow::toggleLogVisible(bool visible) +{ + if (visible) { + ui->btnToggleLog->setArrowType(Qt::DownArrow); + ui->textLog->setVisible(true); + m_AppConfig.setLogExpanded(true); + } else { + ui->btnToggleLog->setArrowType(Qt::RightArrow); + m_expandedSize = size(); + ui->textLog->setVisible(false); + m_AppConfig.setLogExpanded(false); + } + // 10 ms is long enough to process events and quick enough to not see the visual change. + QTimer::singleShot(10, this, &MainWindow::updateSize); +} + void MainWindow::onShown() { // if a critical error was shown just before the main window (i.e. on app @@ -465,6 +495,26 @@ void MainWindow::resetCore() m_CoreProcess.restart(); } +void MainWindow::updateSize() +{ +#ifdef Q_OS_MAC + // On mac os the titlebar is part of the height so we need to adjust our Y coord to avoid moving the window up + const auto kTitleBarOffset = 28 +#else + const auto kTitleBarOffset = 0; +#endif + if (ui->textLog->isVisible()) { + setMaximumHeight(16777215); + setMaximumWidth(16777215); + setGeometry(x(), y() + kTitleBarOffset , m_expandedSize.width(), m_expandedSize.height()); + } else { + adjustSize(); + // Prevent Resize with log collapsed + setMaximumHeight(height()); + setMaximumWidth(width()); + } +} + void MainWindow::showMyFingerprint() { QMessageBox::information(this, "TLS fingerprint", TlsFingerprint::local().readFirst()); @@ -661,18 +711,18 @@ void MainWindow::handleLogLine(const QString &line) { const int kScrollBottomThreshold = 2; - QScrollBar *verticalScroll = ui->m_pLogOutput->verticalScrollBar(); + QScrollBar *verticalScroll = ui->textLog->verticalScrollBar(); int currentScroll = verticalScroll->value(); int maxScroll = verticalScroll->maximum(); const auto scrollAtBottom = qAbs(currentScroll - maxScroll) <= kScrollBottomThreshold; // only trim end instead of the whole line to prevent tab-indented debug // filenames from losing their indentation. - ui->m_pLogOutput->appendPlainText(trimEnd(line)); + ui->textLog->appendPlainText(trimEnd(line)); if (scrollAtBottom) { verticalScroll->setValue(verticalScroll->maximum()); - ui->m_pLogOutput->horizontalScrollBar()->setValue(0); + ui->textLog->horizontalScrollBar()->setValue(0); } updateFromLogLine(line); diff --git a/src/apps/deskflow-gui/MainWindow.h b/src/apps/deskflow-gui/MainWindow.h index 621f227d7..49d8ceada 100644 --- a/src/apps/deskflow-gui/MainWindow.h +++ b/src/apps/deskflow-gui/MainWindow.h @@ -101,6 +101,7 @@ public slots: void onAppAboutToQuit(); private slots: + void toggleLogVisible(bool visible); // // Manual slots // @@ -137,6 +138,7 @@ private slots: private: std::unique_ptr ui; + void updateSize(); AppConfig &appConfig() { return m_AppConfig; @@ -200,6 +202,7 @@ private: deskflow::gui::ClientConnection m_ClientConnection; deskflow::gui::TlsUtility m_TlsUtility; QTimer m_WindowSaveTimer; + QSize m_expandedSize = QSize(); // Window Actions QAction *m_actionAbout = nullptr; diff --git a/src/apps/deskflow-gui/MainWindow.ui b/src/apps/deskflow-gui/MainWindow.ui index 66d64fba3..af2ccb217 100644 --- a/src/apps/deskflow-gui/MainWindow.ui +++ b/src/apps/deskflow-gui/MainWindow.ui @@ -6,22 +6,16 @@ 0 0 - 800 - 600 + 883 + 690 - + 0 0 - - - 750 - 550 - - Deskflow @@ -32,8 +26,17 @@ + + QLayout::SizeConstraint::SetMinAndMaxSize + + + + 0 + 0 + + This computer's name: @@ -42,7 +45,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -54,6 +57,12 @@ + + + 0 + 0 + + m_pLabelUpdate @@ -66,6 +75,12 @@ + + + 0 + 0 + + <html><head/><body><p>The highlighted IP is the one we think you should use. The server listens on all IPs, so the other IPs may work as well.</p></body></html> @@ -110,7 +125,7 @@ 15 - + @@ -154,7 +169,7 @@ - + @@ -236,7 +251,7 @@ <html><head/><body><p>TLS enabled (<a href="#"><span style=" text-decoration: underline; color:#4285f4;">fingerprint</span></a>)</p></body></html> - Qt::RichText + Qt::TextFormat::RichText 20 @@ -246,7 +261,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -261,7 +276,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -298,7 +313,7 @@ 15 - + @@ -342,7 +357,7 @@ - + @@ -410,19 +425,6 @@ - - - - Qt::Vertical - - - - 20 - 1 - - - - @@ -430,31 +432,55 @@ - - - - 0 - 0 - + + + + 0 + 0 + - - Logs + + QFrame::Shape::StyledPanel - - - 8 - - - 8 - - - 8 - - - 8 - + + QFrame::Shadow::Raised + + - + + + QLayout::SizeConstraint::SetMinAndMaxSize + + + + + ... + + + true + + + Qt::ArrowType::RightArrow + + + + + + + + 0 + 0 + + + + Log + + + + + + + 0 @@ -471,7 +497,7 @@ false - QPlainTextEdit::NoWrap + QPlainTextEdit::LineWrapMode::NoWrap true @@ -490,19 +516,13 @@ 6 - QLayout::SetDefaultConstraint + QLayout::SizeConstraint::SetDefaultConstraint true - - - - - :/icons/64x64/padlock.png - 32 @@ -515,10 +535,16 @@ 32 + + + + + :/icons/64x64/padlock.png + true - + @@ -530,7 +556,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -549,7 +575,7 @@ m_pLabelNotice - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter 0 @@ -562,10 +588,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -614,14 +640,19 @@ rbModeServer - rmModeClient lineClientIp btnConnectToClient - m_pButtonConfigureServer + btnConfigureServer + rbModeClient lineHostname btnConnect - m_pLogOutput + btnToggleLog + textLog btnApplySettings btnToggleCore + + + + diff --git a/src/lib/gui/config/AppConfig.cpp b/src/lib/gui/config/AppConfig.cpp index a95b41498..dc43b063d 100644 --- a/src/lib/gui/config/AppConfig.cpp +++ b/src/lib/gui/config/AppConfig.cpp @@ -86,6 +86,7 @@ const char *const AppConfig::m_SettingsName[] = { "", // 41 = Show dev thanks, obsolete "showCloseReminder", "enableUpdateCheck", + "logExpanded", }; AppConfig::AppConfig(deskflow::gui::IConfigScopes &scopes, std::shared_ptr deps) @@ -151,6 +152,7 @@ void AppConfig::recallFromCurrentScope() m_MainWindowSize = getFromCurrentScope(kMainWindowSize, [](const QVariant &v) { return v.toSize(); }); m_ShowCloseReminder = getFromCurrentScope(kShowCloseReminder, m_ShowCloseReminder).toBool(); m_EnableUpdateCheck = getFromCurrentScope(kEnableUpdateCheck, [](const QVariant &v) { return v.toBool(); }); + m_logExpanded = getFromCurrentScope(kLogExpanded, m_logExpanded).toBool(); } void AppConfig::recallScreenName() @@ -208,6 +210,7 @@ void AppConfig::commit() setInCurrentScope(kMainWindowPosition, m_MainWindowPosition); setInCurrentScope(kShowCloseReminder, m_ShowCloseReminder); setInCurrentScope(kEnableUpdateCheck, m_EnableUpdateCheck); + setInCurrentScope(kLogExpanded, m_logExpanded); } if (m_TlsChanged) { @@ -584,6 +587,11 @@ std::optional AppConfig::enableUpdateCheck() const return m_EnableUpdateCheck; } +bool AppConfig::logExpanded() const +{ + return m_logExpanded; +} + /////////////////////////////////////////////////////////////////////////////// // End getters /////////////////////////////////////////////////////////////////////////////// @@ -757,6 +765,13 @@ void AppConfig::setEnableUpdateCheck(bool value) m_EnableUpdateCheck = value; } +void AppConfig::setLogExpanded(bool expanded) +{ + if (expanded == m_logExpanded) + return; + m_logExpanded = expanded; +} + /////////////////////////////////////////////////////////////////////////////// // End setters /////////////////////////////////////////////////////////////////////////////// diff --git a/src/lib/gui/config/AppConfig.h b/src/lib/gui/config/AppConfig.h index 8fc077413..8d37b3529 100644 --- a/src/lib/gui/config/AppConfig.h +++ b/src/lib/gui/config/AppConfig.h @@ -109,6 +109,7 @@ private: // 41 = show dev thanks, obsolete kShowCloseReminder = 42, kEnableUpdateCheck = 43, + kLogExpanded = 44, }; public: @@ -183,6 +184,7 @@ public: std::optional mainWindowPosition() const; bool showCloseReminder() const; std::optional enableUpdateCheck() const; + bool logExpanded() const; // // Setters (overrides) @@ -223,6 +225,7 @@ public: void setMainWindowPosition(const QPoint &position); void setShowCloseReminder(bool show); void setEnableUpdateCheck(bool value); + void setLogExpanded(bool expanded); /// @brief Sets the user preference to load from SystemScope. /// @param [in] value @@ -328,6 +331,7 @@ private: bool m_LoadFromSystemScope = false; bool m_ShowCloseReminder = true; std::optional m_EnableUpdateCheck; + bool m_logExpanded = true; /** * @brief Flag is set when any TLS is setting is changed, and is reset