From 23a58c021444dbd1b55157247ff5876f5a9d3358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?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 | 338 +++++++++++++++++--------------- 3 files changed, 213 insertions(+), 156 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,47 +76,135 @@ - - - - - 13 - 0 - 0 - 0 - + + + + 0 - - Adjust the depth of the navigation tree + + 6 - - 5 - - - 1 - - - 2 - - - Qt::Horizontal - - - QSlider::TicksBothSides - - + + + + Update navigation tree + + + ... + + + ../../../../lib/images/reload.png + + + + 20 + 20 + + + + + + + + Qt::Horizontal + + + + 16 + 20 + + + + + + + + Decrease nesting depth of selected item + + + ... + + + ../../../../lib/images/promote.png + + + + 20 + 20 + + + + + + + + Increase nesting depth of selected item + + + ... + + + ../../../../lib/images/demote.png + + + + 20 + 20 + + + + + + + + Move selected item down by one + + + ... + + + ../../../../lib/images/down.png + + + + 20 + 20 + + + + + + + + Move selected item up by one + + + ... + + + ../../../../lib/images/up.png + + + + 20 + 20 + + + + + - - + + + + 4 + 0 QLayout::SetMinimumSize - - 4 - @@ -131,128 +252,35 @@ - - - - 6 + + + + + 13 + 0 + 0 + 0 + - - 0 + + Adjust the depth of the navigation tree - - - - Update navigation tree - - - ... - - - - ../../../../lib/images/reload.png../../../../lib/images/reload.png - - - - 20 - 20 - - - - - - - - Qt::Horizontal - - - - 16 - 20 - - - - - - - - Decrease nesting depth of selected item - - - ... - - - - ../../../../lib/images/promote.png../../../../lib/images/promote.png - - - - 20 - 20 - - - - - - - - Increase nesting depth of selected item - - - ... - - - - ../../../../lib/images/demote.png../../../../lib/images/demote.png - - - - 20 - 20 - - - - - - - - Move selected item down by one - - - ... - - - - ../../../../lib/images/down.png../../../../lib/images/down.png - - - - 20 - 20 - - - - - - - - Move selected item up by one - - - ... - - - - ../../../../lib/images/up.png../../../../lib/images/up.png - - - - 20 - 20 - - - - - + + 5 + + + 1 + + + 2 + + + Qt::Horizontal + + + QSlider::TicksBothSides + +