Browse Source

MainWindow: support hiding tool bar

ToolBar: Ctrl+E Shift+#
Le Tan 7 years ago
parent
commit
e59a23cda6

+ 6 - 0
src/resources/docs/shortcuts_en.md

@@ -204,6 +204,8 @@ Toggle expanding the edit area.
 Toggle single panel or two panels mode.
 - `T`   
 Toggle the Tools panel.
+- `Shift+#`   
+Toggle the Tool Bar.
 - `F`   
 Popup the opened notes list of current split window. Within this list, pressing the sequence number in front of each note could jump to that note.
 - `A`   
@@ -226,6 +228,10 @@ Discard current changes and exit edit mode.
 Vertically split current window.
 - `R`   
 Remove current split window.
+- `Shift+|`   
+Maximize current split window.
+- `=`   
+Distribute all the split windows evenly.
 - `H`   
 Jump to the first split window on the left.
 - `L`   

+ 6 - 0
src/resources/docs/shortcuts_zh.md

@@ -205,6 +205,8 @@ RemoveSplit=R
 切换单列/双列面板模式。
 - `T`   
 打开或关闭工具面板。
+- `Shift+#`   
+打开或关闭工具栏。
 - `F`   
 打开当前分割窗口的笔记列表。在该列表中,可以直接按笔记对应的序号实现跳转。
 - `A`   
@@ -227,6 +229,10 @@ RemoveSplit=R
 垂直分割当前窗口。
 - `R`   
 移除当前分割窗口。
+- `Shift+|`   
+最大化当前分割窗口。
+- `=`   
+均等分布所有分割窗口。
 - `H`   
 跳转到左边一个分割窗口。
 - `L`   

+ 5 - 0
src/resources/vnote.ini

@@ -159,6 +159,9 @@ search_dock_checked=false
 ; Whether show menu bar
 menu_bar_checked=true
 
+; Whether show tool bar
+tool_bar_checked=true
+
 ; Pages to open on startup
 ; 0 - none; 1 - Continue where you left off; 2 - specific pages
 startup_page_type=0
@@ -370,6 +373,8 @@ DiscardAndRead=Q
 ToolsDock=T
 ; Toggle Search dock widget
 SearchDock=C
+; Toggle tool bar
+ToolBar=Shift+#
 ; Close current note
 CloseNote=X
 ; Show shortcuts help document

+ 14 - 0
src/vconfigmanager.h

@@ -474,6 +474,9 @@ public:
     bool getMenuBarChecked() const;
     void setMenuBarChecked(bool p_checked);
 
+    bool getToolBarChecked() const;
+    void setToolBarChecked(bool p_checked);
+
     bool getSingleClickClosePreviousTab() const;
     void setSingleClickClosePreviousTab(bool p_enabled);
 
@@ -2215,6 +2218,17 @@ inline void VConfigManager::setMenuBarChecked(bool p_checked)
     setConfigToSettings("global", "menu_bar_checked", p_checked);
 }
 
+inline bool VConfigManager::getToolBarChecked() const
+{
+    return getConfigFromSettings("global",
+                                 "tool_bar_checked").toBool();
+}
+
+inline void VConfigManager::setToolBarChecked(bool p_checked)
+{
+    setConfigToSettings("global", "tool_bar_checked", p_checked);
+}
+
 inline bool VConfigManager::getSingleClickClosePreviousTab() const
 {
     return m_singleClickClosePreviousTab;

+ 67 - 8
src/vmainwindow.cpp

@@ -175,6 +175,10 @@ void VMainWindow::registerCaptainAndNavigationTargets()
                                      g_config->getCaptainShortcutKeySequence("DiscardAndRead"),
                                      this,
                                      discardAndReadByCaptain);
+    m_captain->registerCaptainTarget(tr("ToolBar"),
+                                     g_config->getCaptainShortcutKeySequence("ToolBar"),
+                                     this,
+                                     toggleToolBarByCaptain);
     m_captain->registerCaptainTarget(tr("ToolsDock"),
                                      g_config->getCaptainShortcutKeySequence("ToolsDock"),
                                      this,
@@ -343,13 +347,15 @@ void VMainWindow::initToolBar()
     const int tbIconSize = g_config->getToolBarIconSize() * VUtils::calculateScaleFactor();
     QSize iconSize(tbIconSize, tbIconSize);
 
-    initFileToolBar(iconSize);
-    initViewToolBar(iconSize);
-    initEditToolBar(iconSize);
-    initNoteToolBar(iconSize);
+    m_toolBars.append(initFileToolBar(iconSize));
+    m_toolBars.append(initViewToolBar(iconSize));
+    m_toolBars.append(initEditToolBar(iconSize));
+    m_toolBars.append(initNoteToolBar(iconSize));
+
+    setToolBarVisible(g_config->getToolBarChecked());
 }
 
-void VMainWindow::initViewToolBar(QSize p_iconSize)
+QToolBar *VMainWindow::initViewToolBar(QSize p_iconSize)
 {
     QToolBar *viewToolBar = addToolBar(tr("View"));
     viewToolBar->setObjectName("ViewToolBar");
@@ -422,6 +428,8 @@ void VMainWindow::initViewToolBar(QSize p_iconSize)
             });
 
     viewToolBar->addAction(expandViewAct);
+
+    return viewToolBar;
 }
 
 // Enable/disable all actions of @p_widget.
@@ -434,7 +442,7 @@ static void setActionsEnabled(QWidget *p_widget, bool p_enabled)
     }
 }
 
-void VMainWindow::initEditToolBar(QSize p_iconSize)
+QToolBar *VMainWindow::initEditToolBar(QSize p_iconSize)
 {
     m_editToolBar = addToolBar(tr("Edit Toolbar"));
     m_editToolBar->setObjectName("EditToolBar");
@@ -557,9 +565,11 @@ void VMainWindow::initEditToolBar(QSize p_iconSize)
     m_editToolBar->addAction(insertImageAct);
 
     setActionsEnabled(m_editToolBar, false);
+
+    return m_editToolBar;
 }
 
-void VMainWindow::initNoteToolBar(QSize p_iconSize)
+QToolBar *VMainWindow::initNoteToolBar(QSize p_iconSize)
 {
     QToolBar *noteToolBar = addToolBar(tr("Note Toolbar"));
     noteToolBar->setObjectName("NoteToolBar");
@@ -614,9 +624,11 @@ void VMainWindow::initNoteToolBar(QSize p_iconSize)
     noteToolBar->addWidget(m_attachmentBtn);
     noteToolBar->addAction(flashPageAct);
     noteToolBar->addAction(universalEntryAct);
+
+    return noteToolBar;
 }
 
-void VMainWindow::initFileToolBar(QSize p_iconSize)
+QToolBar *VMainWindow::initFileToolBar(QSize p_iconSize)
 {
     QToolBar *fileToolBar = addToolBar(tr("Note"));
     fileToolBar->setObjectName("NoteToolBar");
@@ -707,6 +719,8 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
     fileToolBar->addAction(m_editReadAct);
     fileToolBar->addAction(m_discardExitAct);
     fileToolBar->addAction(saveNoteAct);
+
+    return fileToolBar;
 }
 
 void VMainWindow::initMenuBar()
@@ -922,6 +936,19 @@ void VMainWindow::initViewMenu()
 {
     m_viewMenu = menuBar()->addMenu(tr("&View"));
     m_viewMenu->setToolTipsVisible(true);
+
+    m_toolBarAct = new QAction(tr("Tool Bar"), this);
+    m_toolBarAct->setToolTip(tr("Toogle the tool bar"));
+    VUtils::fixTextWithCaptainShortcut(m_toolBarAct, "ToolBar");
+    m_toolBarAct->setCheckable(true);
+    m_toolBarAct->setChecked(g_config->getToolBarChecked());
+    connect(m_toolBarAct, &QAction::triggered,
+            this, [this] (bool p_checked) {
+                g_config->setToolBarChecked(p_checked);
+                setToolBarVisible(p_checked);
+            });
+
+    m_viewMenu->addAction(m_toolBarAct);
 }
 
 void VMainWindow::initFileMenu()
@@ -2645,7 +2672,20 @@ bool VMainWindow::showAttachmentListByCaptain(void *p_target, void *p_data)
     Q_UNUSED(p_data);
     VMainWindow *obj = static_cast<VMainWindow *>(p_target);
     if (obj->m_attachmentBtn->isEnabled()) {
+        // Show tool bar first.
+        bool toolBarChecked = obj->m_toolBarAct->isChecked();
+        if (!toolBarChecked) {
+            obj->setToolBarVisible(true);
+
+            // Make it visible first.
+            QCoreApplication::sendPostedEvents();
+        }
+
         obj->m_attachmentBtn->showPopupWidget();
+
+        if (!toolBarChecked) {
+            obj->setToolBarVisible(false);
+        }
     }
 
     return true;
@@ -2686,6 +2726,14 @@ bool VMainWindow::discardAndReadByCaptain(void *p_target, void *p_data)
     return true;
 }
 
+bool VMainWindow::toggleToolBarByCaptain(void *p_target, void *p_data)
+{
+    Q_UNUSED(p_data);
+    VMainWindow *obj = static_cast<VMainWindow *>(p_target);
+    obj->m_toolBarAct->trigger();
+    return true;
+}
+
 bool VMainWindow::toggleToolsDockByCaptain(void *p_target, void *p_data)
 {
     Q_UNUSED(p_data);
@@ -3186,6 +3234,17 @@ void VMainWindow::setMenuBarVisible(bool p_visible)
     }
 }
 
+void VMainWindow::setToolBarVisible(bool p_visible)
+{
+    for (auto bar : m_toolBars) {
+        if (p_visible) {
+            bar->setFixedSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
+        } else {
+            bar->setFixedHeight(0);
+        }
+    }
+}
+
 void VMainWindow::kickOffStartUpTimer(const QStringList &p_files)
 {
     QTimer::singleShot(300, [this, p_files]() {

+ 14 - 6
src/vmainwindow.h

@@ -211,14 +211,13 @@ private:
 
     void initToolBar();
 
-    void initFileToolBar(QSize p_iconSize = QSize());
+    QToolBar *initFileToolBar(QSize p_iconSize = QSize());
 
-    void initViewToolBar(QSize p_iconSize = QSize());
+    QToolBar *initViewToolBar(QSize p_iconSize = QSize());
 
-    void initNoteToolBar(QSize p_iconSize = QSize());
+    QToolBar *initNoteToolBar(QSize p_iconSize = QSize());
 
-    // Init the Edit toolbar.
-    void initEditToolBar(QSize p_iconSize = QSize());
+    QToolBar *initEditToolBar(QSize p_iconSize = QSize());
 
     void initMenuBar();
     void initFileMenu();
@@ -297,6 +296,8 @@ private:
 
     void setMenuBarVisible(bool p_visible);
 
+    void setToolBarVisible(bool p_visible);
+
     void showNotebookPanel();
 
     // Captain mode functions.
@@ -310,6 +311,8 @@ private:
 
     static bool discardAndReadByCaptain(void *p_target, void *p_data);
 
+    static bool toggleToolBarByCaptain(void *p_target, void *p_data);
+
     static bool toggleToolsDockByCaptain(void *p_target, void *p_data);
 
     static bool toggleSearchDockByCaptain(void *p_target, void *p_data);
@@ -407,6 +410,8 @@ private:
     // Enable heading sequence for current note.
     QAction *m_headingSequenceAct;
 
+    QAction *m_toolBarAct;
+
     // Act group for render styles.
     QActionGroup *m_renderStyleActs;
 
@@ -416,9 +421,12 @@ private:
     // Menus
     QMenu *m_viewMenu;
 
-    // Edit Toolbar.
+    // Edit ToolBar.
     QToolBar *m_editToolBar;
 
+    // All the ToolBar.
+    QVector<QToolBar *> m_toolBars;
+
     // Attachment button.
     VButtonWithWidget *m_attachmentBtn;