From 4727d0aa9894848b3c1bf7617440a81aa06ec6e1 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 28 Mar 2018 19:36:35 +0800 Subject: [PATCH] refine interfaces --- .../themes/v_material/v_material.palette | 2 +- .../themes/v_material/v_material.qss | 5 ---- .../themes/v_moonlight/v_moonlight.palette | 2 +- .../themes/v_moonlight/v_moonlight.qss | 4 --- .../themes/v_native/v_native.palette | 2 +- src/resources/themes/v_native/v_native.qss | 4 --- src/resources/themes/v_pure/v_pure.palette | 2 +- src/resources/themes/v_pure/v_pure.qss | 4 --- src/vcart.cpp | 19 ++++++++------ src/vcart.h | 2 ++ src/vfilelist.cpp | 26 +++++++++++++++++++ src/vfilelist.h | 6 +++++ src/vmainwindow.cpp | 11 +++----- src/vmainwindow.h | 2 -- src/vsnippetlist.cpp | 14 +++++++--- src/vsnippetlist.h | 2 ++ 16 files changed, 65 insertions(+), 42 deletions(-) diff --git a/src/resources/themes/v_material/v_material.palette b/src/resources/themes/v_material/v_material.palette index dc4d3697..0a6820ed 100644 --- a/src/resources/themes/v_material/v_material.palette +++ b/src/resources/themes/v_material/v_material.palette @@ -6,7 +6,7 @@ qss_file=v_material.qss mdhl_file=v_material.mdhl css_file=v_material.css codeblock_css_file=v_material_codeblock.css -vsersion=1 +version=2 [phony] ; Abstract color attributes. diff --git a/src/resources/themes/v_material/v_material.qss b/src/resources/themes/v_material/v_material.qss index 64efa0a4..c59427b9 100644 --- a/src/resources/themes/v_material/v_material.qss +++ b/src/resources/themes/v_material/v_material.qss @@ -10,11 +10,6 @@ QWidget { color: @widget_fg; } - -QWidget[NotebookPanel="true"] { - padding-left: 3px; -} - /* End QWidget */ /* QMainWindow */ diff --git a/src/resources/themes/v_moonlight/v_moonlight.palette b/src/resources/themes/v_moonlight/v_moonlight.palette index 5d3cabe1..7b7b9b07 100644 --- a/src/resources/themes/v_moonlight/v_moonlight.palette +++ b/src/resources/themes/v_moonlight/v_moonlight.palette @@ -7,7 +7,7 @@ mdhl_file=v_moonlight.mdhl css_file=v_moonlight.css codeblock_css_file=v_moonlight_codeblock.css mermaid_css_file=v_moonlight_mermaid.css -version=6 +version=7 ; This mapping will be used to translate colors when the content of HTML is copied ; without background. You could just specify the foreground colors mapping here. diff --git a/src/resources/themes/v_moonlight/v_moonlight.qss b/src/resources/themes/v_moonlight/v_moonlight.qss index aa2bffbb..84e13c30 100644 --- a/src/resources/themes/v_moonlight/v_moonlight.qss +++ b/src/resources/themes/v_moonlight/v_moonlight.qss @@ -6,10 +6,6 @@ QToolTip } /* QWidget */ -QWidget[NotebookPanel="true"] { - padding-left: 3px; -} - QWidget#FindReplaceTitleWidget { background: @title_bg; } diff --git a/src/resources/themes/v_native/v_native.palette b/src/resources/themes/v_native/v_native.palette index 27d37c21..7d951a31 100644 --- a/src/resources/themes/v_native/v_native.palette +++ b/src/resources/themes/v_native/v_native.palette @@ -7,7 +7,7 @@ mdhl_file=v_native.mdhl css_file=v_native.css codeblock_css_file=v_native_codeblock.css mermaid_css_file=v_native_mermaid.css -version=6 +version=7 [phony] ; Abstract color attributes. diff --git a/src/resources/themes/v_native/v_native.qss b/src/resources/themes/v_native/v_native.qss index db992501..aa16633c 100644 --- a/src/resources/themes/v_native/v_native.qss +++ b/src/resources/themes/v_native/v_native.qss @@ -4,10 +4,6 @@ QWidget color: @widget_fg; font-family: "Hiragino Sans GB", "冬青黑体", "Microsoft YaHei", "微软雅黑", "Microsoft YaHei UI", "WenQuanYi Micro Hei", "文泉驿雅黑", "Dengxian", "等线体", "STXihei", "华文细黑", "Liberation Sans", "Droid Sans", "NSimSun", "新宋体", "SimSun", "宋体", "Helvetica", "sans-serif", "Tahoma", "Arial", "Verdana", "Geneva", "Georgia", "Times New Roman"; } - -QWidget[NotebookPanel="true"] { - padding-left: 3px; -} /* End QWidget */ /* QMenuBar */ diff --git a/src/resources/themes/v_pure/v_pure.palette b/src/resources/themes/v_pure/v_pure.palette index e8f0818a..2d18967f 100644 --- a/src/resources/themes/v_pure/v_pure.palette +++ b/src/resources/themes/v_pure/v_pure.palette @@ -7,7 +7,7 @@ mdhl_file=v_pure.mdhl css_file=v_pure.css codeblock_css_file=v_pure_codeblock.css mermaid_css_file=v_pure_mermaid.css -version=6 +version=7 [phony] ; Abstract color attributes. diff --git a/src/resources/themes/v_pure/v_pure.qss b/src/resources/themes/v_pure/v_pure.qss index 6e77bc6f..1a4605f2 100644 --- a/src/resources/themes/v_pure/v_pure.qss +++ b/src/resources/themes/v_pure/v_pure.qss @@ -6,10 +6,6 @@ QToolTip } /* QWidget */ -QWidget[NotebookPanel="true"] { - padding-left: 3px; -} - QWidget#FindReplaceTitleWidget { background: @title_bg; } diff --git a/src/vcart.cpp b/src/vcart.cpp index 61c08893..d36de566 100644 --- a/src/vcart.cpp +++ b/src/vcart.cpp @@ -19,6 +19,8 @@ VCart::VCart(QWidget *p_parent) { setupUI(); + updateNumberLabel(); + initActions(); } @@ -40,6 +42,7 @@ void VCart::setupUI() MessageBoxType::Danger); if (ret == QMessageBox::Ok) { m_itemList->clear(); + updateNumberLabel(); } } }); @@ -158,14 +161,7 @@ void VCart::addItem(const QString &p_path) item->setData(Qt::UserRole, p_path); m_itemList->addItem(item); - - int cnt = m_itemList->count(); - if (cnt > 0) { - m_numLabel->setText(tr("%1 %2").arg(cnt) - .arg(cnt > 1 ? tr("Items") : tr("Item"))); - } else { - m_numLabel->setText(""); - } + updateNumberLabel(); } void VCart::deleteSelectedItems() @@ -263,3 +259,10 @@ void VCart::sortItems() VListWidget::sortListWidget(m_itemList, sortedIdx); } } + +void VCart::updateNumberLabel() const +{ + int cnt = m_itemList->count(); + m_numLabel->setText(tr("%1 %2").arg(cnt) + .arg(cnt > 1 ? tr("Items") : tr("Item"))); +} diff --git a/src/vcart.h b/src/vcart.h index b67eed9a..dc36ec6f 100644 --- a/src/vcart.h +++ b/src/vcart.h @@ -51,6 +51,8 @@ private: QString getFilePath(const QListWidgetItem *p_item) const; + void updateNumberLabel() const; + QPushButton *m_clearBtn; QLabel *m_numLabel; QListWidget *m_itemList; diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index 03dfd4b5..067c52b4 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -56,10 +56,24 @@ VFileList::VFileList(QWidget *parent) fileList->setFocus(); } }); + + updateNumberLabel(); } void VFileList::setupUI() { + QLabel *titleLabel = new QLabel(tr("Notes"), this); + titleLabel->setProperty("TitleLabel", true); + + m_numLabel = new QLabel(this); + + QHBoxLayout *titleLayout = new QHBoxLayout(); + titleLayout->addWidget(titleLabel); + titleLayout->addStretch(); + titleLayout->addWidget(m_numLabel); + + titleLayout->setContentsMargins(0, 0, 0, 0); + fileList = new VListWidget(this); fileList->setContextMenuPolicy(Qt::CustomContextMenu); fileList->setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -67,6 +81,7 @@ void VFileList::setupUI() fileList->setAttribute(Qt::WA_MacShowFocusRect, false); QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(titleLayout); mainLayout->addWidget(fileList); mainLayout->setContentsMargins(0, 0, 0, 0); @@ -198,6 +213,7 @@ void VFileList::setDirectory(VDirectory *p_directory) if (m_directory == p_directory) { if (!m_directory) { fileList->clearAll(); + updateNumberLabel(); } return; @@ -206,6 +222,7 @@ void VFileList::setDirectory(VDirectory *p_directory) m_directory = p_directory; if (!m_directory) { fileList->clearAll(); + updateNumberLabel(); return; } @@ -224,6 +241,8 @@ void VFileList::updateFileList() VNoteFile *file = files[i]; insertFileListItem(file); } + + updateNumberLabel(); } void VFileList::fileInfo() @@ -1188,3 +1207,10 @@ void VFileList::handleOpenWithActionTriggered() } } } + +void VFileList::updateNumberLabel() const +{ + int cnt = fileList->count(); + m_numLabel->setText(tr("%1 %2").arg(cnt) + .arg(cnt > 1 ? tr("Items") : tr("Item"))); +} diff --git a/src/vfilelist.h b/src/vfilelist.h index fcfdf83c..71e7dfeb 100644 --- a/src/vfilelist.h +++ b/src/vfilelist.h @@ -166,8 +166,14 @@ private: void activateItem(QListWidgetItem *p_item, bool p_restoreFocus = false); + void updateNumberLabel() const; + VEditArea *editArea; + VListWidget *fileList; + + QLabel *m_numLabel; + QPointer m_directory; // Magic number for clipboard operations. diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index d359f6f0..12ee1953 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -276,22 +276,18 @@ void VMainWindow::setupUI() QWidget *VMainWindow::setupDirectoryPanel() { // Notebook selector. - notebookLabel = new QLabel(tr("Notebooks")); + QLabel *notebookLabel = new QLabel(tr("Notebooks")); notebookLabel->setProperty("TitleLabel", true); - notebookLabel->setProperty("NotebookPanel", true); notebookSelector = new VNotebookSelector(); notebookSelector->setObjectName("NotebookSelector"); - notebookSelector->setProperty("NotebookPanel", true); notebookSelector->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); // Navigation panel. - directoryLabel = new QLabel(tr("Folders")); + QLabel *directoryLabel = new QLabel(tr("Folders")); directoryLabel->setProperty("TitleLabel", true); - directoryLabel->setProperty("NotebookPanel", true); directoryTree = new VDirectoryTree; - directoryTree->setProperty("NotebookPanel", true); QVBoxLayout *naviLayout = new QVBoxLayout; naviLayout->addWidget(directoryLabel); @@ -318,10 +314,9 @@ QWidget *VMainWindow::setupDirectoryPanel() nbLayout->addWidget(notebookLabel); nbLayout->addWidget(notebookSelector); nbLayout->addWidget(m_naviSplitter); - nbLayout->setContentsMargins(0, 0, 0, 0); + nbLayout->setContentsMargins(3, 0, 0, 0); nbLayout->setSpacing(0); QWidget *nbContainer = new QWidget(); - nbContainer->setObjectName("NotebookPanel"); nbContainer->setLayout(nbLayout); nbContainer->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); diff --git a/src/vmainwindow.h b/src/vmainwindow.h index 2e61bed4..0b4ed9c5 100644 --- a/src/vmainwindow.h +++ b/src/vmainwindow.h @@ -315,8 +315,6 @@ private: VCaptain *m_captain; - QLabel *notebookLabel; - QLabel *directoryLabel; VNotebookSelector *notebookSelector; VFileList *m_fileList; VDirectoryTree *directoryTree; diff --git a/src/vsnippetlist.cpp b/src/vsnippetlist.cpp index 20f10a1b..ae911e25 100644 --- a/src/vsnippetlist.cpp +++ b/src/vsnippetlist.cpp @@ -39,6 +39,8 @@ VSnippetList::VSnippetList(QWidget *p_parent) } updateContent(); + + updateNumberLabel(); } void VSnippetList::setupUI() @@ -394,13 +396,12 @@ void VSnippetList::updateContent() int cnt = m_snippetList->count(); if (cnt > 0) { - m_numLabel->setText(tr("%1 %2").arg(cnt) - .arg(cnt > 1 ? tr("Snippets") : tr("Snippet"))); m_snippetList->setFocus(); } else { - m_numLabel->setText(""); m_addBtn->setFocus(); } + + updateNumberLabel(); } bool VSnippetList::addSnippet(const VSnippet &p_snippet, QString *p_errMsg) @@ -623,3 +624,10 @@ void VSnippetList::focusInEvent(QFocusEvent *p_event) m_snippetList->setFocus(); } } + +void VSnippetList::updateNumberLabel() const +{ + int cnt = m_snippetList->count(); + m_numLabel->setText(tr("%1 %2").arg(cnt) + .arg(cnt > 1 ? tr("Items") : tr("Item"))); +} diff --git a/src/vsnippetlist.h b/src/vsnippetlist.h index daa307f1..af396082 100644 --- a/src/vsnippetlist.h +++ b/src/vsnippetlist.h @@ -87,6 +87,8 @@ private: bool deleteSnippetFile(const VSnippet &p_snippet, QString *p_errMsg = nullptr); + void updateNumberLabel() const; + QPushButton *m_addBtn; QPushButton *m_locateBtn; QLabel *m_numLabel;