From f0cb5273702a9b09a1775eda616f713263806e06 Mon Sep 17 00:00:00 2001 From: Nikita Zimin Date: Wed, 3 Jan 2024 18:17:55 +0300 Subject: [PATCH] Hack for restoring maximized window --- emulator/mainwindow.cpp | 18 +++++++++++++----- emulator/qkeyboardview.cpp | 2 +- emulator/qscreen.cpp | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/emulator/mainwindow.cpp b/emulator/mainwindow.cpp index bbc8278..a1b341b 100644 --- a/emulator/mainwindow.cpp +++ b/emulator/mainwindow.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -207,9 +208,11 @@ void MainWindow::changeEvent(QEvent *e) } } -void MainWindow::closeEvent(QCloseEvent *) +void MainWindow::closeEvent(QCloseEvent * event) { saveSettings(Global_getSettings()); + + QMainWindow::closeEvent(event); } void MainWindow::saveSettings(QSettings * settings) @@ -233,12 +236,17 @@ void MainWindow::restoreSettings(QSettings * settings) int scrViewMode = Global_getSettings()->value("MainWindow/ScreenMode").toInt(); m_screen->setMode(scrViewMode); - //Update centralWidget size + // Update centralWidget size ui->centralWidget->setMaximumHeight(m_screen->maximumHeight() + m_keyboard->maximumHeight()); - ui->centralWidget->setMaximumWidth(m_screen->maximumWidth()); + int maxwid = m_screen->maximumWidth() > m_keyboard->maximumWidth() ? m_screen->maximumWidth() : m_keyboard->maximumWidth(); + ui->centralWidget->setMaximumWidth(maxwid); - restoreGeometry(settings->value("MainWindow/Geometry").toByteArray()); - restoreState(settings->value("MainWindow/WindowState").toByteArray()); + QByteArray geometry = Global_getSettings()->value("MainWindow/Geometry").toByteArray(); + if (!geometry.isEmpty()) + restoreGeometry(geometry); + if (isMaximized()) //HACK for restoring maximized window, see https://bugreports.qt.io/browse/QTBUG-46620 + setGeometry(QApplication::desktop()->availableGeometry(this)); + restoreState(Global_getSettings()->value("MainWindow/WindowState").toByteArray()); m_keyboard->setVisible(settings->value("MainWindow/KeyboardView", true).toBool()); m_dockConsole->setVisible(settings->value("MainWindow/ConsoleView", false).toBool()); diff --git a/emulator/qkeyboardview.cpp b/emulator/qkeyboardview.cpp index bedc6d4..4359b0d 100644 --- a/emulator/qkeyboardview.cpp +++ b/emulator/qkeyboardview.cpp @@ -102,7 +102,7 @@ QKeyboardView::QKeyboardView(QWidget *parent) : m_nKeyPressedScan = m_nKeyPressedCode = 0; setMinimumSize(551 + 8, 216 + 8); - setMaximumSize(904, 216 + 20); + setMaximumSize(1024, 216 + 24); } void QKeyboardView::paintEvent(QPaintEvent *) diff --git a/emulator/qscreen.cpp b/emulator/qscreen.cpp index b69677f..b922c0a 100644 --- a/emulator/qscreen.cpp +++ b/emulator/qscreen.cpp @@ -50,7 +50,7 @@ void QEmulatorScreen::createDisplay() m_image = new QImage(cxScreenWidth, cyScreenHeight, QImage::Format_RGB32); setMinimumSize(cxScreenWidth + 8, cyScreenHeight + 8); - setMaximumSize(cxScreenWidth + 100, cyScreenHeight + 20); + setMaximumSize(std::max(cxScreenWidth + 100, 1024), cyScreenHeight + 24); } void QEmulatorScreen::paintEvent(QPaintEvent * /*event*/)