Properly save and restore the mainwindow state
[quassel.git] / src / qtui / mainwin.h
index b05b724..ac79a8d 100644 (file)
 #  include <QMainWindow>
 #endif
 
+#ifdef Q_WS_WIN
+#  include <windows.h>
+#endif
+
 #include <QSystemTrayIcon>
 
 #include "qtui.h"
-#include "sessionsettings.h"
 #include "titlesetter.h"
+#include "uisettings.h"
 
 class ActionCollection;
 class BufferView;
 class BufferViewConfig;
+class ClientBufferViewConfig;
 class BufferViewDock;
 class BufferWidget;
 class InputWidget;
 class MsgProcessorStatusWidget;
 class NickListWidget;
-class SystemTrayIcon;
+class SystemTray;
 
 class QMenu;
 class QLabel;
@@ -64,24 +69,34 @@ class MainWin
 
     void init();
 
-    void addBufferView(BufferViewConfig *config);
+    void addBufferView(ClientBufferViewConfig *config);
     BufferView *allBuffersView() const;
 
-    inline QSystemTrayIcon *systemTrayIcon() const;
+    inline SystemTray *systemTray() const;
 
-    virtual bool event(QEvent *event);
+    bool event(QEvent *event);
 
     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
 
+    void saveStateToSettings(UiSettings &);
+    void restoreStateFromSettings(UiSettings &);
+
   public slots:
     void saveStateToSession(const QString &sessionId);
     void saveStateToSessionSettings(SessionSettings &s);
     void showStatusBarMessage(const QString &message);
 
+    void toggleMinimizedToTray();
+
+    //! Bring window to front and focus it
+    void forceActivated();
+
   protected:
     void closeEvent(QCloseEvent *event);
-    virtual void changeEvent(QEvent *event);
+    void changeEvent(QEvent *event);
+    void moveEvent(QMoveEvent *event);
+    void resizeEvent(QResizeEvent *event);
 
   protected slots:
     void connectedToCore();
@@ -89,7 +104,6 @@ class MainWin
     void updateLagIndicator(int lag = -1);
     void disconnectedFromCore();
     void setDisconnectedState();
-    void systrayActivated(QSystemTrayIcon::ActivationReason);
 
   private slots:
     void addBufferView(int bufferViewConfigId);
@@ -109,7 +123,7 @@ class MainWin
 #endif
     void on_actionConfigureNetworks_triggered();
     void on_actionConfigureViews_triggered();
-    void on_actionLockDockPositions_toggled(bool lock);
+    void on_actionLockLayout_toggled(bool lock);
     void on_actionDebugNetworkModel_triggered();
     void on_actionDebugMessageModel_triggered();
     void on_actionDebugLog_triggered();
@@ -120,6 +134,7 @@ class MainWin
     void connectOrDisconnectFromNet();
 
     void saveStatusBarStatus(bool enabled);
+    void aboutToQuit();
 
     void loadLayout();
     void saveLayout();
@@ -133,7 +148,6 @@ class MainWin
     KHelpMenu *_kHelpMenu;
 #endif
 
-    QMenu *systrayMenu;
     QLabel *coreLagLabel;
     QLabel *sslLabel;
     MsgProcessorStatusWidget *msgProcessorStatusWidget;
@@ -153,11 +167,11 @@ class MainWin
     void setupToolBars();
 
     void updateIcon();
-    void hideToTray();
-    void toggleMinimizedToTray();
     void enableMenus();
 
-    QSystemTrayIcon *_trayIcon;
+    void hideToTray();
+
+    SystemTray *_systemTray;
 
     QList<BufferViewDock *> _bufferViews;
     BufferWidget *_bufferWidget;
@@ -165,14 +179,24 @@ class MainWin
     InputWidget *_inputWidget;
 
     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
+    QMenu *_toolbarMenu;
     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
 
     QWidget *_awayLog;
+
+    QSize _normalSize; //!< Size of the non-maximized window
+    QPoint _normalPos; //!< Position of the non-maximized window
+    bool _isHidden;
+
+#ifdef Q_WS_WIN
+    DWORD dwTickCount;
+#endif
+
     friend class QtUi;
 };
 
-QSystemTrayIcon *MainWin::systemTrayIcon() const {
-  return _trayIcon;
+SystemTray *MainWin::systemTray() const {
+  return _systemTray;
 }
 
 #endif