From 23a58c021444dbd1b55157247ff5876f5a9d3358 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sat, 13 Feb 2010 08:30:16 +0000 Subject: [PATCH] * TocWidget.{cpp,h}: * TocWidgetUi.ui: - add filter bar. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33457 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/TocWidget.cpp | 30 +++- src/frontends/qt4/TocWidget.h | 1 + src/frontends/qt4/ui/TocUi.ui | 238 ++++++++++++++++++-------------- 3 files changed, 163 insertions(+), 106 deletions(-) diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp index 49e96f511e..473d7de343 100644 --- a/src/frontends/qt4/TocWidget.cpp +++ b/src/frontends/qt4/TocWidget.cpp @@ -82,6 +82,8 @@ TocWidget::TocWidget(GuiView & gui_view, QWidget * parent) this, SLOT(showContextMenu(const QPoint &))); connect(tocTV, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showContextMenu(const QPoint &))); + connect(filterLE, SIGNAL(textEdited(QString)), + this, SLOT(filterContents())); init(QString()); } @@ -440,7 +442,6 @@ void TocWidget::updateView() && gui_view_.tocModels().isSorted(current_type_)); sortCB->blockSignals(false); - bool const can_navigate_ = canNavigate(current_type_); persistentCB->setEnabled(can_navigate_); @@ -456,11 +457,38 @@ void TocWidget::updateView() persistentCB->setChecked(persistent_); select(gui_view_.tocModels().currentIndex(current_type_)); } + filterContents(); tocTV->setEnabled(true); tocTV->setUpdatesEnabled(true); } +void TocWidget::filterContents() +{ + QModelIndexList indices = tocTV->model()->match( + tocTV->model()->index(0, 0), + Qt::DisplayRole, "*", -1, + Qt::MatchFlags(Qt::MatchWildcard|Qt::MatchRecursive)); + + int size = indices.size(); + for (int i = 0; i < size; i++) { + QModelIndex index = indices[i]; + bool const matches = + index.data().toString().contains( + filterLE->text(), Qt::CaseSensitive); + tocTV->setRowHidden(index.row(), index.parent(), !matches); + } + // recursively unhide parents of unhidden children + for (int i = size - 1; i >= 0; i--) { + QModelIndex index = indices[i]; + if (!tocTV->isRowHidden(index.row(), index.parent()) + && index.parent() != QModelIndex()) + tocTV->setRowHidden(index.parent().row(), + index.parent().parent(), false); + } +} + + static QString decodeType(QString const & str) { QString type = str; diff --git a/src/frontends/qt4/TocWidget.h b/src/frontends/qt4/TocWidget.h index d2ca8b8375..7c7ca3f0e3 100644 --- a/src/frontends/qt4/TocWidget.h +++ b/src/frontends/qt4/TocWidget.h @@ -63,6 +63,7 @@ protected Q_SLOTS: void on_moveDownTB_clicked(); void on_moveInTB_clicked(); void on_moveOutTB_clicked(); + void filterContents(); void showContextMenu(const QPoint & pos); diff --git a/src/frontends/qt4/ui/TocUi.ui b/src/frontends/qt4/ui/TocUi.ui index 5fd75fbb83..8491a12552 100644 --- a/src/frontends/qt4/ui/TocUi.ui +++ b/src/frontends/qt4/ui/TocUi.ui @@ -9,13 +9,46 @@ 0 0 202 - 332 + 355 - + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + Filter: + + + filterLE + + + + + + + Enter string to filter contents + + + + + @@ -31,7 +64,7 @@ - + @@ -43,102 +76,14 @@ - - - - - 13 - 0 - 0 - 0 - - - - Adjust the depth of the navigation tree - - - 5 - - - 1 - - - 2 - - - Qt::Horizontal - - - QSlider::TicksBothSides - - - - - - - 0 - - - QLayout::SetMinimumSize - + + - 4 + 0 - - - - - 0 - 0 - 0 - 0 - - - - - 0 - 21 - - - - Sort - - - - - - - - 0 - 1 - 0 - 0 - - - - - 0 - 21 - - - - Try to keep persistent view of the uncollapsed nodes - - - Keep - - - - - - - 6 - - 0 - @@ -148,8 +93,7 @@ ... - - ../../../../lib/images/reload.png../../../../lib/images/reload.png + ../../../../lib/images/reload.png @@ -164,7 +108,7 @@ Qt::Horizontal - + 16 20 @@ -181,8 +125,7 @@ ... - - ../../../../lib/images/promote.png../../../../lib/images/promote.png + ../../../../lib/images/promote.png @@ -201,8 +144,7 @@ ... - - ../../../../lib/images/demote.png../../../../lib/images/demote.png + ../../../../lib/images/demote.png @@ -221,8 +163,7 @@ ... - - ../../../../lib/images/down.png../../../../lib/images/down.png + ../../../../lib/images/down.png @@ -241,8 +182,7 @@ ... - - ../../../../lib/images/up.png../../../../lib/images/up.png + ../../../../lib/images/up.png @@ -254,6 +194,94 @@ + + + + 4 + + + 0 + + + QLayout::SetMinimumSize + + + + + + 0 + 0 + 0 + 0 + + + + + 0 + 21 + + + + Sort + + + + + + + + 0 + 1 + 0 + 0 + + + + + 0 + 21 + + + + Try to keep persistent view of the uncollapsed nodes + + + Keep + + + + + + + + + + 13 + 0 + 0 + 0 + + + + Adjust the depth of the navigation tree + + + 5 + + + 1 + + + 2 + + + Qt::Horizontal + + + QSlider::TicksBothSides + + + -- 2.39.2