feat: Visiblity toggle for the log on the main window

This commit is contained in:
sithlord48
2024-12-05 16:32:01 -05:00
committed by Nick Bolton
parent 98eb89255d
commit 638970d65e
5 changed files with 174 additions and 71 deletions

View File

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

View File

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

View File

@ -6,22 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>883</width>
<height>690</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>750</width>
<height>550</height>
</size>
</property>
<property name="windowTitle">
<string>Deskflow</string>
</property>
@ -32,8 +26,17 @@
</property>
<item>
<layout class="QHBoxLayout" name="m_layoutName">
<property name="sizeConstraint">
<enum>QLayout::SizeConstraint::SetMinAndMaxSize</enum>
</property>
<item>
<widget class="QLabel" name="lblComputerName">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">This computer's name:</string>
</property>
@ -42,7 +45,7 @@
<item>
<spacer name="m_pSpacerUpdate">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -54,6 +57,12 @@
</item>
<item>
<widget class="QLabel" name="m_pLabelUpdate">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">m_pLabelUpdate</string>
</property>
@ -66,6 +75,12 @@
</item>
<item>
<widget class="QLabel" name="m_pLabelIpAddresses">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;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.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@ -110,7 +125,7 @@
<property name="spacing">
<number>15</number>
</property>
<item alignment="Qt::AlignTop">
<item alignment="Qt::AlignmentFlag::AlignTop">
<widget class="QWidget" name="m_pWidgetServerRadio" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@ -154,7 +169,7 @@
</layout>
</widget>
</item>
<item alignment="Qt::AlignTop">
<item alignment="Qt::AlignmentFlag::AlignTop">
<widget class="QWidget" name="m_pWidgetServer" native="true">
<layout class="QVBoxLayout" name="m_pLayoutServer">
<property name="spacing">
@ -236,7 +251,7 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;TLS enabled (&lt;a href=&quot;#&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#4285f4;&quot;&gt;fingerprint&lt;/span&gt;&lt;/a&gt;)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
<enum>Qt::TextFormat::RichText</enum>
</property>
<property name="indent">
<number>20</number>
@ -246,7 +261,7 @@
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -261,7 +276,7 @@
<item>
<spacer name="spacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -298,7 +313,7 @@
<property name="spacing">
<number>15</number>
</property>
<item alignment="Qt::AlignTop">
<item alignment="Qt::AlignmentFlag::AlignTop">
<widget class="QWidget" name="m_pWidgetClientRadio" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@ -342,7 +357,7 @@
</layout>
</widget>
</item>
<item alignment="Qt::AlignTop">
<item alignment="Qt::AlignmentFlag::AlignTop">
<widget class="QWidget" name="m_pWidgetClientInput" native="true">
<layout class="QVBoxLayout" name="m_pLayoutClient">
<property name="spacing">
@ -410,19 +425,6 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@ -430,31 +432,55 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="m_pGroupLog">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
<widget class="QFrame" name="frameLog">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Logs</string>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPlainTextEdit" name="m_pLogOutput">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SizeConstraint::SetMinAndMaxSize</enum>
</property>
<item>
<widget class="QToolButton" name="btnToggleLog">
<property name="text">
<string>...</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::ArrowType::RightArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblLog">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Log</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="textLog">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -471,7 +497,7 @@
<bool>false</bool>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
<enum>QPlainTextEdit::LineWrapMode::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
@ -490,19 +516,13 @@
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="m_pLabelPadlock">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../../../res/gui/deskflow.qrc">:/icons/64x64/padlock.png</pixmap>
</property>
<property name="minimumSize">
<size>
<width>32</width>
@ -515,10 +535,16 @@
<height>32</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../res/deskflow.qrc">:/icons/64x64/padlock.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QLabel" name="m_pStatusLabel">
@ -530,7 +556,7 @@
<item>
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -549,7 +575,7 @@
<string notr="true">m_pLabelNotice</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
</property>
<property name="margin">
<number>0</number>
@ -562,10 +588,10 @@
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -614,14 +640,19 @@
</customwidgets>
<tabstops>
<tabstop>rbModeServer</tabstop>
<tabstop>rmModeClient</tabstop>
<tabstop>lineClientIp</tabstop>
<tabstop>btnConnectToClient</tabstop>
<tabstop>m_pButtonConfigureServer</tabstop>
<tabstop>btnConfigureServer</tabstop>
<tabstop>rbModeClient</tabstop>
<tabstop>lineHostname</tabstop>
<tabstop>btnConnect</tabstop>
<tabstop>m_pLogOutput</tabstop>
<tabstop>btnToggleLog</tabstop>
<tabstop>textLog</tabstop>
<tabstop>btnApplySettings</tabstop>
<tabstop>btnToggleCore</tabstop>
</tabstops>
<resources>
<include location="../res/deskflow.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -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> deps)
@ -151,6 +152,7 @@ void AppConfig::recallFromCurrentScope()
m_MainWindowSize = getFromCurrentScope<QSize>(kMainWindowSize, [](const QVariant &v) { return v.toSize(); });
m_ShowCloseReminder = getFromCurrentScope(kShowCloseReminder, m_ShowCloseReminder).toBool();
m_EnableUpdateCheck = getFromCurrentScope<bool>(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<bool> 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
///////////////////////////////////////////////////////////////////////////////

View File

@ -109,6 +109,7 @@ private:
// 41 = show dev thanks, obsolete
kShowCloseReminder = 42,
kEnableUpdateCheck = 43,
kLogExpanded = 44,
};
public:
@ -183,6 +184,7 @@ public:
std::optional<QPoint> mainWindowPosition() const;
bool showCloseReminder() const;
std::optional<bool> 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<bool> m_EnableUpdateCheck;
bool m_logExpanded = true;
/**
* @brief Flag is set when any TLS is setting is changed, and is reset