[LyX/master] Use a proper filter bar in the outliner
Juergen Spitzmueller
spitz at lyx.org
Sun Feb 28 12:53:15 UTC 2021
commit 1205018286f1e10e271e42dac0f6e88967f9cb59
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Sun Feb 28 13:57:24 2021 +0100
Use a proper filter bar in the outliner
---
src/frontends/qt/GuiToc.h | 2 +-
src/frontends/qt/TocWidget.cpp | 21 ++++++++++++++++++---
src/frontends/qt/TocWidget.h | 3 +++
src/frontends/qt/ui/TocUi.ui | 15 ++++-----------
4 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/src/frontends/qt/GuiToc.h b/src/frontends/qt/GuiToc.h
index 92f64b5..9e46d6e 100644
--- a/src/frontends/qt/GuiToc.h
+++ b/src/frontends/qt/GuiToc.h
@@ -42,7 +42,7 @@ public:
bool initialiseParams(std::string const & data) override;
void updateView() override;
void enableView(bool enable) override;
- bool wantInitialFocus() const override { return false; }
+ bool wantInitialFocus() const override { return true; }
void closeEvent(QCloseEvent * event) override;
bool isClosing() const override { return is_closing_; }
diff --git a/src/frontends/qt/TocWidget.cpp b/src/frontends/qt/TocWidget.cpp
index de2b07a..8e32774 100644
--- a/src/frontends/qt/TocWidget.cpp
+++ b/src/frontends/qt/TocWidget.cpp
@@ -17,6 +17,7 @@
#include "GuiView.h"
#include "qt_helpers.h"
#include "TocModel.h"
+#include "FancyLineEdit.h"
#include "Buffer.h"
#include "BufferView.h"
@@ -77,11 +78,18 @@ TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
// Only one item selected at a time.
tocTV->setSelectionMode(QAbstractItemView::SingleSelection);
- setFocusProxy(tocTV);
// The toc types combo won't change its model.
typeCO->setModel(gui_view_.tocModels().nameModel());
+ // The filter bar
+ filter_ = new FancyLineEdit(this);
+ filter_->setClearButton(true);
+ filter_->setPlaceholderText(qt_("All items"));
+ filterBarL->addWidget(filter_, 0);
+ filterLA->setBuddy(filter_);
+ setFocusProxy(filter_);
+
// Make sure the buttons are disabled when first shown without a loaded
// Buffer.
enableControls(false);
@@ -92,8 +100,15 @@ 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)),
+ connect(filter_, SIGNAL(textEdited(QString)),
this, SLOT(filterContents()));
+#if (QT_VERSION < 0x050000)
+ connect(filter_, SIGNAL(downPressed()),
+ tocTV, SLOT(setFocus()));
+#else
+ connect(filter_, &FancyLineEdit::downPressed,
+ tocTV, [this](){ focusAndHighlight(tocTV); });
+#endif
connect(activeFilterCO, SIGNAL(activated(int)),
this, SLOT(filterContents()));
@@ -521,7 +536,7 @@ void TocWidget::filterContents()
QModelIndex index = indices[i];
bool matches =
index.data().toString().contains(
- filterLE->text(), Qt::CaseInsensitive);
+ filter_->text(), Qt::CaseInsensitive);
TocItem const & item =
gui_view_.tocModels().currentItem(current_type_, index);
matches &= (show_active && item.isOutput()) || (show_inactive && !item.isOutput());
diff --git a/src/frontends/qt/TocWidget.h b/src/frontends/qt/TocWidget.h
index 3545a44..4f8c617 100644
--- a/src/frontends/qt/TocWidget.h
+++ b/src/frontends/qt/TocWidget.h
@@ -34,6 +34,7 @@ class Inset;
namespace frontend {
+class FancyLineEdit;
class GuiView;
class TocWidget : public QWidget, public Ui::TocUi
@@ -118,6 +119,8 @@ private:
GuiView & gui_view_;
// Timer for scheduling expensive update operations
QTimer * timer_;
+ /// Filter bar
+ FancyLineEdit * filter_;
};
} // namespace frontend
diff --git a/src/frontends/qt/ui/TocUi.ui b/src/frontends/qt/ui/TocUi.ui
index bc634eb..3fa219d 100644
--- a/src/frontends/qt/ui/TocUi.ui
+++ b/src/frontends/qt/ui/TocUi.ui
@@ -342,17 +342,7 @@
<item row="2" column="0">
<widget class="QLabel" name="filterLA">
<property name="text">
- <string>Filter:</string>
- </property>
- <property name="buddy">
- <cstring>filterLE</cstring>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QLineEdit" name="filterLE">
- <property name="toolTip">
- <string>Enter string to filter contents</string>
+ <string>&Filter:</string>
</property>
</widget>
</item>
@@ -369,6 +359,9 @@
</property>
</widget>
</item>
+ <item row="2" column="1">
+ <layout class="QHBoxLayout" name="filterBarL"/>
+ </item>
</layout>
</item>
</layout>
More information about the lyx-cvs
mailing list