Skip to content

Commit b6e7a4b

Browse files
laanwjcodablock
authored andcommitted
Merge bitcoin#11335: Replace save|restoreWindowGeometry with Qt functions
13baf72 Replace save|restoreWindowGeometry with Qt functions (MeshCollider) Pull request description: Alternative to bitcoin#11208, closes 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
1 parent 61c5fb9 commit b6e7a4b

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
@@ -133,7 +133,11 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
133133
/* Open CSS when configured */
134134
this->setStyleSheet(GUIUtil::loadStyleSheet());
135135

136-
GUIUtil::restoreWindowGeometry("nWindow", QSize(850, 550), this);
136+
QSettings settings;
137+
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
138+
// Restore failed (perhaps missing setting), center the window
139+
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
140+
}
137141

138142
QString windowTitle = tr(PACKAGE_NAME) + " - ";
139143
#ifdef ENABLE_WALLET
@@ -278,7 +282,8 @@ BitcoinGUI::~BitcoinGUI()
278282
// Unsubscribe from notifications from core
279283
unsubscribeFromCoreSignals();
280284

281-
GUIUtil::saveWindowGeometry("nWindow", this);
285+
QSettings settings;
286+
settings.setValue("MainWindowGeometry", saveGeometry());
282287
if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
283288
trayIcon->hide();
284289
#ifdef Q_OS_MAC

src/qt/guiutil.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -867,32 +867,6 @@ void migrateQtSettings()
867867
}
868868
}
869869

870-
void saveWindowGeometry(const QString& strSetting, QWidget *parent)
871-
{
872-
QSettings settings;
873-
settings.setValue(strSetting + "Pos", parent->pos());
874-
settings.setValue(strSetting + "Size", parent->size());
875-
}
876-
877-
void restoreWindowGeometry(const QString& strSetting, const QSize& defaultSize, QWidget *parent)
878-
{
879-
QSettings settings;
880-
QPoint pos = settings.value(strSetting + "Pos").toPoint();
881-
QSize size = settings.value(strSetting + "Size", defaultSize).toSize();
882-
883-
parent->resize(size);
884-
parent->move(pos);
885-
886-
if ((!pos.x() && !pos.y()) || (QApplication::desktop()->screenNumber(parent) == -1))
887-
{
888-
QRect screen = QApplication::desktop()->screenGeometry();
889-
QPoint defaultPos = screen.center() -
890-
QPoint(defaultSize.width() / 2, defaultSize.height() / 2);
891-
parent->resize(defaultSize);
892-
parent->move(defaultPos);
893-
}
894-
}
895-
896870
// Return name of current UI-theme or default theme if no theme was found
897871
QString getThemeName()
898872
{

src/qt/guiutil.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ namespace GUIUtil
185185
/** Modify Qt network specific settings on migration */
186186
void migrateQtSettings();
187187

188-
/** Save window size and position */
189-
void saveWindowGeometry(const QString& strSetting, QWidget *parent);
190-
/** Restore window size and position */
191-
void restoreWindowGeometry(const QString& strSetting, const QSize &defaultSizeIn, QWidget *parent);
192-
193188
/** Load global CSS theme */
194189
QString loadStyleSheet();
195190

src/qt/rpcconsole.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#endif
3131

3232
#include <QDir>
33+
#include <QDesktopWidget>
3334
#include <QKeyEvent>
3435
#include <QMenu>
3536
#include <QMessageBox>
@@ -439,7 +440,11 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
439440
consoleFontSize(0)
440441
{
441442
ui->setupUi(this);
442-
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
443+
QSettings settings;
444+
if (!restoreGeometry(settings.value("RPCConsoleWindowGeometry").toByteArray())) {
445+
// Restore failed (perhaps missing setting), center the window
446+
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
447+
}
443448

444449
ui->openDebugLogfileButton->setToolTip(ui->openDebugLogfileButton->toolTip().arg(tr(PACKAGE_NAME)));
445450

@@ -491,14 +496,14 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
491496

492497
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
493498

494-
QSettings settings;
495499
consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(QFont()).pointSize()).toInt();
496500
clear();
497501
}
498502

499503
RPCConsole::~RPCConsole()
500504
{
501-
GUIUtil::saveWindowGeometry("nRPCConsoleWindow", this);
505+
QSettings settings;
506+
settings.setValue("RPCConsoleWindowGeometry", saveGeometry());
502507
RPCUnsetTimerInterface(rpcTimerInterface);
503508
delete rpcTimerInterface;
504509
delete ui;

0 commit comments

Comments
 (0)