From 73b1db7a521ead79eb2f65bdd48805714598bdae Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 3 Nov 2018 20:03:12 +0800 Subject: [PATCH] NotebookPanel: support spliting file list out --- src/resources/vnote.ini | 3 +++ src/vconfigmanager.h | 15 ++++++++++++++- src/vfilelist.cpp | 22 +++++++++++++++++++++- src/vfilelist.h | 8 +++++++- src/vmainwindow.cpp | 31 ++++++++++++++++++++++++++++--- src/vmainwindow.h | 4 ++++ src/vtagexplorer.cpp | 4 ++-- 7 files changed, 79 insertions(+), 8 deletions(-) diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index c87161f8..3ed7bb4f 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -272,6 +272,9 @@ keyboard_layout_mapping_keys= ; Chosen keyboard layout mapping from keyboard_layouts.ini keyboard_layout= +; Whether split file list out of the notebook panel +split_file_list=false + [editor] ; Auto indent as previous line auto_indent=true diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index 56bef627..9b1c2172 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -602,6 +602,9 @@ public: const QString &getEditorFontFamily() const; void setEditorFontFamily(const QString &p_font); + bool getEnableSplitFileList() const; + void setEnableSplitFileList(bool p_enable); + private: // Look up a config from user and default settings. QVariant getConfigFromSettings(const QString §ion, const QString &key) const; @@ -1075,7 +1078,7 @@ private: // 2 - always int m_autoScrollCursorLine; - // Editor font family to override the value set by the style + // Editor font family to override the value set by the style. QString m_editorFontFamily; // The name of the config file in each directory. @@ -2809,4 +2812,14 @@ inline void VConfigManager::setEditorFontFamily(const QString &p_font) setConfigToSettings("editor", "editor_font_family", m_editorFontFamily); } + +inline bool VConfigManager::getEnableSplitFileList() const +{ + return getConfigFromSettings("global", "split_file_list").toBool(); +} + +inline void VConfigManager::setEnableSplitFileList(bool p_enable) +{ + setConfigToSettings("global", "split_file_list", p_enable); +} #endif // VCONFIGMANAGER_H diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index 7a3c4982..f3d4d81a 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -61,7 +61,9 @@ void VFileList::setupUI() QLabel *titleLabel = new QLabel(tr("Notes"), this); titleLabel->setProperty("TitleLabel", true); - QPushButton *viewBtn = new QPushButton(VIconUtils::buttonIcon(":/resources/icons/view.svg"), "", this); + QPushButton *viewBtn = new QPushButton(VIconUtils::buttonIcon(":/resources/icons/view.svg"), + "", + this); viewBtn->setToolTip(tr("View")); viewBtn->setProperty("CornerBtn", true); viewBtn->setFocusPolicy(Qt::NoFocus); @@ -73,11 +75,24 @@ void VFileList::setupUI() }); viewBtn->setMenu(viewMenu); + m_splitBtn = new QPushButton(VIconUtils::buttonIcon(":/resources/icons/split_window.svg"), + "", + this); + m_splitBtn->setToolTip(tr("Split")); + m_splitBtn->setCheckable(true); + m_splitBtn->setProperty("CornerBtn", true); + m_splitBtn->setFocusPolicy(Qt::NoFocus); + connect(m_splitBtn, &QPushButton::clicked, + this, [this](bool p_checked) { + emit requestSplitOut(p_checked); + }); + m_numLabel = new QLabel(this); QHBoxLayout *titleLayout = new QHBoxLayout(); titleLayout->addWidget(titleLabel); titleLayout->addWidget(viewBtn); + titleLayout->addWidget(m_splitBtn); titleLayout->addStretch(); titleLayout->addWidget(m_numLabel); @@ -1523,3 +1538,8 @@ QByteArray VFileList::getMimeData(const QString &p_format, return QJsonDocument(obj).toJson(QJsonDocument::Compact); } + +void VFileList::setEnableSplitOut(bool p_enabled) +{ + m_splitBtn->setChecked(p_enabled); +} diff --git a/src/vfilelist.h b/src/vfilelist.h index 488b83e9..bc131df4 100644 --- a/src/vfilelist.h +++ b/src/vfilelist.h @@ -54,6 +54,8 @@ public: const QVector &p_files, bool p_isCut); + void setEnableSplitOut(bool p_enabled); + // Implementations for VNavigationMode. void showNavigation() Q_DECL_OVERRIDE; bool handleKeyNavigation(int p_key, bool &p_succeed) Q_DECL_OVERRIDE; @@ -76,6 +78,9 @@ signals: void fileUpdated(const VNoteFile *p_file, UpdateAction p_act); + // Request to split self out of the notebook panel. + void requestSplitOut(bool p_enabled); + private slots: void contextMenuRequested(QPoint pos); @@ -195,6 +200,8 @@ private: VFileListWidget *fileList; + QPushButton *m_splitBtn; + QLabel *m_numLabel; QPointer m_directory; @@ -232,5 +239,4 @@ inline QWidget *VFileList::getContentWidget() const { return fileList; } - #endif // VFILELIST_H diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index ec75b05e..fe85f6bf 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -326,6 +326,9 @@ void VMainWindow::setupNaviBox() tr("Tags")); connect(m_notebookSelector, &VNotebookSelector::curNotebookChanged, m_tagExplorer, &VTagExplorer::setNotebook); + + connect(m_fileList, &VFileList::requestSplitOut, + this, &VMainWindow::splitFileListOut); } void VMainWindow::setupNotebookPanel() @@ -354,12 +357,11 @@ void VMainWindow::setupNotebookPanel() m_fileList->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, 1); - m_nbSplitter->setStretchFactor(1, 2); + + setupFileListSplitOut(g_config->getEnableSplitFileList()); connect(m_notebookSelector, &VNotebookSelector::curNotebookChanged, this, [this](VNotebook *p_notebook) { @@ -3455,3 +3457,26 @@ void VMainWindow::updateFontOfAllTabs() } } } + +void VMainWindow::splitFileListOut(bool p_enabled) +{ + showNotebookPanel(); + + g_config->setEnableSplitFileList(p_enabled); + + setupFileListSplitOut(p_enabled); +} + +void VMainWindow::setupFileListSplitOut(bool p_enabled) +{ + m_fileList->setEnableSplitOut(p_enabled); + if (p_enabled) { + m_nbSplitter->setOrientation(Qt::Horizontal); + m_nbSplitter->setStretchFactor(0, 1); + m_nbSplitter->setStretchFactor(1, 1); + } else { + m_nbSplitter->setOrientation(Qt::Vertical); + m_nbSplitter->setStretchFactor(0, 1); + m_nbSplitter->setStretchFactor(1, 2); + } +} diff --git a/src/vmainwindow.h b/src/vmainwindow.h index 52e6ce79..4a1f0b28 100644 --- a/src/vmainwindow.h +++ b/src/vmainwindow.h @@ -210,6 +210,8 @@ private slots: void stayOnTop(bool p_enabled); + void splitFileListOut(bool p_enabled); + protected: void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; @@ -224,6 +226,8 @@ private: void setupNotebookPanel(); + void setupFileListSplitOut(bool p_enabled); + void initToolBar(); QToolBar *initFileToolBar(QSize p_iconSize = QSize()); diff --git a/src/vtagexplorer.cpp b/src/vtagexplorer.cpp index 8c97a6de..cb761792 100644 --- a/src/vtagexplorer.cpp +++ b/src/vtagexplorer.cpp @@ -83,8 +83,8 @@ void VTagExplorer::setupUI() m_splitter->setObjectName("TagExplorerSplitter"); m_splitter->addWidget(m_tagList); m_splitter->addWidget(fileWidget); - m_splitter->setStretchFactor(0, 0); - m_splitter->setStretchFactor(1, 1); + m_splitter->setStretchFactor(0, 1); + m_splitter->setStretchFactor(1, 2); QVBoxLayout *mainLayout = new QVBoxLayout(); mainLayout->addWidget(m_notebookLabel);