]> git.lyx.org Git - lyx.git/commitdiff
Use a proper filter bar in the outliner
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 28 Feb 2021 12:57:24 +0000 (13:57 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 28 Feb 2021 12:57:24 +0000 (13:57 +0100)
src/frontends/qt/GuiToc.h
src/frontends/qt/TocWidget.cpp
src/frontends/qt/TocWidget.h
src/frontends/qt/ui/TocUi.ui

index 92f64b5061ffaab6afdeede70606aadabb5833bc..9e46d6e3b2558c31d2b52cd59af2c3d9e3a9d4b9 100644 (file)
@@ -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_; }
 
index de2b07a1ee3ffa57cfd25fa113ad3d39fe8788d2..8e32774d017dc15fd7d2f6c4b2d94a8e2570ebc2 100644 (file)
@@ -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());
index 3545a44e1c9f93713dac09a5c5f330ff8a2d476d..4f8c617c3e294b2fcca35998b763827866de68e9 100644 (file)
@@ -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
index bc634eb4fa384af50bdfdd07994ddaaa884e88d3..3fa219dc7f881a9d0890c3dd276ec31887843018 100644 (file)
      <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>&amp;Filter:</string>
        </property>
       </widget>
      </item>
        </property>
       </widget>
      </item>
+     <item row="2" column="1">
+      <layout class="QHBoxLayout" name="filterBarL"/>
+     </item>
     </layout>
    </item>
   </layout>