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.
This commit is contained in:
Tim Ledbetter 2024-06-09 19:25:17 +01:00 committed by Tim Flynn
parent 0a3203fa25
commit 2ea680b5b3
Notes: sideshowbarker 2024-07-17 02:14:39 +09:00
3 changed files with 27 additions and 0 deletions

View File

@ -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<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);
}
}
}

View File

@ -9,6 +9,7 @@
#include "WebContentView.h"
#include <LibWebView/Forward.h>
#include <QCheckBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QWidget>
@ -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<size_t> 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 };
};
}

View File

@ -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())