Browse Source

Merge #11335: Replace save|restoreWindowGeometry with Qt functions

13baf72 Replace save|restoreWindowGeometry with Qt functions (MeshCollider)

Pull request description:

  Alternative to https://github.com/bitcoin/bitcoin/pull/11208, closes https://github.com/bitcoin/bitcoin/issues/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
0.16
Wladimir J. van der Laan 7 years ago
parent
commit
8cf88b4aae
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
  1. 9
      src/qt/bitcoingui.cpp
  2. 26
      src/qt/guiutil.cpp
  3. 5
      src/qt/guiutil.h
  4. 11
      src/qt/rpcconsole.cpp

9
src/qt/bitcoingui.cpp

@ -123,7 +123,11 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
spinnerFrame(0), spinnerFrame(0),
platformStyle(_platformStyle) platformStyle(_platformStyle)
{ {
GUIUtil::restoreWindowGeometry("nWindow", QSize(850, 550), this); QSettings settings;
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
// Restore failed (perhaps missing setting), center the window
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
}
QString windowTitle = tr(PACKAGE_NAME) + " - "; QString windowTitle = tr(PACKAGE_NAME) + " - ";
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
@ -261,7 +265,8 @@ BitcoinGUI::~BitcoinGUI()
// Unsubscribe from notifications from core // Unsubscribe from notifications from core
unsubscribeFromCoreSignals(); unsubscribeFromCoreSignals();
GUIUtil::saveWindowGeometry("nWindow", this); QSettings settings;
settings.setValue("MainWindowGeometry", saveGeometry());
if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu) if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
trayIcon->hide(); trayIcon->hide();
#ifdef Q_OS_MAC #ifdef Q_OS_MAC

26
src/qt/guiutil.cpp

@ -862,32 +862,6 @@ bool SetStartOnSystemStartup(bool fAutoStart) { return false; }
#endif #endif
void saveWindowGeometry(const QString& strSetting, QWidget *parent)
{
QSettings settings;
settings.setValue(strSetting + "Pos", parent->pos());
settings.setValue(strSetting + "Size", parent->size());
}
void restoreWindowGeometry(const QString& strSetting, const QSize& defaultSize, QWidget *parent)
{
QSettings settings;
QPoint pos = settings.value(strSetting + "Pos").toPoint();
QSize size = settings.value(strSetting + "Size", defaultSize).toSize();
parent->resize(size);
parent->move(pos);
if ((!pos.x() && !pos.y()) || (QApplication::desktop()->screenNumber(parent) == -1))
{
QRect screen = QApplication::desktop()->screenGeometry();
QPoint defaultPos((screen.width() - defaultSize.width()) / 2,
(screen.height() - defaultSize.height()) / 2);
parent->resize(defaultSize);
parent->move(defaultPos);
}
}
void setClipboard(const QString& str) void setClipboard(const QString& str)
{ {
QApplication::clipboard()->setText(str, QClipboard::Clipboard); QApplication::clipboard()->setText(str, QClipboard::Clipboard);

5
src/qt/guiutil.h

@ -179,11 +179,6 @@ namespace GUIUtil
bool GetStartOnSystemStartup(); bool GetStartOnSystemStartup();
bool SetStartOnSystemStartup(bool fAutoStart); bool SetStartOnSystemStartup(bool fAutoStart);
/** Save window size and position */
void saveWindowGeometry(const QString& strSetting, QWidget *parent);
/** Restore window size and position */
void restoreWindowGeometry(const QString& strSetting, const QSize &defaultSizeIn, QWidget *parent);
/* Convert QString to OS specific boost path through UTF-8 */ /* Convert QString to OS specific boost path through UTF-8 */
fs::path qstringToBoostPath(const QString &path); fs::path qstringToBoostPath(const QString &path);

11
src/qt/rpcconsole.cpp

@ -28,6 +28,7 @@
#include <wallet/wallet.h> #include <wallet/wallet.h>
#endif #endif
#include <QDesktopWidget>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
@ -428,7 +429,11 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
consoleFontSize(0) consoleFontSize(0)
{ {
ui->setupUi(this); ui->setupUi(this);
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this); QSettings settings;
if (!restoreGeometry(settings.value("RPCConsoleWindowGeometry").toByteArray())) {
// Restore failed (perhaps missing setting), center the window
move(QApplication::desktop()->availableGeometry().center() - frameGeometry().center());
}
ui->openDebugLogfileButton->setToolTip(ui->openDebugLogfileButton->toolTip().arg(tr(PACKAGE_NAME))); ui->openDebugLogfileButton->setToolTip(ui->openDebugLogfileButton->toolTip().arg(tr(PACKAGE_NAME)));
@ -466,14 +471,14 @@ RPCConsole::RPCConsole(const PlatformStyle *_platformStyle, QWidget *parent) :
ui->detailWidget->hide(); ui->detailWidget->hide();
ui->peerHeading->setText(tr("Select a peer to view detailed information.")); ui->peerHeading->setText(tr("Select a peer to view detailed information."));
QSettings settings;
consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(QFont()).pointSize()).toInt(); consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(QFont()).pointSize()).toInt();
clear(); clear();
} }
RPCConsole::~RPCConsole() RPCConsole::~RPCConsole()
{ {
GUIUtil::saveWindowGeometry("nRPCConsoleWindow", this); QSettings settings;
settings.setValue("RPCConsoleWindowGeometry", saveGeometry());
RPCUnsetTimerInterface(rpcTimerInterface); RPCUnsetTimerInterface(rpcTimerInterface);
delete rpcTimerInterface; delete rpcTimerInterface;
delete ui; delete ui;

Loading…
Cancel
Save