diff --git a/Ladybird/Qt/FindInPageWidget.cpp b/Ladybird/Qt/FindInPageWidget.cpp index 1674cc79dc3..062e7f2e7c4 100644 --- a/Ladybird/Qt/FindInPageWidget.cpp +++ b/Ladybird/Qt/FindInPageWidget.cpp @@ -66,10 +66,15 @@ FindInPageWidget::FindInPageWidget(Tab* tab, WebContentView* content_view) 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_previous_button); layout->addWidget(m_next_button); layout->addWidget(m_match_case); + layout->addWidget(m_result_label); layout->addStretch(1); layout->addWidget(m_exit_button); } @@ -123,4 +128,18 @@ void FindInPageWidget::hideEvent(QHideEvent*) m_tab->update_hover_label(); } +void FindInPageWidget::update_result_label(size_t current_match_index, Optional 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); + } +} + } diff --git a/Ladybird/Qt/FindInPageWidget.h b/Ladybird/Qt/FindInPageWidget.h index 14e752c781e..6dab1bc9018 100644 --- a/Ladybird/Qt/FindInPageWidget.h +++ b/Ladybird/Qt/FindInPageWidget.h @@ -9,6 +9,7 @@ #include "WebContentView.h" #include #include +#include #include #include #include @@ -23,6 +24,8 @@ class FindInPageWidget final : public QWidget { public: FindInPageWidget(Tab* tab, WebContentView* content_view); + void update_result_label(size_t current_match_index, Optional const& total_match_count); + virtual ~FindInPageWidget() override; public slots: @@ -43,6 +46,7 @@ private: QPushButton* m_next_button { nullptr }; QPushButton* m_exit_button { nullptr }; QCheckBox* m_match_case { nullptr }; + QLabel* m_result_label { nullptr }; }; } diff --git a/Ladybird/Qt/Tab.cpp b/Ladybird/Qt/Tab.cpp index c88d409fae6..d00db16a710 100644 --- a/Ladybird/Qt/Tab.cpp +++ b/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().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); QObject::connect(m_select_dropdown, &QMenu::aboutToHide, this, [this]() { if (!m_select_dropdown->activeAction())