diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 75ab4dbd7..70f638b88 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -102,7 +102,7 @@ /** Constructor */ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) - : QMainWindow(parent, flags) + : RWindow("MainWindow", parent, flags) { /* Invoke the Qt Designer generated QObject setup routine */ ui.setupUi(this); diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index 467d43bb5..1dc6dad26 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -59,7 +59,7 @@ class SMPlayer; class PeerStatus; -class MainWindow : public QMainWindow +class MainWindow : public RWindow { Q_OBJECT diff --git a/retroshare-gui/src/gui/Preferences/GeneralDialog.cpp b/retroshare-gui/src/gui/Preferences/GeneralDialog.cpp index 7908edc28..6eba15039 100644 --- a/retroshare-gui/src/gui/Preferences/GeneralDialog.cpp +++ b/retroshare-gui/src/gui/Preferences/GeneralDialog.cpp @@ -22,6 +22,7 @@ #include "rshare.h" #include "GeneralDialog.h" +#include #include /** Constructor */ @@ -60,9 +61,7 @@ GeneralDialog::~GeneralDialog() /** Saves the changes on this page */ bool GeneralDialog::save(QString &errmsg) -{ - Q_UNUSED(errmsg); - +{ _settings->setValue(QString::fromUtf8("StartMinimized"), startMinimized()); _settings->setRunRetroshareOnBoot( @@ -74,11 +73,9 @@ GeneralDialog::save(QString &errmsg) /** Loads the settings for this page */ void GeneralDialog::load() -{ - +{ ui.chkRunRetroshareAtSystemStartup->setChecked( _settings->runRetroshareOnBoot()); - ui.checkStartMinimized->setChecked(_settings->value(QString::fromUtf8("StartMinimized"), false).toBool()); diff --git a/retroshare-gui/src/gui/Preferences/GeneralDialog.h b/retroshare-gui/src/gui/Preferences/GeneralDialog.h index 728451e91..6638260fd 100644 --- a/retroshare-gui/src/gui/Preferences/GeneralDialog.h +++ b/retroshare-gui/src/gui/Preferences/GeneralDialog.h @@ -22,6 +22,7 @@ #ifndef _GENERALDIALOG_H #define _GENERALDIALOG_H + #include #include #include @@ -54,7 +55,7 @@ private slots: private: /** A RetroShare Settings object used for saving/loading settings */ - RshareSettings* _settings; + RshareSettings *_settings; diff --git a/retroshare-gui/src/gui/common/rwindow.cpp b/retroshare-gui/src/gui/common/rwindow.cpp index be298f1e1..0278fb4f6 100644 --- a/retroshare-gui/src/gui/common/rwindow.cpp +++ b/retroshare-gui/src/gui/common/rwindow.cpp @@ -23,11 +23,11 @@ #include #include -#include #include #include #include #include +#include #include "rwindow.h" @@ -36,8 +36,7 @@ RWindow::RWindow(QString name, QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { _name = name; - _settings = new RshareSettings(); - _previouslyShown = false; + _settings = new RSettings(name); } /** Destructor. */ @@ -51,8 +50,7 @@ RWindow::~RWindow() void RWindow::setShortcut(QString shortcut, const char *slot) { - QShortcut *s = new QShortcut(QKeySequence(shortcut), this, slot, 0); - Q_UNUSED(s); + rApp->createShortcut(QKeySequence(shortcut), this, this, slot); } /** Saves the size and location of the window. */ @@ -73,7 +71,10 @@ RWindow::restoreWindowState() { #if QT_VERSION >= 0x040200 QByteArray geometry = getSetting("Geometry", QByteArray()).toByteArray(); - restoreGeometry(geometry); + if (geometry.isEmpty()) + adjustSize(); + else + restoreGeometry(geometry); #else QRect screen = QDesktopWidget().availableGeometry(); @@ -115,25 +116,14 @@ void RWindow::setVisible(bool visible) { if (visible) { - /* If this is the first time this window is shown, restore its window - * position and size. */ - if (!_previouslyShown) { -#if !defined (Q_WS_WIN) - /* Use the standard palette on non-Windows, overriding whatever was - * specified in the .ui file for this dialog. */ - setPalette(QPalette()); -#endif - - restoreWindowState(); - _previouslyShown = true; - } - /* Bring the window to the top, if it's already open. Otherwise, make the * window visible. */ if (isVisible()) { activateWindow(); setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive); raise(); + } else { + restoreWindowState(); } } else { /* Save the last size and position of this window. */ diff --git a/retroshare-gui/src/gui/common/rwindow.h b/retroshare-gui/src/gui/common/rwindow.h index 1d470b66e..0b491e83b 100644 --- a/retroshare-gui/src/gui/common/rwindow.h +++ b/retroshare-gui/src/gui/common/rwindow.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include class RWindow : public QMainWindow @@ -68,8 +68,7 @@ signals: private: QString _name; /**< Name associated with this window. */ - RshareSettings* _settings; /**< Object used to store window properties */ - bool _previouslyShown; /**< True if show() has been called for this window. */ + RSettings* _settings; /**< Object used to store window properties */ }; #endif diff --git a/retroshare-gui/src/rshare.cpp b/retroshare-gui/src/rshare.cpp index 1d56b3435..c3ece6933 100644 --- a/retroshare-gui/src/rshare.cpp +++ b/retroshare-gui/src/rshare.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -413,4 +414,12 @@ Rshare::log(Log::LogLevel level, QString msg) return _log.log(level, msg); } - +/** Creates and binds a shortcut such that when key is pressed in + * sender's context, receiver's slot will be called. */ +void +Rshare::createShortcut(const QKeySequence &key, QWidget *sender, + QWidget *receiver, const char *slot) +{ + QShortcut *s = new QShortcut(key, sender); + connect(s, SIGNAL(activated()), receiver, slot); +} diff --git a/retroshare-gui/src/rshare.h b/retroshare-gui/src/rshare.h index ea0264015..828023d36 100644 --- a/retroshare-gui/src/rshare.h +++ b/retroshare-gui/src/rshare.h @@ -33,6 +33,7 @@ #include #include #include +#include #include "util/log.h" #include "gui/Preferences/rsharesettings.h" @@ -106,6 +107,11 @@ public: * running() will be emitted when the event loop has started. */ static int run(); + /** Creates and binds a shortcut such that when key is pressed in + * sender's context, receiver's slot will be called. */ + static void createShortcut(const QKeySequence &key, QWidget *sender, + QWidget *receiver, const char *slot); + signals: /** Emitted when the application is running and the main event loop has * started. */