From 42434314d65cdc29402c7adcb08c2fa5113f7ca2 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Wed, 2 Aug 2023 01:56:58 +0200 Subject: Implement find dialog This dialog consolidates options for searching through textual elements in lists which simplifies the logic present in the MainWindow class. --- src/finddialog.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/finddialog.h (limited to 'src/finddialog.h') diff --git a/src/finddialog.h b/src/finddialog.h new file mode 100644 index 0000000..c6907f8 --- /dev/null +++ b/src/finddialog.h @@ -0,0 +1,49 @@ +#pragma once +#include +#include +#include "./ui_finddialog.h" + +QT_BEGIN_NAMESPACE +namespace Ui { class FindDialog; } +QT_END_NAMESPACE + +class FindDialog : public QDialog { + Q_OBJECT + +public: + FindDialog(QWidget *parent = nullptr); + ~FindDialog(); + +public slots: + void set_search_text(const QString &text); + void set_qlist_widget(QListWidget* widget); + inline void run_search(); + +signals: + void item_selected(QListWidgetItem* item); + void search_text_changed(const QString &text); + +private slots: + void on_textInputSearch_textEdited(const QString &text); + void on_buttonSearchPrev_clicked(); + void on_buttonSearchNext_clicked(); + void on_hSlider_valueChanged(int value); + void on_spinBox_valueChanged(int value); + +private: + Ui::FindDialog* ui; + + QListWidget* list_widget = nullptr; + QString* last_search = new QString; + QList matches; + int selected_match = 0; + int total_matches = 0; + + // This is used with the spin box to avoid having repeated value changes due to the on_spinBox_valueChanged slot + bool value_changed_processed = false; + + void init_search(); + void update_status(); + void select_match(); + bool has_search_changed(); +}; -- cgit v1.2.3-54-g00ecf