-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1890 from srcejon/fix_1835
Fix MDI window geometry save/restore
- Loading branch information
Showing
6 changed files
with
145 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
// Copyright (C) 2023 Jon Beniston, M7RCE // | ||
// // | ||
// This program is free software; you can redistribute it and/or modify // | ||
// it under the terms of the GNU General Public License as published by // | ||
// the Free Software Foundation as version 3 of the License, or // | ||
// (at your option) any later version. // | ||
// // | ||
// This program is distributed in the hope that it will be useful, // | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of // | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | ||
// GNU General Public License V3 for more details. // | ||
// // | ||
// You should have received a copy of the GNU General Public License // | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. // | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include <QWidget> | ||
#include <QDebug> | ||
#include <QDataStream> | ||
|
||
#include "mdiutils.h" | ||
|
||
// QWidget::save/restoreGeometry doesn't work properly for MDI sub-windows | ||
// so we have this code | ||
|
||
QByteArray MDIUtils::saveMDIGeometry(QWidget *widget) | ||
{ | ||
QByteArray array; | ||
QDataStream stream(&array, QIODevice::WriteOnly); | ||
quint16 version = 1; | ||
stream << version | ||
<< widget->x() | ||
<< widget->y() | ||
<< widget->width() | ||
<< widget->height() | ||
<< widget->isMaximized() | ||
<< widget->isFullScreen(); | ||
return array; | ||
} | ||
|
||
bool MDIUtils::restoreMDIGeometry(QWidget *widget, const QByteArray& geometry) | ||
{ | ||
if (geometry.size() == 66) | ||
{ | ||
// Older versions of SDRangel used save/restoreGeometry | ||
return widget->restoreGeometry(geometry); | ||
} | ||
else if (geometry.size() < 4) | ||
{ | ||
qDebug() << "MDIUtils::restoreMDIGeometry: geometry is invalid"; | ||
return false; | ||
} | ||
else | ||
{ | ||
QDataStream stream(geometry); | ||
quint16 version = 0; | ||
stream >> version; | ||
if (version != 1) | ||
{ | ||
qDebug() << "MDIUtils::restoreMDIGeometry: Unsupported version" << version; | ||
return false; | ||
} | ||
|
||
// Restore window position | ||
qint32 x, y, width, height; | ||
stream >> x >> y >> width >> height; | ||
widget->move(x, y); | ||
widget->resize(width, height); | ||
|
||
// Restore window state | ||
// After restoring the geometry for a number of MDI windows, if one was maximized | ||
// but not the last to have geometry restored for, we end up with the wrong | ||
// window being maximized, so we don't bother trying for now | ||
bool maximized, fullscreen; | ||
stream >> maximized >> fullscreen; | ||
/*if (fullscreen) { | ||
widget->showFullScreen(); | ||
} else if (maximized) { | ||
widget->showMaximized(); | ||
} else { | ||
widget->showNormal(); | ||
}*/ | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
// Copyright (C) 2023 Jon Beniston, M7RCE // | ||
// // | ||
// This program is free software; you can redistribute it and/or modify // | ||
// it under the terms of the GNU General Public License as published by // | ||
// the Free Software Foundation as version 3 of the License, or // | ||
// (at your option) any later version. // | ||
// // | ||
// This program is distributed in the hope that it will be useful, // | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of // | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | ||
// GNU General Public License V3 for more details. // | ||
// // | ||
// You should have received a copy of the GNU General Public License // | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. // | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifndef SDRGUI_GUI_MDIUTILS_H | ||
#define SDRGUI_GUI_MDIUTILS_H | ||
|
||
#include <QByteArray> | ||
|
||
#include "export.h" | ||
|
||
class QWidget; | ||
|
||
class SDRGUI_API MDIUtils { | ||
|
||
public: | ||
|
||
static QByteArray saveMDIGeometry(QWidget *widget); | ||
static bool restoreMDIGeometry(QWidget *widget, const QByteArray& geometry); | ||
|
||
}; | ||
|
||
#endif // SDRGUI_GUI_MDIUTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters