Browse Source

MainWindow: remember expanded state

Le Tan 7 years ago
parent
commit
b4554e1be8
5 changed files with 41 additions and 1 deletions
  1. 6 0
      src/resources/vnote.ini
  2. 3 0
      src/vconfigmanager.cpp
  3. 21 0
      src/vconfigmanager.h
  4. 10 0
      src/vmainwindow.cpp
  5. 1 1
      src/vmainwindow.h

+ 6 - 0
src/resources/vnote.ini

@@ -236,6 +236,12 @@ outline_expanded_level=6
 ; [optional] Prefix of the name of inserted images
 image_name_prefix=
 
+; MainWindow panel view state
+; 0 - ExpandMode
+; 1 - HorizontalMode (Not Implemented)
+; 2 - VerticalMode
+panel_view_state=2
+
 [export]
 ; Path of the wkhtmltopdf tool
 wkhtmltopdf=wkhtmltopdf

+ 3 - 0
src/vconfigmanager.cpp

@@ -306,6 +306,9 @@ void VConfigManager::initialize()
 
     m_imageNamePrefix = getConfigFromSettings("global",
                                               "image_name_prefix").toString();
+
+    m_panelViewState = getConfigFromSettings("global",
+                                             "panel_view_state").toInt();
 }
 
 void VConfigManager::initSettings()

+ 21 - 0
src/vconfigmanager.h

@@ -198,6 +198,9 @@ public:
     const QByteArray getTagExplorerSplitterState() const;
     void setTagExplorerSplitterState(const QByteArray &p_state);
 
+    int getPanelViewState() const;
+    void setPanelViewState(int p_state);
+
     bool getFindCaseSensitive() const;
     void setFindCaseSensitive(bool p_enabled);
 
@@ -941,6 +944,9 @@ private:
     // Prefix of the name of inserted images.
     QString m_imageNamePrefix;
 
+    // State of MainWindow panel view.
+    int m_panelViewState;
+
     // The name of the config file in each directory.
     static const QString c_dirConfigFile;
 
@@ -2454,4 +2460,19 @@ inline const QString &VConfigManager::getImageNamePrefix() const
 {
     return m_imageNamePrefix;
 }
+
+inline int VConfigManager::getPanelViewState() const
+{
+    return m_panelViewState;
+}
+
+inline void VConfigManager::setPanelViewState(int p_state)
+{
+    if (m_panelViewState == p_state) {
+        return;
+    }
+
+    m_panelViewState = p_state;
+    setConfigToSettings("global", "panel_view_state", m_panelViewState);
+}
 #endif // VCONFIGMANAGER_H

+ 10 - 0
src/vmainwindow.cpp

@@ -109,6 +109,13 @@ VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent)
 
     initDockWindows();
 
+    int state = g_config->getPanelViewState();
+    if (state < 0 || state >= (int)PanelViewState::Invalid) {
+        state = (int)PanelViewState::VerticalMode;
+    }
+
+    changePanelView((PanelViewState)state);
+
     restoreStateAndGeometry();
 
     setContextMenuPolicy(Qt::NoContextMenu);
@@ -2069,9 +2076,12 @@ void VMainWindow::changePanelView(PanelViewState p_state)
         break;
 
     default:
+        Q_ASSERT(false);
         break;
     }
 
+    g_config->setPanelViewState((int)p_state);
+
     expandViewAct->setChecked(p_state == PanelViewState::ExpandMode);
 }
 

+ 1 - 1
src/vmainwindow.h

@@ -48,7 +48,7 @@ class VTagExplorer;
 
 enum class PanelViewState
 {
-    ExpandMode,
+    ExpandMode = 0,
     HorizontalMode,
     VerticalMode,
     Invalid