setting tree match complete (#1932)

This commit is contained in:
chendapao 2021-12-09 18:40:51 +08:00 committed by GitHub
parent 911392deab
commit b369612070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 3 deletions

View File

@ -31,6 +31,10 @@ QWidget[DialogCentralWidget="true"] {
border: 1px solid @widgets#qwidget#error#border; border: 1px solid @widgets#qwidget#error#border;
} }
[HitSettingWidget="true"] {
border: 4px solid @widgets#qwidget#info#border;
}
/* QAbstractScrollArea */ /* QAbstractScrollArea */
QAbstractScrollArea { QAbstractScrollArea {
border: 1px solid @widgets#qabstractscrollarea#border; border: 1px solid @widgets#qabstractscrollarea#border;

View File

@ -22,6 +22,14 @@
#include "vipage.h" #include "vipage.h"
#include "notemanagementpage.h" #include "notemanagementpage.h"
#include <QDebug>
#include <QTimer>
#include <QColor>
#include "settingspage.h"
#include "utils/widgetutils.h"
#include "../../propertydefs.h"
#include <core/vnotex.h>
using namespace vnotex; using namespace vnotex;
SettingsDialog::SettingsDialog(QWidget *p_parent) SettingsDialog::SettingsDialog(QWidget *p_parent)
@ -67,6 +75,19 @@ void SettingsDialog::setupPageExplorer(QBoxLayout *p_layout, QWidget *p_parent)
m_searchEdit = WidgetsFactory::createLineEdit(p_parent); m_searchEdit = WidgetsFactory::createLineEdit(p_parent);
m_searchEdit->setPlaceholderText(tr("Search")); m_searchEdit->setPlaceholderText(tr("Search"));
layout->addWidget(m_searchEdit); layout->addWidget(m_searchEdit);
connect(m_searchEdit,&QLineEdit::textChanged,
this, [this]() { QTimer::singleShot(500, this, [this](){
forEachPage([this](SettingsPage *p_page) {
bool hit = p_page->search(m_searchEdit->text());
if (hit) {
qDebug() << p_page->title();
// 目前只能找到tree的 通过 外观 笔记管理快速访问与编辑器好像没有加入到tree的搜索中
// 不知道如何找到item并且高亮
}
return hit;
});
});
});
m_pageExplorer = new TreeWidget(TreeWidget::None, p_parent); m_pageExplorer = new TreeWidget(TreeWidget::None, p_parent);
TreeWidget::setupSingleColumnHeaderlessTree(m_pageExplorer, false, false); TreeWidget::setupSingleColumnHeaderlessTree(m_pageExplorer, false, false);

View File

@ -1,4 +1,6 @@
#include "settingspage.h" #include "settingspage.h"
#include "utils/widgetutils.h"
#include "../../propertydefs.h"
using namespace vnotex; using namespace vnotex;
@ -19,16 +21,17 @@ bool SettingsPage::search(const QString &p_key)
if (item.m_words.contains(p_key, Qt::CaseInsensitive)) { if (item.m_words.contains(p_key, Qt::CaseInsensitive)) {
// Continue to search all the matched targets. // Continue to search all the matched targets.
hit = true; hit = true;
searchHit(item.m_target); searchHit(item.m_target, true);
} }
} }
return hit; return hit;
} }
void SettingsPage::searchHit(QWidget *p_target) void SettingsPage::searchHit(QWidget *p_target, bool hit)
{ {
Q_UNUSED(p_target); Q_UNUSED(p_target);
WidgetUtils::setPropertyDynamically(p_target, PropertyDefs::c_hitSettingWidght, hit);
} }
void SettingsPage::addSearchItem(const QString &p_words, QWidget *p_target) void SettingsPage::addSearchItem(const QString &p_words, QWidget *p_target)

View File

@ -34,7 +34,7 @@ namespace vnotex
virtual bool saveInternal() = 0; virtual bool saveInternal() = 0;
// Subclass could override this method to highlight matched target. // Subclass could override this method to highlight matched target.
virtual void searchHit(QWidget *p_target); virtual void searchHit(QWidget *p_target, bool hit);
void addSearchItem(const QString &p_words, QWidget *p_target); void addSearchItem(const QString &p_words, QWidget *p_target);

View File

@ -25,3 +25,5 @@ const char *PropertyDefs::c_embeddedLineEdit = "EmbeddedLineEdit";
const char *PropertyDefs::c_dockWidgetIndex = "DockIndex"; const char *PropertyDefs::c_dockWidgetIndex = "DockIndex";
const char *PropertyDefs::c_dockWidgetTitle = "DockTitle"; const char *PropertyDefs::c_dockWidgetTitle = "DockTitle";
const char *PropertyDefs::c_hitSettingWidght = "HitSettingWidget";

View File

@ -33,6 +33,8 @@ namespace vnotex
static const char *c_dockWidgetIndex; static const char *c_dockWidgetIndex;
static const char *c_dockWidgetTitle; static const char *c_dockWidgetTitle;
static const char *c_hitSettingWidght;
}; };
} }