]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiSearch.h
Update toolbar and properly reset focus when find widget is closed (#12396)
[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 #include "FancyLineEdit.h"
19
20 #include <QMenu>
21 #include <QDockWidget>
22
23 #include "ui_SearchUi.h"
24
25 namespace lyx {
26 namespace frontend {
27
28 class GuiSearch;
29
30 class GuiSearchWidget : public QWidget, public Ui::SearchUi
31 {
32         Q_OBJECT
33
34 public:
35         GuiSearchWidget(QWidget * parent, GuiView & view);
36         ///
37         void saveSession(QSettings & settings, QString const & session_key) const;
38         ///
39         void restoreSession(QString const & session_key);
40         ///
41         void setBufferView(BufferView const * bv) { bv_ = bv; }
42         ///
43         bool initialiseParams(std::string const &);
44         ///
45         bool isMinimized() { return minimized_; }
46
47 private Q_SLOTS:
48         void findChanged();
49         void findBufferChanged();
50         void findClicked();
51         void findPrevClicked();
52         void replaceClicked();
53         void replacePrevClicked();
54         void replaceallClicked();
55         void minimizeClicked(bool const toggle = true);
56         void caseSenseActTriggered();
57         void wholeWordsActTriggered();
58         void searchSelActTriggered();
59         void immediateActTriggered();
60         void wrapActTriggered();
61 Q_SIGNALS:
62         void needTitleBarUpdate() const;
63         void needSizeUpdate() const;
64
65 private:
66         ///
67         void keyPressEvent(QKeyEvent * e) override;
68         ///
69         void showEvent(QShowEvent * e) override;
70         ///
71         void hideEvent(QHideEvent * e) override;
72         ///
73         void doFind(bool const backwards = false,
74                     bool const instant = false);
75         ///
76         void doReplace(bool const backwards = false);
77         /// Searches occurrence of string
78         void find(docstring const & search,
79                   bool casesensitive, bool matchword,
80                   bool forward, bool instant, bool wrap, bool onlysel);
81         /// Replaces occurrence of string
82         void replace(docstring const & search, docstring const & replace,
83                      bool casesensitive, bool matchword,
84                      bool forward, bool all, bool wrap, bool onlysel);
85         ///
86         void handleIndicators();
87         ///
88         BufferView const * bv_ = nullptr;
89         ///
90         GuiView & view_;
91         ///
92         bool minimized_ = false;
93         /// contains the search box
94         FancyLineEdit * findLE_;
95         /// The options menu
96         QMenu * menu_;
97         /// And its actions
98         QAction * act_casesense_ = new QAction(this);
99         ///
100         QAction * act_wholewords_ = new QAction(this);
101         ///
102         QAction * act_selection_ = new QAction(this);
103         ///
104         QAction * act_immediate_ = new QAction(this);
105         ///
106         QAction * act_wrap_ = new QAction(this);
107 };
108
109
110 class GuiSearch : public DockView
111 {
112         Q_OBJECT
113
114 public:
115         GuiSearch(
116                 GuiView & parent, ///< the main window where to dock.
117                 Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
118                 Qt::WindowFlags flags = {});
119
120         /// Controller inherited method.
121         ///@{
122         bool initialiseParams(std::string const & sdata) override
123                 { return widget_->initialiseParams(sdata); }
124         void clearParams() override {}
125         void dispatchParams() override {}
126         bool isBufferDependent() const override { return true; }
127         void updateView() override;
128         void saveSession(QSettings & settings) const override;
129         void restoreSession() override;
130         ///@}
131
132 protected:
133         bool wantInitialFocus() const override { return true; }
134         void mouseMoveEvent(QMouseEvent * event) override;
135         void mousePressEvent(QMouseEvent * event) override;
136         void mouseDoubleClickEvent(QMouseEvent *event) override;
137
138 public Q_SLOTS:
139         ///
140         void onBufferViewChanged() override;
141
142 private Q_SLOTS:
143         /// update title display
144         void updateTitle();
145         /// update dock size
146         void updateSize();
147
148 private:
149         /// The encapsulated widget.
150         GuiSearchWidget * widget_;
151         ///
152         QPoint dragPosition;
153 };
154
155 } // namespace frontend
156 } // namespace lyx
157
158 #endif // GUISEARCH_H