TagExplorer: support spliting file list out

This commit is contained in:
Le Tan 2018-11-03 20:45:49 +08:00
parent 73b1db7a52
commit 64d2aab76a
4 changed files with 67 additions and 7 deletions

View File

@ -275,6 +275,9 @@ keyboard_layout=
; Whether split file list out of the notebook panel
split_file_list=false
; Whether split file list out of the tag explorer
split_tag_file_list=false
[editor]
; Auto indent as previous line
auto_indent=true

View File

@ -605,6 +605,9 @@ public:
bool getEnableSplitFileList() const;
void setEnableSplitFileList(bool p_enable);
bool getEnableSplitTagFileList() const;
void setEnableSplitTagFileList(bool p_enable);
private:
// Look up a config from user and default settings.
QVariant getConfigFromSettings(const QString &section, const QString &key) const;
@ -2822,4 +2825,14 @@ inline void VConfigManager::setEnableSplitFileList(bool p_enable)
{
setConfigToSettings("global", "split_file_list", p_enable);
}
inline bool VConfigManager::getEnableSplitTagFileList() const
{
return getConfigFromSettings("global", "split_tag_file_list").toBool();
}
inline void VConfigManager::setEnableSplitTagFileList(bool p_enable)
{
setConfigToSettings("global", "split_tag_file_list", p_enable);
}
#endif // VCONFIGMANAGER_H

View File

@ -59,9 +59,36 @@ void VTagExplorer::setupUI()
}
});
QVBoxLayout *tagLayout = new QVBoxLayout();
tagLayout->addWidget(m_notebookLabel);
tagLayout->addWidget(m_tagList);
tagLayout->setContentsMargins(0, 0, 0, 0);
QWidget *tagWidget = new QWidget(this);
tagWidget->setLayout(tagLayout);
m_tagLabel = new QLabel(tr("Notes"), this);
m_tagLabel->setProperty("TitleLabel", true);
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) {
g_config->setEnableSplitTagFileList(p_checked);
setupFileListSplitOut(p_checked);
});
QHBoxLayout *titleLayout = new QHBoxLayout();
titleLayout->addWidget(m_tagLabel);
titleLayout->addWidget(m_splitBtn);
titleLayout->addStretch();
titleLayout->setContentsMargins(0, 0, 0, 0);
m_fileList = new VListWidget(this);
m_fileList->setAttribute(Qt::WA_MacShowFocusRect, false);
m_fileList->setContextMenuPolicy(Qt::CustomContextMenu);
@ -71,23 +98,22 @@ void VTagExplorer::setupUI()
connect(m_fileList, &QListWidget::customContextMenuRequested,
this, &VTagExplorer::handleFileListContextMenuRequested);
QWidget *fileWidget = new QWidget(this);
QVBoxLayout *fileLayout = new QVBoxLayout();
fileLayout->addWidget(m_tagLabel);
fileLayout->addLayout(titleLayout);
fileLayout->addWidget(m_fileList);
fileLayout->setContentsMargins(0, 0, 0, 0);
QWidget *fileWidget = new QWidget(this);
fileWidget->setLayout(fileLayout);
m_splitter = new QSplitter(this);
m_splitter->setOrientation(Qt::Vertical);
m_splitter->setObjectName("TagExplorerSplitter");
m_splitter->addWidget(m_tagList);
m_splitter->addWidget(tagWidget);
m_splitter->addWidget(fileWidget);
m_splitter->setStretchFactor(0, 1);
m_splitter->setStretchFactor(1, 2);
setupFileListSplitOut(g_config->getEnableSplitTagFileList());
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(m_notebookLabel);
mainLayout->addWidget(m_splitter);
mainLayout->setContentsMargins(0, 0, 0, 0);
@ -512,3 +538,17 @@ void VTagExplorer::registerNavigationTarget()
VNavigationModeListWidgetWrapper *fileWrapper = new VNavigationModeListWidgetWrapper(m_fileList, this);
g_mainWin->getCaptain()->registerNavigationTarget(fileWrapper);
}
void VTagExplorer::setupFileListSplitOut(bool p_enabled)
{
m_splitBtn->setChecked(p_enabled);
if (p_enabled) {
m_splitter->setOrientation(Qt::Horizontal);
m_splitter->setStretchFactor(0, 1);
m_splitter->setStretchFactor(1, 1);
} else {
m_splitter->setOrientation(Qt::Vertical);
m_splitter->setStretchFactor(0, 1);
m_splitter->setStretchFactor(1, 2);
}
}

View File

@ -81,12 +81,16 @@ private:
void promptToRemoveEmptyTag(const QString &p_tag);
void setupFileListSplitOut(bool p_enabled);
bool m_uiInitialized;
QLabel *m_notebookLabel;
QLabel *m_tagLabel;
QPushButton *m_splitBtn;
VListWidget *m_tagList;
VListWidget *m_fileList;