Browse Source

UI/Qt: Display query results on find in page panel

The number of matches and current match index are now displayed to the
user when a find in page query is performed.
Tim Ledbetter 1 year ago
parent
commit
2ea680b5b3
3 changed files with 27 additions and 0 deletions
  1. 19 0
      Ladybird/Qt/FindInPageWidget.cpp
  2. 4 0
      Ladybird/Qt/FindInPageWidget.h
  3. 4 0
      Ladybird/Qt/Tab.cpp

+ 19 - 0
Ladybird/Qt/FindInPageWidget.cpp

@@ -66,10 +66,15 @@ FindInPageWidget::FindInPageWidget(Tab* tab, WebContentView* content_view)
         find_text_changed();
         find_text_changed();
     });
     });
 
 
+    m_result_label = new QLabel(this);
+    m_result_label->setVisible(false);
+    m_result_label->setStyleSheet("font-weight: bold;");
+
     layout->addWidget(m_find_text, 1);
     layout->addWidget(m_find_text, 1);
     layout->addWidget(m_previous_button);
     layout->addWidget(m_previous_button);
     layout->addWidget(m_next_button);
     layout->addWidget(m_next_button);
     layout->addWidget(m_match_case);
     layout->addWidget(m_match_case);
+    layout->addWidget(m_result_label);
     layout->addStretch(1);
     layout->addStretch(1);
     layout->addWidget(m_exit_button);
     layout->addWidget(m_exit_button);
 }
 }
@@ -123,4 +128,18 @@ void FindInPageWidget::hideEvent(QHideEvent*)
         m_tab->update_hover_label();
         m_tab->update_hover_label();
 }
 }
 
 
+void FindInPageWidget::update_result_label(size_t current_match_index, Optional<size_t> const& total_match_count)
+{
+    if (total_match_count.has_value()) {
+        auto label_text = "Phrase not found"_string;
+        if (total_match_count.value() > 0)
+            label_text = MUST(String::formatted("{} of {} matches", current_match_index + 1, total_match_count.value()));
+
+        m_result_label->setText(qstring_from_ak_string(label_text));
+        m_result_label->setVisible(true);
+    } else {
+        m_result_label->setVisible(false);
+    }
+}
+
 }
 }

+ 4 - 0
Ladybird/Qt/FindInPageWidget.h

@@ -9,6 +9,7 @@
 #include "WebContentView.h"
 #include "WebContentView.h"
 #include <LibWebView/Forward.h>
 #include <LibWebView/Forward.h>
 #include <QCheckBox>
 #include <QCheckBox>
+#include <QLabel>
 #include <QLineEdit>
 #include <QLineEdit>
 #include <QPushButton>
 #include <QPushButton>
 #include <QWidget>
 #include <QWidget>
@@ -23,6 +24,8 @@ class FindInPageWidget final : public QWidget {
 public:
 public:
     FindInPageWidget(Tab* tab, WebContentView* content_view);
     FindInPageWidget(Tab* tab, WebContentView* content_view);
 
 
+    void update_result_label(size_t current_match_index, Optional<size_t> const& total_match_count);
+
     virtual ~FindInPageWidget() override;
     virtual ~FindInPageWidget() override;
 
 
 public slots:
 public slots:
@@ -43,6 +46,7 @@ private:
     QPushButton* m_next_button { nullptr };
     QPushButton* m_next_button { nullptr };
     QPushButton* m_exit_button { nullptr };
     QPushButton* m_exit_button { nullptr };
     QCheckBox* m_match_case { nullptr };
     QCheckBox* m_match_case { nullptr };
+    QLabel* m_result_label { nullptr };
 };
 };
 
 
 }
 }

+ 4 - 0
Ladybird/Qt/Tab.cpp

@@ -315,6 +315,10 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
         view().file_picker_closed(std::move(selected_files));
         view().file_picker_closed(std::move(selected_files));
     };
     };
 
 
+    view().on_find_in_page = [this](auto current_match_index, auto const& total_match_count) {
+        m_find_in_page->update_result_label(current_match_index, total_match_count);
+    };
+
     m_select_dropdown = new QMenu("Select Dropdown", this);
     m_select_dropdown = new QMenu("Select Dropdown", this);
     QObject::connect(m_select_dropdown, &QMenu::aboutToHide, this, [this]() {
     QObject::connect(m_select_dropdown, &QMenu::aboutToHide, this, [this]() {
         if (!m_select_dropdown->activeAction())
         if (!m_select_dropdown->activeAction())