diff --git a/src/resources/icons/compact_mode.svg b/src/resources/icons/compact_mode.svg deleted file mode 100644 index 6cc49aa2..00000000 --- a/src/resources/icons/compact_mode.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - one_panel - - Layer 1 - - - - - diff --git a/src/resources/icons/notebook.svg b/src/resources/icons/notebook.svg new file mode 100644 index 00000000..f7ba80b7 --- /dev/null +++ b/src/resources/icons/notebook.svg @@ -0,0 +1,8 @@ + + + + + + diff --git a/src/resources/icons/one_panel.svg b/src/resources/icons/one_panel.svg deleted file mode 100644 index 2b8f3ffb..00000000 --- a/src/resources/icons/one_panel.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - - one_panel - - Layer 1 - - - - \ No newline at end of file diff --git a/src/resources/icons/two_panels.svg b/src/resources/icons/two_panels.svg deleted file mode 100644 index 7e9757bb..00000000 --- a/src/resources/icons/two_panels.svg +++ /dev/null @@ -1,11 +0,0 @@ - - - - one_panel - - Layer 1 - - - - - \ No newline at end of file diff --git a/src/resources/themes/v_moonlight/v_moonlight.qss b/src/resources/themes/v_moonlight/v_moonlight.qss index 15ae9046..fa42dba9 100644 --- a/src/resources/themes/v_moonlight/v_moonlight.qss +++ b/src/resources/themes/v_moonlight/v_moonlight.qss @@ -402,7 +402,6 @@ VButtonMenuItem:disabled { /* QComboBox */ QComboBox#NotebookSelector { border: none; - border-bottom: $2px solid @combobox_notebookselector_border; font-size: 13pt; padding-top: 3px; padding-bottom: 3px; diff --git a/src/resources/themes/v_pure/v_pure.qss b/src/resources/themes/v_pure/v_pure.qss index ee21836a..bcc11cce 100644 --- a/src/resources/themes/v_pure/v_pure.qss +++ b/src/resources/themes/v_pure/v_pure.qss @@ -402,7 +402,6 @@ VButtonMenuItem:disabled { /* QComboBox */ QComboBox#NotebookSelector { border: none; - border-bottom: $2px solid @combobox_notebookselector_border; font-size: 13pt; padding-top: 3px; padding-bottom: 3px; diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index a235c7c4..a2b42a5d 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -147,9 +147,6 @@ confirm_reload_folder=true ; Whether double click on a tab to close it double_click_close_tab=true -; Whether put folder and note panel in one vertical column -enable_compact_mode=true - ; Whether enable tools dock widget tools_dock_checked=true @@ -350,8 +347,6 @@ AttachmentList=A LocateCurrentFile=D ; Toggle Expand mode ExpandMode=E -; Alternate one/two panels view -OnePanelView=P ; Discard changes and enter read mode DiscardAndRead=Q ; Toggle Tools dock widget diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index 9f394483..4ab3421f 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -238,9 +238,6 @@ void VConfigManager::initialize() m_doubleClickCloseTab = getConfigFromSettings("global", "double_click_close_tab").toBool(); - m_enableCompactMode = getConfigFromSettings("global", - "enable_compact_mode").toBool(); - int tmpStartupPageMode = getConfigFromSettings("global", "startup_page_type").toInt(); if (tmpStartupPageMode < (int)StartupPageType::Invalid @@ -337,18 +334,6 @@ void VConfigManager::initSettings() void VConfigManager::initFromSessionSettings() { curNotebookIndex = getConfigFromSessionSettings("global", "current_notebook").toInt(); - - m_mainWindowGeometry = getConfigFromSessionSettings("geometry", - "main_window_geometry").toByteArray(); - - m_mainWindowState = getConfigFromSessionSettings("geometry", - "main_window_state").toByteArray(); - - m_mainSplitterState = getConfigFromSessionSettings("geometry", - "main_splitter_state").toByteArray(); - - m_naviSplitterState = getConfigFromSessionSettings("geometry", - "navi_splitter_state").toByteArray(); } void VConfigManager::readCustomColors() @@ -1478,7 +1463,6 @@ void VConfigManager::resetLayoutConfigurations() resetDefaultConfig("global", "tools_dock_checked"); resetDefaultConfig("global", "search_dock_checked"); resetDefaultConfig("global", "menu_bar_checked"); - resetDefaultConfig("global", "enable_compact_mode"); clearGroupOfSettings(m_sessionSettings, "geometry"); diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index 3bdc14a3..fb8789b4 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -176,17 +176,17 @@ public: bool getSearchDockChecked() const; void setSearchDockChecked(bool p_checked); - const QByteArray &getMainWindowGeometry() const; + const QByteArray getMainWindowGeometry() const; void setMainWindowGeometry(const QByteArray &p_geometry); - const QByteArray &getMainWindowState() const; + const QByteArray getMainWindowState() const; void setMainWindowState(const QByteArray &p_state); - const QByteArray &getMainSplitterState() const; + const QByteArray getMainSplitterState() const; void setMainSplitterState(const QByteArray &p_state); - const QByteArray &getNaviSplitterState() const; - void setNaviSplitterState(const QByteArray &p_state); + const QByteArray getNotebookSplitterState() const; + void setNotebookSplitterState(const QByteArray &p_state); bool getFindCaseSensitive() const; void setFindCaseSensitive(bool p_enabled); @@ -344,9 +344,6 @@ public: bool getDoubleClickCloseTab() const; - bool getEnableCompactMode() const; - void setEnableCompactMode(bool p_enabled); - StartupPageType getStartupPageType() const; void setStartupPageType(StartupPageType p_type); @@ -623,11 +620,6 @@ private: QString curRenderBackgroundColor; - QByteArray m_mainWindowGeometry; - QByteArray m_mainWindowState; - QByteArray m_mainSplitterState; - QByteArray m_naviSplitterState; - // Find/Replace dialog options bool m_findCaseSensitive; bool m_findWholeWordOnly; @@ -815,9 +807,6 @@ private: // Whether double click on a tab to close it. bool m_doubleClickCloseTab; - // Whether put folder and note panel in one single column. - bool m_enableCompactMode; - // Type of the pages to open on startup. StartupPageType m_startupPageType; @@ -1204,56 +1193,56 @@ inline void VConfigManager::setSearchDockChecked(bool p_checked) p_checked); } -inline const QByteArray& VConfigManager::getMainWindowGeometry() const +inline const QByteArray VConfigManager::getMainWindowGeometry() const { - return m_mainWindowGeometry; + return getConfigFromSessionSettings("geometry", + "main_window_geometry").toByteArray(); } inline void VConfigManager::setMainWindowGeometry(const QByteArray &p_geometry) { - m_mainWindowGeometry = p_geometry; setConfigToSessionSettings("geometry", "main_window_geometry", - m_mainWindowGeometry); + p_geometry); } -inline const QByteArray& VConfigManager::getMainWindowState() const +inline const QByteArray VConfigManager::getMainWindowState() const { - return m_mainWindowState; + return getConfigFromSessionSettings("geometry", + "main_window_state").toByteArray(); } inline void VConfigManager::setMainWindowState(const QByteArray &p_state) { - m_mainWindowState = p_state; setConfigToSessionSettings("geometry", "main_window_state", - m_mainWindowState); + p_state); } -inline const QByteArray& VConfigManager::getMainSplitterState() const +inline const QByteArray VConfigManager::getMainSplitterState() const { - return m_mainSplitterState; + return getConfigFromSessionSettings("geometry", + "main_splitter_state").toByteArray(); } inline void VConfigManager::setMainSplitterState(const QByteArray &p_state) { - m_mainSplitterState = p_state; setConfigToSessionSettings("geometry", "main_splitter_state", - m_mainSplitterState); + p_state); } -inline const QByteArray& VConfigManager::getNaviSplitterState() const +inline const QByteArray VConfigManager::getNotebookSplitterState() const { - return m_naviSplitterState; + return getConfigFromSessionSettings("geometry", + "notebook_splitter_state").toByteArray(); } -inline void VConfigManager::setNaviSplitterState(const QByteArray &p_state) +inline void VConfigManager::setNotebookSplitterState(const QByteArray &p_state) { - m_naviSplitterState = p_state; setConfigToSessionSettings("geometry", - "navi_splitter_state", - m_naviSplitterState); + "notebook_splitter_state", + p_state); } inline bool VConfigManager::getFindCaseSensitive() const @@ -1965,21 +1954,6 @@ inline bool VConfigManager::getDoubleClickCloseTab() const return m_doubleClickCloseTab; } -inline bool VConfigManager::getEnableCompactMode() const -{ - return m_enableCompactMode; -} - -inline void VConfigManager::setEnableCompactMode(bool p_enabled) -{ - if (m_enableCompactMode == p_enabled) { - return; - } - - m_enableCompactMode = p_enabled; - setConfigToSettings("global", "enable_compact_mode", m_enableCompactMode); -} - inline StartupPageType VConfigManager::getStartupPageType() const { return m_startupPageType; diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 70dd57e6..1c8ffa46 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -85,18 +85,6 @@ VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent) m_webUtils.init(); g_webUtils = &m_webUtils; - if (g_config->getEnableCompactMode()) { - m_panelViewState = PanelViewState::CompactMode; - } else { - m_panelViewState = PanelViewState::TwoPanels; - } - - m_panelViewTimer = new QTimer(this); - m_panelViewTimer->setSingleShot(true); - m_panelViewTimer->setInterval(500); - connect(m_panelViewTimer, &QTimer::timeout, - this, &VMainWindow::postChangePanelView); - initCaptain(); setupUI(); @@ -109,8 +97,6 @@ VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent) initDockWindows(); - changePanelView(m_panelViewState); - restoreStateAndGeometry(); setContextMenuPolicy(Qt::NoContextMenu); @@ -155,8 +141,9 @@ void VMainWindow::initCaptain() void VMainWindow::registerCaptainAndNavigationTargets() { + m_captain->registerNavigationTarget(m_naviBox); m_captain->registerNavigationTarget(m_notebookSelector); - m_captain->registerNavigationTarget(directoryTree); + m_captain->registerNavigationTarget(m_dirTree); m_captain->registerNavigationTarget(m_fileList); m_captain->registerNavigationTarget(m_editArea); m_captain->registerNavigationTarget(m_toolBox); @@ -177,10 +164,6 @@ void VMainWindow::registerCaptainAndNavigationTargets() g_config->getCaptainShortcutKeySequence("ExpandMode"), this, toggleExpandModeByCaptain); - m_captain->registerCaptainTarget(tr("OnePanelView"), - g_config->getCaptainShortcutKeySequence("OnePanelView"), - this, - toggleOnePanelViewByCaptain); m_captain->registerCaptainTarget(tr("DiscardAndRead"), g_config->getCaptainShortcutKeySequence("DiscardAndRead"), this, @@ -213,41 +196,39 @@ void VMainWindow::registerCaptainAndNavigationTargets() void VMainWindow::setupUI() { - QWidget *directoryPanel = setupDirectoryPanel(); + m_naviBox = new VToolBox(); - m_fileList = new VFileList(); - m_fileList->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); + setupNotebookPanel(); + + m_naviBox->addItem(m_nbSplitter, + ":/resources/icons/notebook.svg", + tr("Notebooks"), + m_dirTree); m_editArea = new VEditArea(); m_editArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_findReplaceDialog = m_editArea->getFindReplaceDialog(); m_fileList->setEditArea(m_editArea); - directoryTree->setEditArea(m_editArea); + m_dirTree->setEditArea(m_editArea); // Main Splitter m_mainSplitter = new QSplitter(); m_mainSplitter->setObjectName("MainSplitter"); - m_mainSplitter->addWidget(directoryPanel); - m_mainSplitter->addWidget(m_fileList); - setTabOrder(directoryTree, m_fileList->getContentWidget()); + m_mainSplitter->addWidget(m_naviBox); m_mainSplitter->addWidget(m_editArea); m_mainSplitter->setStretchFactor(0, 0); m_mainSplitter->setStretchFactor(1, 0); - m_mainSplitter->setStretchFactor(2, 1); - // Signals - connect(directoryTree, &VDirectoryTree::currentDirectoryChanged, - m_fileList, &VFileList::setDirectory); - connect(directoryTree, &VDirectoryTree::directoryUpdated, + connect(m_dirTree, &VDirectoryTree::directoryUpdated, m_editArea, &VEditArea::handleDirectoryUpdated); connect(m_notebookSelector, &VNotebookSelector::notebookUpdated, m_editArea, &VEditArea::handleNotebookUpdated); connect(m_notebookSelector, &VNotebookSelector::notebookCreated, - directoryTree, [this](const QString &p_name, bool p_import) { + m_dirTree, [this](const QString &p_name, bool p_import) { Q_UNUSED(p_name); if (!p_import) { - directoryTree->newRootDirectory(); + m_dirTree->newRootDirectory(); } }); @@ -284,66 +265,53 @@ void VMainWindow::setupUI() initTrayIcon(); } -QWidget *VMainWindow::setupDirectoryPanel() +void VMainWindow::setupNotebookPanel() { - // Notebook selector. - QLabel *notebookLabel = new QLabel(tr("Notebooks")); - notebookLabel->setProperty("TitleLabel", true); - m_notebookSelector = new VNotebookSelector(); m_notebookSelector->setObjectName("NotebookSelector"); m_notebookSelector->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); - // Navigation panel. + // Folders. QLabel *directoryLabel = new QLabel(tr("Folders")); directoryLabel->setProperty("TitleLabel", true); - directoryTree = new VDirectoryTree; + m_dirTree = new VDirectoryTree; QVBoxLayout *naviLayout = new QVBoxLayout; + naviLayout->addWidget(m_notebookSelector); naviLayout->addWidget(directoryLabel); - naviLayout->addWidget(directoryTree); + naviLayout->addWidget(m_dirTree); naviLayout->setContentsMargins(0, 0, 0, 0); naviLayout->setSpacing(0); QWidget *naviWidget = new QWidget(); naviWidget->setLayout(naviLayout); - QWidget *tmpWidget = new QWidget(); + // Notes. + m_fileList = new VFileList(); + m_fileList->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); - // Compact splitter. - m_naviSplitter = new QSplitter(); - m_naviSplitter->setOrientation(Qt::Vertical); - m_naviSplitter->setObjectName("NaviSplitter"); - m_naviSplitter->addWidget(naviWidget); - m_naviSplitter->addWidget(tmpWidget); - m_naviSplitter->setStretchFactor(0, 0); - m_naviSplitter->setStretchFactor(1, 1); - - tmpWidget->hide(); - - QVBoxLayout *nbLayout = new QVBoxLayout; - nbLayout->addWidget(notebookLabel); - nbLayout->addWidget(m_notebookSelector); - nbLayout->addWidget(m_naviSplitter); - nbLayout->setContentsMargins(3, 0, 0, 0); - nbLayout->setSpacing(0); - QWidget *nbContainer = new QWidget(); - nbContainer->setLayout(nbLayout); - nbContainer->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); + m_nbSplitter = new QSplitter(); + m_nbSplitter->setOrientation(Qt::Vertical); + m_nbSplitter->setObjectName("NotebookSplitter"); + m_nbSplitter->addWidget(naviWidget); + m_nbSplitter->addWidget(m_fileList); + m_nbSplitter->setStretchFactor(0, 0); + m_nbSplitter->setStretchFactor(1, 1); connect(m_notebookSelector, &VNotebookSelector::curNotebookChanged, this, [this](VNotebook *p_notebook) { - directoryTree->setNotebook(p_notebook); - directoryTree->setFocus(); + m_dirTree->setNotebook(p_notebook); + m_dirTree->setFocus(); }); connect(m_notebookSelector, &VNotebookSelector::curNotebookChanged, this, &VMainWindow::handleCurrentNotebookChanged); - connect(directoryTree, &VDirectoryTree::currentDirectoryChanged, + connect(m_dirTree, &VDirectoryTree::currentDirectoryChanged, this, &VMainWindow::handleCurrentDirectoryChanged); - return nbContainer; + connect(m_dirTree, &VDirectoryTree::currentDirectoryChanged, + m_fileList, &VFileList::setDirectory); } void VMainWindow::initToolBar() @@ -366,92 +334,6 @@ void VMainWindow::initViewToolBar(QSize p_iconSize) viewToolBar->setIconSize(p_iconSize); } - m_viewActGroup = new QActionGroup(this); - QAction *onePanelViewAct = new QAction(VIconUtils::menuIcon(":/resources/icons/one_panel.svg"), - tr("Single Panel"), - m_viewActGroup); - VUtils::fixTextWithCaptainShortcut(onePanelViewAct, "OnePanelView"); - onePanelViewAct->setStatusTip(tr("Display only the notes list panel")); - onePanelViewAct->setCheckable(true); - onePanelViewAct->setData((int)PanelViewState::SinglePanel); - - QAction *twoPanelViewAct = new QAction(VIconUtils::menuIcon(":/resources/icons/two_panels.svg"), - tr("Two Panels"), - m_viewActGroup); - VUtils::fixTextWithCaptainShortcut(twoPanelViewAct, "OnePanelView"); - twoPanelViewAct->setStatusTip(tr("Display both the folders and notes list panel")); - twoPanelViewAct->setCheckable(true); - twoPanelViewAct->setData((int)PanelViewState::TwoPanels); - - QAction *compactViewAct = new QAction(VIconUtils::menuIcon(":/resources/icons/compact_mode.svg"), - tr("Compact Mode"), - m_viewActGroup); - compactViewAct->setStatusTip(tr("Integrate the folders and notes list panel in one column")); - compactViewAct->setCheckable(true); - compactViewAct->setData((int)PanelViewState::CompactMode); - - connect(m_viewActGroup, &QActionGroup::triggered, - this, [this](QAction *p_action) { - if (!p_action) { - return; - } - - int act = p_action->data().toInt(); - switch (act) { - case (int)PanelViewState::SinglePanel: - onePanelView(); - break; - - case (int)PanelViewState::TwoPanels: - twoPanelView(); - break; - - case (int)PanelViewState::CompactMode: - compactModeView(); - break; - - default: - break; - } - }); - - QMenu *panelMenu = new QMenu(this); - panelMenu->setToolTipsVisible(true); - panelMenu->addAction(onePanelViewAct); - panelMenu->addAction(twoPanelViewAct); - panelMenu->addAction(compactViewAct); - - expandViewAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/expand.svg"), - tr("Expand"), this); - VUtils::fixTextWithCaptainShortcut(expandViewAct, "ExpandMode"); - expandViewAct->setStatusTip(tr("Expand the edit area")); - expandViewAct->setCheckable(true); - expandViewAct->setMenu(panelMenu); - connect(expandViewAct, &QAction::triggered, - this, [this](bool p_checked) { - // Recover m_panelViewState or change to expand mode. - changePanelView(p_checked ? PanelViewState::ExpandMode - : m_panelViewState); - }); - - viewToolBar->addAction(expandViewAct); - - 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) { - setMenuBarVisible(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); @@ -463,7 +345,6 @@ void VMainWindow::initViewToolBar(QSize p_iconSize) } fullScreenAct->setStatusTip(tr("Toggle full screen")); - fullScreenAct->setMenu(screenMenu); connect(fullScreenAct, &QAction::triggered, this, [this]() { if (windowState() & Qt::WindowFullScreen) { @@ -477,7 +358,37 @@ void VMainWindow::initViewToolBar(QSize p_iconSize) } }); - viewToolBar->addAction(fullScreenAct); + 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) { + setMenuBarVisible(p_checked); + g_config->setMenuBarChecked(p_checked); + }); + + QMenu *viewMenu = new QMenu(this); + viewMenu->setToolTipsVisible(true); + viewMenu->addAction(fullScreenAct); + viewMenu->addAction(menuBarAct); + + expandViewAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/expand.svg"), + tr("Expand"), + this); + VUtils::fixTextWithCaptainShortcut(expandViewAct, "ExpandMode"); + expandViewAct->setStatusTip(tr("Expand the edit area")); + expandViewAct->setCheckable(true); + expandViewAct->setMenu(viewMenu); + connect(expandViewAct, &QAction::triggered, + this, [this](bool p_checked) { + changePanelView(p_checked ? PanelViewState::ExpandMode + : PanelViewState::VerticalMode); + }); + + viewToolBar->addAction(expandViewAct); } // Enable/disable all actions of @p_widget. @@ -691,7 +602,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize) this); newRootDirAct->setStatusTip(tr("Create a root folder in current notebook")); connect(newRootDirAct, &QAction::triggered, - directoryTree, &VDirectoryTree::newRootDirectory); + m_dirTree, &VDirectoryTree::newRootDirectory); newNoteAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/create_note_tb.svg"), tr("New Note"), this); @@ -2050,127 +1961,25 @@ void VMainWindow::handleAreaTabStatusUpdated(const VEditTabInfo &p_info) updateStatusInfo(p_info); } -void VMainWindow::onePanelView() -{ - m_panelViewState = PanelViewState::SinglePanel; - g_config->setEnableCompactMode(false); - changePanelView(m_panelViewState, true); -} - -void VMainWindow::twoPanelView() -{ - m_panelViewState = PanelViewState::TwoPanels; - g_config->setEnableCompactMode(false); - changePanelView(m_panelViewState, true); -} - -void VMainWindow::compactModeView() -{ - m_panelViewState = PanelViewState::CompactMode; - g_config->setEnableCompactMode(true); - changePanelView(m_panelViewState, true); -} - -void VMainWindow::enableCompactMode(bool p_enabled) -{ - const int fileListIdx = 1; - bool isCompactMode = m_naviSplitter->indexOf(m_fileList) != -1; - if (p_enabled) { - // Change to compact mode. - if (isCompactMode) { - return; - } - - // Take m_fileList out of m_mainSplitter. - QWidget *tmpWidget = new QWidget(this); - Q_ASSERT(fileListIdx == m_mainSplitter->indexOf(m_fileList)); - m_fileList->hide(); - m_mainSplitter->replaceWidget(fileListIdx, tmpWidget); - tmpWidget->hide(); - - // Insert m_fileList into m_naviSplitter. - QWidget *wid = m_naviSplitter->replaceWidget(fileListIdx, m_fileList); - delete wid; - - m_fileList->show(); - } else { - // Disable compact mode and go back to two panels view. - if (!isCompactMode) { - return; - } - - // Take m_fileList out of m_naviSplitter. - Q_ASSERT(fileListIdx == m_naviSplitter->indexOf(m_fileList)); - QWidget *tmpWidget = new QWidget(this); - m_fileList->hide(); - m_naviSplitter->replaceWidget(fileListIdx, tmpWidget); - tmpWidget->hide(); - - // Insert m_fileList into m_mainSplitter. - QWidget *wid = m_mainSplitter->replaceWidget(fileListIdx, m_fileList); - delete wid; - - m_fileList->show(); - } - - // Set Tab order. - setTabOrder(directoryTree, m_fileList->getContentWidget()); -} - -void VMainWindow::changePanelView(PanelViewState p_state, bool p_postCheck) +void VMainWindow::changePanelView(PanelViewState p_state) { switch (p_state) { case PanelViewState::ExpandMode: - m_mainSplitter->widget(0)->hide(); - m_mainSplitter->widget(1)->hide(); - m_mainSplitter->widget(2)->show(); - break; - - case PanelViewState::SinglePanel: - enableCompactMode(false); - m_mainSplitter->widget(0)->hide(); m_mainSplitter->widget(1)->show(); - m_mainSplitter->widget(2)->show(); break; - case PanelViewState::TwoPanels: - enableCompactMode(false); - + case PanelViewState::HorizontalMode: + case PanelViewState::VerticalMode: m_mainSplitter->widget(0)->show(); m_mainSplitter->widget(1)->show(); - m_mainSplitter->widget(2)->show(); - break; - - case PanelViewState::CompactMode: - m_mainSplitter->widget(0)->show(); - m_mainSplitter->widget(1)->hide(); - m_mainSplitter->widget(2)->show(); - - enableCompactMode(true); break; default: break; } - // Change the action state. - QList acts = m_viewActGroup->actions(); - for (auto & act : acts) { - if (act->data().toInt() == (int)p_state) { - act->setChecked(true); - } else { - act->setChecked(false); - } - } - - if (p_state != PanelViewState::ExpandMode) { - expandViewAct->setChecked(false); - } - - if (p_postCheck) { - m_panelViewTimer->start(); - } + expandViewAct->setChecked(p_state == PanelViewState::ExpandMode); } void VMainWindow::updateWindowTitle(const QString &str) @@ -2297,16 +2106,8 @@ void VMainWindow::saveStateAndGeometry() g_config->setMainWindowState(saveState()); g_config->setToolsDockChecked(m_toolDock->isVisible()); g_config->setSearchDockChecked(m_searchDock->isVisible()); - - if (m_panelViewState == PanelViewState::CompactMode) { - g_config->setNaviSplitterState(m_naviSplitter->saveState()); - g_config->setMainSplitterState(m_mainSplitter->saveState()); - } else { - // In one panel view, it will save the wrong state that the directory tree - // panel has a width of zero. - changePanelView(PanelViewState::TwoPanels); - g_config->setMainSplitterState(m_mainSplitter->saveState()); - } + g_config->setNotebookSplitterState(m_nbSplitter->saveState()); + g_config->setMainSplitterState(m_mainSplitter->saveState()); } void VMainWindow::restoreStateAndGeometry() @@ -2329,9 +2130,9 @@ void VMainWindow::restoreStateAndGeometry() m_mainSplitter->restoreState(splitterState); } - const QByteArray &naviSplitterState = g_config->getNaviSplitterState(); - if (!naviSplitterState.isEmpty()) { - m_naviSplitter->restoreState(naviSplitterState); + const QByteArray &nbSplitterState = g_config->getNotebookSplitterState(); + if (!nbSplitterState.isEmpty()) { + m_nbSplitter->restoreState(nbSplitterState); } } @@ -2370,12 +2171,12 @@ bool VMainWindow::locateFile(VFile *p_file) VNoteFile *file = dynamic_cast(p_file); VNotebook *notebook = file->getNotebook(); if (m_notebookSelector->locateNotebook(notebook)) { - while (directoryTree->currentNotebook() != notebook) { + while (m_dirTree->currentNotebook() != notebook) { QCoreApplication::sendPostedEvents(); } VDirectory *dir = file->getDirectory(); - if (directoryTree->locateDirectory(dir)) { + if (m_dirTree->locateDirectory(dir)) { while (m_fileList->currentDirectory() != dir) { QCoreApplication::sendPostedEvents(); } @@ -2389,11 +2190,7 @@ bool VMainWindow::locateFile(VFile *p_file) // Open the directory and file panels after location. if (ret) { - if (m_panelViewState == PanelViewState::CompactMode) { - compactModeView(); - } else { - twoPanelView(); - } + showNotebookPanel(); } return ret; @@ -2408,23 +2205,19 @@ bool VMainWindow::locateDirectory(VDirectory *p_directory) VNotebook *notebook = p_directory->getNotebook(); if (m_notebookSelector->locateNotebook(notebook)) { - while (directoryTree->currentNotebook() != notebook) { + while (m_dirTree->currentNotebook() != notebook) { QCoreApplication::sendPostedEvents(); } - if (directoryTree->locateDirectory(p_directory)) { + if (m_dirTree->locateDirectory(p_directory)) { ret = true; - directoryTree->setFocus(); + m_dirTree->setFocus(); } } // Open the directory and file panels after location. if (ret) { - if (m_panelViewState == PanelViewState::CompactMode) { - compactModeView(); - } else { - twoPanelView(); - } + showNotebookPanel(); } return ret; @@ -2439,16 +2232,12 @@ bool VMainWindow::locateNotebook(VNotebook *p_notebook) if (m_notebookSelector->locateNotebook(p_notebook)) { ret = true; - directoryTree->setFocus(); + m_dirTree->setFocus(); } // Open the directory and file panels after location. if (ret) { - if (m_panelViewState == PanelViewState::CompactMode) { - compactModeView(); - } else { - twoPanelView(); - } + showNotebookPanel(); } return ret; @@ -2826,19 +2615,6 @@ bool VMainWindow::toggleExpandModeByCaptain(void *p_target, void *p_data) return true; } -bool VMainWindow::toggleOnePanelViewByCaptain(void *p_target, void *p_data) -{ - Q_UNUSED(p_data); - VMainWindow *obj = static_cast(p_target); - if (obj->m_panelViewState == PanelViewState::TwoPanels) { - obj->onePanelView(); - } else { - obj->twoPanelView(); - } - - return true; -} - bool VMainWindow::discardAndReadByCaptain(void *p_target, void *p_data) { Q_UNUSED(p_data); @@ -3235,7 +3011,7 @@ void VMainWindow::updateEditReadAct(const VEditTab *p_tab) void VMainWindow::handleExportAct() { VExportDialog dialog(m_notebookSelector->currentNotebook(), - directoryTree->currentDirectory(), + m_dirTree->currentDirectory(), m_curFile, m_cart, g_config->getMdConverterType(), @@ -3343,83 +3119,6 @@ void VMainWindow::setMenuBarVisible(bool p_visible) } } -void VMainWindow::postChangePanelView() -{ - const int minVal = 10; - bool needUpdate = false; - QList sizes = m_mainSplitter->sizes(); - switch (m_panelViewState) { - case PanelViewState::SinglePanel: - if (sizes[1] == 0) { - sizes[1] = minVal; - needUpdate = true; - } - - if (sizes[2] == 0) { - sizes[2] = minVal; - needUpdate = true; - } - - break; - - case PanelViewState::TwoPanels: - if (sizes[0] == 0) { - sizes[0] = minVal; - needUpdate = true; - } - - if (sizes[1] == 0) { - sizes[1] = minVal; - needUpdate = true; - } - - if (sizes[2] == 0) { - sizes[2] = minVal; - needUpdate = true; - } - - break; - - case PanelViewState::CompactMode: - { - if (sizes[0] == 0) { - sizes[0] = minVal; - needUpdate = true; - } - - if (sizes[2] == 0) { - sizes[2] = minVal; - needUpdate = true; - } - - bool naviUpdate = false; - QList naviSizes = m_naviSplitter->sizes(); - if (naviSizes[0] == 0) { - naviSizes[0] = minVal; - naviUpdate = true; - } - - if (naviSizes[1] == 0) { - naviSizes[1] = minVal; - naviUpdate = true; - } - - if (naviUpdate) { - m_naviSplitter->setSizes(naviSizes); - } - - break; - } - - default: - break; - } - - if (needUpdate) { - m_mainSplitter->setSizes(sizes); - } -} - void VMainWindow::kickOffStartUpTimer(const QStringList &p_files) { QTimer::singleShot(300, [this, p_files]() { @@ -3431,3 +3130,9 @@ void VMainWindow::kickOffStartUpTimer(const QStringList &p_files) openFiles(p_files, false, OpenFileMode::Read, false, true); }); } + +void VMainWindow::showNotebookPanel() +{ + changePanelView(PanelViewState::VerticalMode); + m_naviBox->setCurrentIndex(0, false); +} diff --git a/src/vmainwindow.h b/src/vmainwindow.h index d94cc870..b36da0bf 100644 --- a/src/vmainwindow.h +++ b/src/vmainwindow.h @@ -46,9 +46,8 @@ class VUniversalEntry; enum class PanelViewState { ExpandMode, - SinglePanel, - TwoPanels, - CompactMode, + HorizontalMode, + VerticalMode, Invalid }; @@ -140,9 +139,6 @@ private slots: void changeHighlightSelectedWord(bool p_checked); void changeHighlightSearchedWord(bool p_checked); void changeHighlightTrailingSapce(bool p_checked); - void onePanelView(); - void twoPanelView(); - void compactModeView(); void curEditFileInfo(); void deleteCurNote(); void handleCurrentDirectoryChanged(const VDirectory *p_dir); @@ -164,9 +160,6 @@ private slots: // Open export dialog. void handleExportAct(); - // Set the panel view properly. - void enableCompactMode(bool p_enabled); - // Handle Vim status updated. void handleVimStatusUpdated(const VVim *p_vim); @@ -196,9 +189,6 @@ private slots: // Activate Universal Entry. void activateUniversalEntry(); - // Make sure width of the panel is not zero after changePanelView(). - void postChangePanelView(); - protected: void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; @@ -208,7 +198,8 @@ protected: private: void setupUI(); - QWidget *setupDirectoryPanel(); + + void setupNotebookPanel(); void initToolBar(); @@ -280,8 +271,7 @@ private: void initTrayIcon(); // Change the panel view according to @p_state. - // Will not change m_panelViewState. - void changePanelView(PanelViewState p_state, bool p_postCheck = false); + void changePanelView(PanelViewState p_state); // Whether heading sequence is applicable to current tab. // Only available for writable Markdown file. @@ -299,6 +289,8 @@ private: void setMenuBarVisible(bool p_visible); + void showNotebookPanel(); + // Captain mode functions. // Popup the attachment list if it is enabled. @@ -308,8 +300,6 @@ private: static bool toggleExpandModeByCaptain(void *p_target, void *p_data); - static bool toggleOnePanelViewByCaptain(void *p_target, void *p_data); - static bool discardAndReadByCaptain(void *p_target, void *p_data); static bool toggleToolsDockByCaptain(void *p_target, void *p_data); @@ -333,15 +323,18 @@ private: VCaptain *m_captain; VNotebookSelector *m_notebookSelector; + VFileList *m_fileList; - VDirectoryTree *directoryTree; + + VDirectoryTree *m_dirTree; + + VToolBox *m_naviBox; // Splitter for directory | files | edit. QSplitter *m_mainSplitter; - // Splitter for directory | files. - // Move directory and file panel in one compact vertical split. - QSplitter *m_naviSplitter; + // Splitter for folders/notes. + QSplitter *m_nbSplitter; VEditArea *m_editArea; @@ -371,9 +364,6 @@ private: VTabIndicator *m_tabIndicator; - // SinglePanel, TwoPanels, CompactMode. - PanelViewState m_panelViewState; - // Actions QAction *newRootDirAct; QAction *newNoteAct; @@ -415,9 +405,6 @@ private: // Act group for code block render styles. QActionGroup *m_codeBlockStyleActs; - // Act group for panel view actions. - QActionGroup *m_viewActGroup; - // Menus QMenu *m_viewMenu; @@ -440,9 +427,6 @@ private: // Timer to check the shared memory between instances of VNote. QTimer *m_sharedMemTimer; - // Timer to check the panel size. - QTimer *m_panelViewTimer; - // Tray icon. QSystemTrayIcon *m_trayIcon; @@ -499,7 +483,7 @@ inline VCart *VMainWindow::getCart() const inline VDirectoryTree *VMainWindow::getDirectoryTree() const { - return directoryTree; + return m_dirTree; } inline VNotebookSelector *VMainWindow::getNotebookSelector() const diff --git a/src/vnote.qrc b/src/vnote.qrc index 7bd0ee56..268d9110 100644 --- a/src/vnote.qrc +++ b/src/vnote.qrc @@ -20,8 +20,6 @@ resources/icons/dir_info.svg resources/icons/notebook_info.svg resources/icons/expand.svg - resources/icons/two_panels.svg - resources/icons/one_panel.svg resources/icons/split_window.svg resources/icons/corner_menu.svg resources/icons/remove_split.svg @@ -92,7 +90,6 @@ resources/icons/delete_attachment.svg resources/icons/sort.svg resources/icons/create_subdir.svg - resources/icons/compact_mode.svg resources/icons/heading_sequence.svg resources/icons/link.svg resources/icons/code_block.svg @@ -216,5 +213,6 @@ utils/markdown-it/markdown-it-front-matter.js utils/markdown-it/markdown-it-imsize.min.js utils/markdown-it/markdown-it-emoji.min.js + resources/icons/notebook.svg diff --git a/src/vtoolbox.cpp b/src/vtoolbox.cpp index 7a113489..d3e9b83d 100644 --- a/src/vtoolbox.cpp +++ b/src/vtoolbox.cpp @@ -40,7 +40,10 @@ void VToolBox::setupUI() setLayout(mainLayout); } -int VToolBox::addItem(QWidget *p_widget, const QString &p_iconFile, const QString &p_text) +int VToolBox::addItem(QWidget *p_widget, + const QString &p_iconFile, + const QString &p_text, + QWidget *p_focusWidget) { int idx = m_items.size(); @@ -66,6 +69,7 @@ int VToolBox::addItem(QWidget *p_widget, const QString &p_iconFile, const QStrin m_widgetLayout->insertWidget(idx, p_widget); m_items.push_back(ItemInfo(p_widget, + p_focusWidget, p_text, btn, icon, @@ -78,7 +82,7 @@ int VToolBox::addItem(QWidget *p_widget, const QString &p_iconFile, const QStrin return idx; } -void VToolBox::setCurrentIndex(int p_idx) +void VToolBox::setCurrentIndex(int p_idx, bool p_focus) { if (p_idx < 0 || p_idx >= m_items.size()) { m_currentIndex = -1; @@ -91,12 +95,16 @@ void VToolBox::setCurrentIndex(int p_idx) m_widgetLayout->setCurrentIndex(m_currentIndex); QWidget *widget = m_widgetLayout->widget(m_currentIndex); - if (widget) { - widget->setFocus(); + if (widget && p_focus) { + if (m_items[m_currentIndex].m_focusWidget) { + m_items[m_currentIndex].m_focusWidget->setFocus(); + } else { + widget->setFocus(); + } } } -void VToolBox::setCurrentWidget(QWidget *p_widget) +void VToolBox::setCurrentWidget(QWidget *p_widget, bool p_focus) { int idx = -1; for (int i = 0; i < m_items.size(); ++i) { @@ -106,7 +114,7 @@ void VToolBox::setCurrentWidget(QWidget *p_widget) } } - setCurrentIndex(idx); + setCurrentIndex(idx, p_focus); } void VToolBox::setCurrentButtonIndex(int p_idx) diff --git a/src/vtoolbox.h b/src/vtoolbox.h index bb6462d3..533f342a 100644 --- a/src/vtoolbox.h +++ b/src/vtoolbox.h @@ -18,11 +18,14 @@ class VToolBox : public QWidget, public VNavigationMode public: explicit VToolBox(QWidget *p_parent = nullptr); - int addItem(QWidget *p_widget, const QString &p_iconFile, const QString &p_text); + int addItem(QWidget *p_widget, + const QString &p_iconFile, + const QString &p_text, + QWidget *p_focusWidget = nullptr); - void setCurrentIndex(int p_idx); + void setCurrentIndex(int p_idx, bool p_focus = true); - void setCurrentWidget(QWidget *p_widget); + void setCurrentWidget(QWidget *p_widget, bool p_focus = true); // Implementations for VNavigationMode. void showNavigation() Q_DECL_OVERRIDE; @@ -32,16 +35,20 @@ private: struct ItemInfo { ItemInfo() - : m_widget(nullptr), m_btn(nullptr) + : m_widget(nullptr), + m_focusWidget(nullptr), + m_btn(nullptr) { } ItemInfo(QWidget *p_widget, + QWidget *p_focusWidget, const QString &p_text, QPushButton *p_btn, const QIcon &p_icon, const QIcon &p_activeIcon) : m_widget(p_widget), + m_focusWidget(p_focusWidget), m_text(p_text), m_btn(p_btn), m_icon(p_icon), @@ -50,6 +57,7 @@ private: } QWidget *m_widget; + QWidget *m_focusWidget; QString m_text; QPushButton *m_btn;