1 #ifndef SEARCH_H 2 #define SEARCH_H 3 4 #include <QString> 5 #include <QThread> 6 #include <QMutex> 7 #include <QWidget> 8 #include <QLineEdit> 9 #include <QLabel> 10 #include <QHBoxLayout> 11 #include <QRect> 12 #include <QEvent> 13 #include <QList> 14 #if QT_VERSION >= 0x050000 15 # include <poppler-qt5.h> 16 #else 17 # include <poppler-qt4.h> 18 #endif 19 20 21 class SearchBar; 22 class Canvas; 23 class Viewer; 24 25 26 class SearchWorker : public QThread { 27 Q_OBJECT 28 29 public: 30 SearchWorker(SearchBar *_bar); 31 void run(); 32 33 volatile bool stop; 34 volatile bool die; 35 36 signals: 37 void update_label_text(const QString &text); 38 void search_done(int page, QList<QRectF> *hits); 39 void clear_hits(); 40 41 private: 42 SearchBar *bar; 43 bool forward; 44 }; 45 46 47 class SearchBar : public QWidget { 48 Q_OBJECT 49 50 public: 51 SearchBar(const QString &file, Viewer *v, QWidget *parent = 0); 52 ~SearchBar(); 53 54 void load(const QString &file, const QByteArray &password); 55 bool is_valid() const; 56 void focus(bool forward = true); 57 const std::map<int,QList<QRectF> *> *get_hits() const; 58 bool is_search_forward() const; 59 60 signals: 61 void search_updated(int page); 62 63 protected: 64 // QT event handling 65 bool event(QEvent *event); 66 67 public slots: 68 void reset_search(); 69 70 private slots: 71 void insert_hits(int page, QList<QRectF> *hits); 72 void clear_hits(); 73 void set_text(); 74 75 private: 76 void initialize(const QString &file, const QByteArray &password); 77 void join_threads(); 78 void shutdown(); 79 80 QLineEdit *line; 81 QLabel *progress; 82 QHBoxLayout *layout; 83 84 Poppler::Document *doc; 85 Viewer *viewer; 86 87 std::map<int,QList<QRectF> *> hits; 88 89 QMutex search_mutex; 90 QMutex term_mutex; 91 SearchWorker *worker; 92 QString term; 93 int start_page; 94 bool forward_tmp; 95 bool forward; 96 97 friend class SearchWorker; 98 }; 99 100 #endif 101 102