refactor: move log to dockwidget simplifying resize code
This commit is contained in:
@ -48,6 +48,7 @@
|
||||
#include <QRegularExpressionValidator>
|
||||
#include <QScreen>
|
||||
#include <QScrollBar>
|
||||
#include <QToolButton>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -91,7 +92,9 @@ MainWindow::MainWindow()
|
||||
|
||||
setWindowIcon(QIcon::fromTheme(QStringLiteral("deskflow")));
|
||||
|
||||
ui->frameLog->layout()->addWidget(m_logWidget);
|
||||
auto dockLayout = new QVBoxLayout();
|
||||
dockLayout->addWidget(m_logWidget);
|
||||
ui->dockLogContents->setLayout(dockLayout);
|
||||
|
||||
// Setup Actions
|
||||
m_actionAbout->setText(tr("About %1...").arg(kAppName));
|
||||
@ -127,10 +130,6 @@ MainWindow::MainWindow()
|
||||
|
||||
m_actionReportBug->setIcon(QIcon(QIcon::fromTheme(QStringLiteral("tools-report-bug"))));
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
ui->btnToggleLog->setFixedHeight(ui->lblLog->height() * 0.6);
|
||||
#endif
|
||||
|
||||
// Setup the Instance Checking
|
||||
// In case of a previous crash remove first
|
||||
QLocalServer::removeServer(m_guiSocketName);
|
||||
@ -148,8 +147,6 @@ MainWindow::MainWindow()
|
||||
|
||||
qDebug().noquote() << "active settings path:" << Settings::settingsPath();
|
||||
|
||||
updateSize();
|
||||
|
||||
// Force generation of SHA256 for the localhost
|
||||
if (Settings::value(Settings::Security::TlsEnabled).toBool()) {
|
||||
if (Settings::value(Settings::Security::KeySize).toInt() < 2048) {
|
||||
@ -180,34 +177,23 @@ MainWindow::~MainWindow()
|
||||
|
||||
void MainWindow::restoreWindow()
|
||||
{
|
||||
const auto windowGeometry = Settings::value(Settings::Gui::WindowGeometry).toRect();
|
||||
auto windowGeometry = Settings::value(Settings::Gui::WindowGeometry).toRect();
|
||||
const auto totalGeometry = QGuiApplication::primaryScreen()->availableGeometry();
|
||||
if (!windowGeometry.isValid()) {
|
||||
// center main window in middle of screen
|
||||
const auto screen = QGuiApplication::primaryScreen();
|
||||
QRect screenGeometry = screen->geometry();
|
||||
adjustSize();
|
||||
windowGeometry = geometry();
|
||||
} else {
|
||||
setGeometry(windowGeometry);
|
||||
}
|
||||
m_expandedSize = geometry().size();
|
||||
|
||||
if (!totalGeometry.contains(windowGeometry)) {
|
||||
QRect screenGeometry = QGuiApplication::primaryScreen()->geometry();
|
||||
move(screenGeometry.center() - rect().center());
|
||||
return;
|
||||
}
|
||||
|
||||
m_expandedSize = windowGeometry.size();
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
const auto screens = QGuiApplication::screens();
|
||||
for (auto screen : screens) {
|
||||
auto geo = screen->geometry();
|
||||
x = std::min(geo.x(), x);
|
||||
y = std::min(geo.y(), y);
|
||||
w = std::max(geo.x() + geo.width(), w);
|
||||
h = std::max(geo.y() + geo.height(), h);
|
||||
}
|
||||
const QRect screensGeometry(x, y, w, h);
|
||||
if (screensGeometry.contains(windowGeometry)) {
|
||||
qDebug() << "restoring main window position";
|
||||
move(windowGeometry.topLeft());
|
||||
}
|
||||
if (!Settings::value(Settings::Gui::LogExpanded).toBool())
|
||||
setFixedSize(size());
|
||||
}
|
||||
|
||||
void MainWindow::setupControls()
|
||||
@ -224,14 +210,8 @@ void MainWindow::setupControls()
|
||||
Settings::setValue(Settings::Core::LastVersion, kVersion);
|
||||
}
|
||||
|
||||
// Setup the log toggle, set its initial state to closed
|
||||
ui->btnToggleLog->setStyleSheet(kStyleFlatButton);
|
||||
if (Settings::value(Settings::Gui::LogExpanded).toBool()) {
|
||||
ui->btnToggleLog->setArrowType(Qt::DownArrow);
|
||||
m_logWidget->setVisible(true);
|
||||
ui->btnToggleLog->click();
|
||||
} else {
|
||||
m_logWidget->setVisible(false);
|
||||
if (!Settings::value(Settings::Gui::LogExpanded).toBool()) {
|
||||
ui->dockLog->hide();
|
||||
}
|
||||
|
||||
ui->serverOptions->setVisible(false);
|
||||
@ -347,7 +327,7 @@ void MainWindow::connectSlots()
|
||||
connect(ui->rbModeServer, &QRadioButton::toggled, this, &MainWindow::coreModeToggled);
|
||||
connect(ui->rbModeClient, &QRadioButton::toggled, this, &MainWindow::coreModeToggled);
|
||||
|
||||
connect(ui->btnToggleLog, &QAbstractButton::toggled, this, &MainWindow::toggleLogVisible);
|
||||
connect(ui->dockLog->toggleViewAction(), &QAction::toggled, this, &MainWindow::toggleLogVisible);
|
||||
|
||||
connect(m_btnUpdate, &QPushButton::clicked, this, &MainWindow::openGetNewVersionUrl);
|
||||
|
||||
@ -360,16 +340,17 @@ void MainWindow::connectSlots()
|
||||
|
||||
void MainWindow::toggleLogVisible(bool visible)
|
||||
{
|
||||
if (visible) {
|
||||
ui->btnToggleLog->setArrowType(Qt::DownArrow);
|
||||
} else {
|
||||
ui->btnToggleLog->setArrowType(Qt::RightArrow);
|
||||
m_expandedSize = size();
|
||||
}
|
||||
m_logWidget->setVisible(visible);
|
||||
setFixedSize(16777215, 16777215);
|
||||
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);
|
||||
if (visible) {
|
||||
setGeometry(x(), y(), m_expandedSize.width(), m_expandedSize.height());
|
||||
} else {
|
||||
m_expandedSize = geometry().size();
|
||||
ui->dockLog->hide();
|
||||
adjustSize();
|
||||
setFixedSize(size());
|
||||
}
|
||||
Settings::setValue(Settings::Gui::WindowGeometry, geometry());
|
||||
}
|
||||
|
||||
void MainWindow::settingsChanged(const QString &key)
|
||||
@ -506,18 +487,6 @@ void MainWindow::resetCore()
|
||||
m_coreProcess.restart();
|
||||
}
|
||||
|
||||
void MainWindow::updateSize()
|
||||
{
|
||||
if (Settings::value(Settings::Gui::LogExpanded).toBool()) {
|
||||
setMaximumSize(16777215, 16777215);
|
||||
resize(m_expandedSize);
|
||||
} else {
|
||||
adjustSize();
|
||||
// Prevent Resize with log collapsed
|
||||
setMaximumSize(width(), height());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showMyFingerprint()
|
||||
{
|
||||
FingerprintDialog fingerprintDialog(this, localFingerprint());
|
||||
@ -728,6 +697,9 @@ void MainWindow::createMenuBar()
|
||||
auto menuEdit = new QMenu(tr("&Edit"), this);
|
||||
menuEdit->addAction(m_actionSettings);
|
||||
|
||||
auto menuView = new QMenu(tr("&View"), this);
|
||||
menuView->addAction(ui->dockLog->toggleViewAction());
|
||||
|
||||
auto menuHelp = new QMenu(tr("&Help"), this);
|
||||
menuHelp->addAction(m_actionAbout);
|
||||
menuHelp->addAction(m_actionReportBug);
|
||||
@ -737,6 +709,7 @@ void MainWindow::createMenuBar()
|
||||
auto menuBar = new QMenuBar(this);
|
||||
menuBar->addMenu(menuFile);
|
||||
menuBar->addMenu(menuEdit);
|
||||
menuBar->addMenu(menuView);
|
||||
menuBar->addMenu(menuHelp);
|
||||
|
||||
setMenuBar(menuBar);
|
||||
@ -899,6 +872,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||
Settings::setValue(Settings::Gui::WindowGeometry, geometry());
|
||||
}
|
||||
qDebug() << "quitting application";
|
||||
|
||||
// any connected dock view acitons will be triggered
|
||||
// disconnect them before accepting the event
|
||||
disconnect(ui->dockLog->toggleViewAction(), &QAction::toggled, nullptr, nullptr);
|
||||
|
||||
event->accept();
|
||||
QApplication::quit();
|
||||
}
|
||||
|
||||
@ -122,7 +122,6 @@ private:
|
||||
void updateModeControlLabels();
|
||||
std::unique_ptr<Ui::MainWindow> ui;
|
||||
|
||||
void updateSize();
|
||||
void createMenuBar();
|
||||
void setupTrayIcon();
|
||||
void applyConfig();
|
||||
|
||||
@ -7,19 +7,19 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>758</width>
|
||||
<height>259</height>
|
||||
<height>305</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Deskflow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="topLevelWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="_2">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
@ -465,74 +465,25 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frameLog">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="_4">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SizeConstraint::SetMinAndMaxSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnToggleLog">
|
||||
<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>
|
||||
<item>
|
||||
<spacer name="spacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<widget class="QDockWidget" name="dockLog">
|
||||
<property name="features">
|
||||
<set>QDockWidget::DockWidgetFeature::DockWidgetClosable</set>
|
||||
</property>
|
||||
<property name="allowedAreas">
|
||||
<set>Qt::DockWidgetArea::BottomDockWidgetArea</set>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Log</string>
|
||||
</property>
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>8</number>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockLogContents"/>
|
||||
</widget>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>btnToggleLog</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user