From 017d27e907004f05b7328f0c63fc25c3d01a54a9 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Tue, 20 Dec 2022 16:22:21 +0000 Subject: [PATCH] Allow maximize button to make window full screen, if already maximized. --- sdrgui/mainspectrum/mainspectrumgui.cpp | 38 ++++++++++++++++++++++--- sdrgui/mainspectrum/mainspectrumgui.h | 1 + 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/sdrgui/mainspectrum/mainspectrumgui.cpp b/sdrgui/mainspectrum/mainspectrumgui.cpp index b40f6768e..177ad49fe 100644 --- a/sdrgui/mainspectrum/mainspectrumgui.cpp +++ b/sdrgui/mainspectrum/mainspectrumgui.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "mainwindow.h" #include "gui/glspectrum.h" @@ -38,7 +39,8 @@ MainSpectrumGUI::MainSpectrumGUI(GLSpectrum *spectrum, GLSpectrumGUI *spectrumGU m_deviceType(DeviceRx), m_deviceSetIndex(0), m_drag(false), - m_resizer(this) + m_resizer(this), + m_mdi(nullptr) { qDebug("MainSpectrumGUI::MainSpectrumGUI: %p", parent); setWindowFlags(windowFlags() | Qt::FramelessWindowHint); @@ -88,7 +90,7 @@ MainSpectrumGUI::MainSpectrumGUI(GLSpectrum *spectrum, GLSpectrumGUI *spectrumGU m_maximizeButton->setFixedSize(20, 20); QIcon maximizeIcon(":/maximize.png"); m_maximizeButton->setIcon(maximizeIcon); - m_maximizeButton->setToolTip("Adjust window to maximum size"); + m_maximizeButton->setToolTip("Adjust window to maximum size in workspace"); m_hideButton = new QPushButton(); m_hideButton->setFixedSize(20, 20); @@ -260,15 +262,42 @@ void MainSpectrumGUI::openMoveToWorkspaceDialog() void MainSpectrumGUI::maximizeWindow() { - showMaximized(); + // If maximize is pressed when maximized, go full screen + if (isMaximized()) + { + m_mdi = mdiArea(); + if (m_mdi) { + m_mdi->removeSubWindow(this); + } + showNormal(); // If we don't go back to normal first, window doesn't get bigger + showFullScreen(); + m_shrinkButton->setToolTip("Adjust window to maximum size in workspace"); + } + else + { + showMaximized(); + m_shrinkButton->setToolTip("Restore window to normal"); + m_maximizeButton->setToolTip("Make window full screen"); + } } void MainSpectrumGUI::shrinkWindow() { qDebug("MainSpectrumGUI::shrinkWindow"); - if (isMaximized()) + if (m_mdi) { showNormal(); + m_mdi->addSubWindow(this); + show(); + showMaximized(); + m_shrinkButton->setToolTip("Restore window to normal"); + m_mdi = nullptr; + } + else if (isMaximized()) + { + showNormal(); + m_shrinkButton->setToolTip("Adjust window to minimum size"); + m_maximizeButton->setToolTip("Adjust window to maximum size in workspace"); } else { @@ -279,6 +308,7 @@ void MainSpectrumGUI::shrinkWindow() void MainSpectrumGUI::setTitle(const QString& title) { + setWindowTitle(title + " Spectrum"); m_titleLabel->setText(title); } diff --git a/sdrgui/mainspectrum/mainspectrumgui.h b/sdrgui/mainspectrum/mainspectrumgui.h index 159fb5a4c..bbae400ad 100644 --- a/sdrgui/mainspectrum/mainspectrumgui.h +++ b/sdrgui/mainspectrum/mainspectrumgui.h @@ -88,6 +88,7 @@ private: bool m_drag; QPoint m_DragPosition; FramelessWindowResizer m_resizer; + QMdiArea *m_mdi; // Saved pointer to MDI when in full screen mode static const int m_MinimumWidth = 380; static const int m_MinimumHeight = 200 + 20 + 10 + 6*22 + 5;