Browse Source

Bitcoin-Qt: save and restore position of debug window

- move the code for saving and restoring window positions from BitcoinGUI
  to GUIUtil, make it more generic and also use it for saving/restoring
  debug window positions
0.10
Philip Kaufmann 12 years ago
parent
commit
c431e9f1f0
  1. 28
      src/qt/bitcoingui.cpp
  2. 4
      src/qt/bitcoingui.h
  3. 25
      src/qt/guiutil.cpp
  4. 5
      src/qt/guiutil.h
  5. 2
      src/qt/rpcconsole.cpp

28
src/qt/bitcoingui.cpp

@ -49,8 +49,6 @@
#endif #endif
#include <QMimeData> #include <QMimeData>
#include <QStyle> #include <QStyle>
#include <QSettings>
#include <QDesktopWidget>
#include <QListWidget> #include <QListWidget>
#include <iostream> #include <iostream>
@ -68,7 +66,7 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
rpcConsole(0), rpcConsole(0),
prevBlocks(0) prevBlocks(0)
{ {
restoreWindowGeometry(); GUIUtil::restoreWindowGeometry("nWindow", QSize(850, 550), this);
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
if (!fIsTestnet) if (!fIsTestnet)
@ -166,7 +164,7 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
BitcoinGUI::~BitcoinGUI() BitcoinGUI::~BitcoinGUI()
{ {
saveWindowGeometry(); GUIUtil::saveWindowGeometry("nWindow", this);
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
@ -425,28 +423,6 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
} }
#endif #endif
void BitcoinGUI::saveWindowGeometry()
{
QSettings settings;
settings.setValue("nWindowPos", pos());
settings.setValue("nWindowSize", size());
}
void BitcoinGUI::restoreWindowGeometry()
{
QSettings settings;
QPoint pos = settings.value("nWindowPos").toPoint();
QSize size = settings.value("nWindowSize", QSize(850, 550)).toSize();
if (!pos.x() && !pos.y())
{
QRect screen = QApplication::desktop()->screenGeometry();
pos.setX((screen.width()-size.width())/2);
pos.setY((screen.height()-size.height())/2);
}
resize(size);
move(pos);
}
void BitcoinGUI::optionsClicked() void BitcoinGUI::optionsClicked()
{ {
if(!clientModel || !clientModel->getOptionsModel()) if(!clientModel || !clientModel->getOptionsModel())

4
src/qt/bitcoingui.h

@ -122,10 +122,6 @@ private:
void createTrayIcon(bool fIsTestnet); void createTrayIcon(bool fIsTestnet);
/** Create system tray menu (or setup the dock menu) */ /** Create system tray menu (or setup the dock menu) */
void createTrayIconMenu(); void createTrayIconMenu();
/** Save window size and position */
void saveWindowGeometry();
/** Restore window size and position */
void restoreWindowGeometry();
public slots: public slots:
/** Set number of connections shown in the UI */ /** Set number of connections shown in the UI */

25
src/qt/guiutil.cpp

@ -24,6 +24,8 @@
#include <QFileDialog> #include <QFileDialog>
#include <QDesktopServices> #include <QDesktopServices>
#include <QThread> #include <QThread>
#include <QSettings>
#include <QDesktopWidget>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -487,6 +489,29 @@ 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();
if (!pos.x() && !pos.y()) {
QRect screen = QApplication::desktop()->screenGeometry();
pos.setX((screen.width() - size.width()) / 2);
pos.setY((screen.height() - size.height()) / 2);
}
parent->resize(size);
parent->move(pos);
}
HelpMessageBox::HelpMessageBox(QWidget *parent) : HelpMessageBox::HelpMessageBox(QWidget *parent) :
QMessageBox(parent) QMessageBox(parent)
{ {

5
src/qt/guiutil.h

@ -96,6 +96,11 @@ 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);
/** Help message for Bitcoin-Qt, shown with --help. */ /** Help message for Bitcoin-Qt, shown with --help. */
class HelpMessageBox : public QMessageBox class HelpMessageBox : public QMessageBox
{ {

2
src/qt/rpcconsole.cpp

@ -187,6 +187,7 @@ RPCConsole::RPCConsole(QWidget *parent) :
historyPtr(0) historyPtr(0)
{ {
ui->setupUi(this); ui->setupUi(this);
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
ui->openDebugLogfileButton->setIcon(QIcon(":/icons/export")); ui->openDebugLogfileButton->setIcon(QIcon(":/icons/export"));
@ -209,6 +210,7 @@ RPCConsole::RPCConsole(QWidget *parent) :
RPCConsole::~RPCConsole() RPCConsole::~RPCConsole()
{ {
GUIUtil::saveWindowGeometry("nRPCConsoleWindow", this);
emit stopExecutor(); emit stopExecutor();
delete ui; delete ui;
} }

Loading…
Cancel
Save