Browse Source

add Menu Bar toolbar button to toggle menu bar

Le Tan 7 years ago
parent
commit
ec0b98f050
6 changed files with 61 additions and 12 deletions
  1. 14 0
      src/resources/icons/menubar.svg
  2. 3 0
      src/resources/vnote.ini
  3. 14 0
      src/vconfigmanager.h
  4. 29 10
      src/vmainwindow.cpp
  5. 0 2
      src/vmainwindow.h
  6. 1 0
      src/vnote.qrc

+ 14 - 0
src/resources/icons/menubar.svg

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
+<g>
+	<path style="fill:#000000" d="M32,376h283.35c6.186-14.112,20.281-24,36.65-24s30.465,9.888,36.65,24H480v32h-91.35c-6.186,14.112-20.281,24-36.65,24
+		s-30.465-9.888-36.65-24H32"/>
+	<path style="fill:#000000" d="M32,240h91.35c6.186-14.112,20.281-24,36.65-24s30.465,9.888,36.65,24H480v32H196.65c-6.186,14.112-20.281,24-36.65,24
+		s-30.465-9.888-36.65-24H32"/>
+	<path style="fill:#000000" d="M32,104h283.35c6.186-14.112,20.281-24,36.65-24s30.465,9.888,36.65,24H480v32h-91.35c-6.186,14.112-20.281,24-36.65,24
+		s-30.465-9.888-36.65-24H32"/>
+</g>
+</svg>

+ 3 - 0
src/resources/vnote.ini

@@ -149,6 +149,9 @@ enable_compact_mode=true
 ; Whether enable tools dock widget
 tools_dock_checked=true
 
+; Whether show menu bar
+menu_bar_checked=true
+
 ; Pages to open on startup
 ; 0 - none; 1 - Continue where you left off; 2 - specific pages
 startup_page_type=0

+ 14 - 0
src/vconfigmanager.h

@@ -435,6 +435,9 @@ public:
     // Return [web]/copy_targets.
     QStringList getCopyTargets() const;
 
+    bool getMenuBarChecked() const;
+    void setMenuBarChecked(bool p_checked);
+
 private:
     // Look up a config from user and default settings.
     QVariant getConfigFromSettings(const QString &section, const QString &key) const;
@@ -2022,4 +2025,15 @@ inline QString VConfigManager::getStyleOfSpanForMark() const
     return getConfigFromSettings("web",
                                  "style_of_span_for_mark").toString();
 }
+
+inline bool VConfigManager::getMenuBarChecked() const
+{
+    return getConfigFromSettings("global",
+                                 "menu_bar_checked").toBool();
+}
+
+inline void VConfigManager::setMenuBarChecked(bool p_checked)
+{
+    setConfigToSettings("global", "menu_bar_checked", p_checked);
+}
 #endif // VCONFIGMANAGER_H

+ 29 - 10
src/vmainwindow.cpp

@@ -429,18 +429,35 @@ void VMainWindow::initViewToolBar(QSize p_iconSize)
 
     viewToolBar->addAction(expandViewAct);
 
-    m_fullScreenAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/fullscreen.svg"),
-                                  tr("Full Screen"),
-                                  this);
+    QAction *menuBarAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/menubar.svg"),
+                                      tr("Menu Bar"),
+                                      this);
+    menuBarAct->setStatusTip(tr("Toggle menu bar"));
+    menuBarAct->setCheckable(true);
+    menuBarAct->setChecked(g_config->getMenuBarChecked());
+    connect(menuBarAct, &QAction::triggered,
+            this, [this](bool p_checked) {
+                menuBar()->setVisible(p_checked);
+                g_config->setMenuBarChecked(p_checked);
+            });
+
+    QMenu *screenMenu = new QMenu(this);
+    screenMenu->setToolTipsVisible(true);
+    screenMenu->addAction(menuBarAct);
+
+    QAction *fullScreenAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/fullscreen.svg"),
+                                         tr("Full Screen"),
+                                         this);
     QString keySeq = g_config->getShortcutKeySequence("FullScreen");
     QKeySequence seq(keySeq);
     if (!seq.isEmpty()) {
-        m_fullScreenAct->setText(tr("Full Screen\t%1").arg(VUtils::getShortcutText(keySeq)));
-        m_fullScreenAct->setShortcut(seq);
+        fullScreenAct->setText(tr("Full Screen\t%1").arg(VUtils::getShortcutText(keySeq)));
+        fullScreenAct->setShortcut(seq);
     }
 
-    m_fullScreenAct->setStatusTip(tr("Toggle full screen"));
-    connect(m_fullScreenAct, &QAction::triggered,
+    fullScreenAct->setStatusTip(tr("Toggle full screen"));
+    fullScreenAct->setMenu(screenMenu);
+    connect(fullScreenAct, &QAction::triggered,
             this, [this]() {
                 if (windowState() & Qt::WindowFullScreen) {
                     if (m_windowOldState & Qt::WindowMaximized) {
@@ -453,7 +470,7 @@ void VMainWindow::initViewToolBar(QSize p_iconSize)
                 }
             });
 
-    viewToolBar->addAction(m_fullScreenAct);
+    viewToolBar->addAction(fullScreenAct);
 }
 
 // Enable/disable all actions of @p_widget.
@@ -764,6 +781,8 @@ void VMainWindow::initMenuBar()
     initViewMenu();
     initMarkdownMenu();
     initHelpMenu();
+
+    menuBar()->setVisible(g_config->getMenuBarChecked());
 }
 
 void VMainWindow::initHelpMenu()
@@ -1877,12 +1896,12 @@ void VMainWindow::handleAreaTabStatusUpdated(const VEditTabInfo &p_info)
             }
 
             // Disconnect the trigger signal from edit tab.
-            disconnect(m_curTab, 0, m_vimCmd, 0);
+            disconnect((VEditTab *)m_curTab, 0, m_vimCmd, 0);
         }
 
         m_curTab = p_info.m_editTab;
         if (m_curTab) {
-            connect(m_curTab, &VEditTab::triggerVimCmd,
+            connect((VEditTab *)m_curTab, &VEditTab::triggerVimCmd,
                     m_vimCmd, &VVimCmdLineEdit::reset);
         }
 

+ 0 - 2
src/vmainwindow.h

@@ -337,8 +337,6 @@ private:
 
     QAction *expandViewAct;
 
-    QAction *m_fullScreenAct;
-
     QAction *m_importNoteAct;
 
     QAction *m_printAct;

+ 1 - 0
src/vnote.qrc

@@ -238,5 +238,6 @@
         <file>resources/icons/cart.svg</file>
         <file>resources/icons/delete_cart_item.svg</file>
         <file>resources/icons/fullscreen.svg</file>
+        <file>resources/icons/menubar.svg</file>
     </qresource>
 </RCC>