Skip to content

Commit 8cf88b4

Browse files
committed
Merge #11335: Replace save|restoreWindowGeometry with Qt functions
13baf72 Replace save|restoreWindowGeometry with Qt functions (MeshCollider) Pull request description: Alternative to bitcoin/bitcoin#11208, closes bitcoin/bitcoin#11207 According to the [Qt documentation](https://doc.qt.io/qt-4.8/qwidget.html#restoreGeometry), restoreGeometry does all the checks we need, so it would be better to rely on them instead of doing it ourselves. ~Haven't tested this properly yet, hence the WIP.~ Gives expected behavior exactly as the other system apps do based on my tests. Only potential issue is the case when the GUI is almost entirely offscreen with only a single strip of pixels, its not really possible to see the GUI, but if you know it's there you can bring it back onscreen with just the mouse. And that's exactly how notepad behaves on Windows so I don't think its a real issue. This also gives much better behavior when closing a maximized window, currently (0.15.0 release) a maximized window will save the window size on close, and then reopen as a not-maximized but still that size, which is really annoying. This reopens as maximized. Gitian build here: https://bitcoin.jonasschnelli.ch/build/305 Tree-SHA512: a8bde14793b4316192df1fa2eaaeb32b44d5ebc5219c35252379840056cd737a9fd162625fd715987f275fec8375334ec1ec328dbc671563f084c611a938985c
2 parents 2d85899 + 13baf72 commit 8cf88b4

File tree

4 files changed

+15
-36
lines changed

4 files changed

+15
-36
lines changed

src/qt/bitcoingui.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
123123
spinnerFrame(0),
124124
platformStyle(_platformStyle)
125125
{
126-
GUIUtil::restoreWindowGeometry("nWindow", QSize(850, 550), this);
126+
QSettings settings;
127+
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
128+
// Restore failed (perhaps missing setting), center the window
129+
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
130+
}
127131

128132
QString windowTitle = tr(PACKAGE_NAME) + " - ";
129133
#ifdef ENABLE_WALLET
@@ -261,7 +265,8 @@ BitcoinGUI::~BitcoinGUI()
261265
// Unsubscribe from notifications from core
262266
unsubscribeFromCoreSignals();
263267

264-
GUIUtil::saveWindowGeometry("nWindow", this);
268+
QSettings settings;
269+
settings.setValue("MainWindowGeometry", saveGeometry());
265270
if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
266271
trayIcon->hide();
267272
#ifdef Q_OS_MAC

src/qt/guiutil.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -862,32 +862,6 @@ bool SetStartOnSystemStartup(bool fAutoStart) { return false; }
862862

863863
#endif
864864

865-
void saveWindowGeometry(const QString& strSetting, QWidget *parent)
866-
{
867-
QSettings settings;
868-
settings.setValue(strSetting + "Pos", parent->pos());
869-
settings.setValue(strSetting + "Size", parent->size());
870-
}
871-
872-
void restoreWindowGeometry(const QString& strSetting, const QSize& defaultSize, QWidget *parent)
873-
{
874-
QSettings settings;
875-
QPoint pos = settings.value(strSetting + "Pos").toPoint();
876-
QSize size = settings.value(strSetting + "Size", defaultSize).toSize();
877-
878-
parent->resize(size);
879-
parent->move(pos);
880-
881-
if ((!pos.x() && !pos.y()) || (QApplication::desktop()->screenNumber(parent) == -1))
882-
{
883-
QRect screen = QApplication::desktop()->screenGeometry();
884-
QPoint defaultPos((screen.width() - defaultSize.width()) / 2,
885-
(screen.height() - defaultSize.height()) / 2);
886-
parent->resize(defaultSize);
887-
parent->move(defaultPos);
888-
}
889-
}
890-
891865
void setClipboard(const QString& str)
892866
{
893867
QApplication::clipboard()->setText(str, QClipboard::Clipboard);

src/qt/guiutil.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@ namespace GUIUtil
179179
bool GetStartOnSystemStartup();
180180
bool SetStartOnSystemStartup(bool fAutoStart);
181181

182-
/** Save window size and position */
183-
void saveWindowGeometry(const QString& strSetting, QWidget *parent);
184-
/** Restore window size and position */
185-
void restoreWindowGeometry(const QString& strSetting, const QSize &defaultSizeIn, QWidget *parent);
186-
187182
/* Convert QString to OS specific boost path through UTF-8 */
188183
fs::path qstringToBoostPath(const QString &path);
189184

src/qt/rpcconsole.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <wallet/wallet.h>
2929
#endif
3030

31+
#include <QDesktopWidget>
3132
#include <QKeyEvent>
3233
#include <QMenu>
3334
#include <QMessageBox>
@@ -428,7 +429,11 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
428429
consoleFontSize(0)
429430
{
430431
ui->setupUi(this);
431-
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
432+
QSettings settings;
433+
if (!restoreGeometry(settings.value("RPCConsoleWindowGeometry").toByteArray())) {
434+
// Restore failed (perhaps missing setting), center the window
435+
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
436+
}
432437

433438
ui->openDebugLogfileButton->setToolTip(ui->openDebugLogfileButton->toolTip().arg(tr(PACKAGE_NAME)));
434439

@@ -466,14 +471,14 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
466471
ui->detailWidget->hide();
467472
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
468473

469-
QSettings settings;
470474
consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(QFont()).pointSize()).toInt();
471475
clear();
472476
}
473477

474478
RPCConsole::~RPCConsole()
475479
{
476-
GUIUtil::saveWindowGeometry("nRPCConsoleWindow", this);
480+
QSettings settings;
481+
settings.setValue("RPCConsoleWindowGeometry", saveGeometry());
477482
RPCUnsetTimerInterface(rpcTimerInterface);
478483
delete rpcTimerInterface;
479484
delete ui;

0 commit comments

Comments
 (0)