]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiSearch.h
Fix Find button with search as you type
[lyx.git] / src / frontends / qt / GuiSearch.h
1 // -*- C++ -*-
2 /**
3  * \file GuiSearch.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef GUISEARCH_H
14 #define GUISEARCH_H
15
16 #include "GuiDialog.h"
17 #include "DockView.h"
18
19 #include <QDockWidget>
20
21 #include "ui_SearchUi.h"
22
23 namespace lyx {
24 namespace frontend {
25
26 class GuiSearch;
27
28 class GuiSearchWidget : public QWidget, public Ui::SearchUi
29 {
30         Q_OBJECT
31
32 public:
33         GuiSearchWidget(QWidget * parent);
34         ///
35         void saveSession(QSettings & settings, QString const & session_key) const;
36         ///
37         void restoreSession(QString const & session_key);
38         ///
39         void setBufferView(BufferView const * bv) { bv_ = bv; }
40         ///
41         bool initialiseParams(std::string const &);
42         ///
43         bool isMinimized() { return minimized_; }
44
45 private Q_SLOTS:
46         void findChanged();
47         void findBufferChanged();
48         void findClicked(bool const backwards = false,
49                          bool const instant = false);
50         void findPrevClicked();
51         void replaceClicked(bool const backwards = false);
52         void replacePrevClicked();
53         void replaceallClicked();
54         void minimizeClicked(bool const toggle = true);
55 Q_SIGNALS:
56         void needTitleBarUpdate() const;
57         void needSizeUpdate() const;
58
59 private:
60         ///
61         void keyPressEvent(QKeyEvent * e) override;
62         ///
63         void showEvent(QShowEvent * e) override;
64         /// Searches occurrence of string
65         void find(docstring const & search,
66                   bool casesensitive, bool matchword,
67                   bool forward, bool instant, bool wrap, bool onlysel);
68         /// Replaces occurrence of string
69         void replace(docstring const & search, docstring const & replace,
70                      bool casesensitive, bool matchword,
71                      bool forward, bool all, bool wrap, bool onlysel);
72         ///
73         BufferView const * bv_ = nullptr;
74         ///
75         bool minimized_ = false;
76 };
77
78
79 class GuiSearch : public DockView
80 {
81         Q_OBJECT
82
83 public:
84         GuiSearch(
85                 GuiView & parent, ///< the main window where to dock.
86                 Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
87                 Qt::WindowFlags flags = {});
88
89         /// Controller inherited method.
90         ///@{
91         bool initialiseParams(std::string const & sdata) override
92                 { return widget_->initialiseParams(sdata); }
93         void clearParams() override {}
94         void dispatchParams() override {}
95         bool isBufferDependent() const override { return true; }
96         void updateView() override;
97         void saveSession(QSettings & settings) const override;
98         void restoreSession() override;
99         ///@}
100
101 protected:
102         bool wantInitialFocus() const override { return true; }
103
104 public Q_SLOTS:
105         ///
106         void onBufferViewChanged() override;
107
108 private Q_SLOTS:
109         /// update title display
110         void updateTitle();
111         /// update dock size
112         void updateSize();
113
114 private:
115         /// The encapsulated widget.
116         GuiSearchWidget * widget_;
117 };
118
119 } // namespace frontend
120 } // namespace lyx
121
122 #endif // GUISEARCH_H