]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiSearch.h
Movable minimised Quick Search Widget
[features.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);
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 doFind(bool const backwards = false,
72                     bool const instant = false);
73         ///
74         void doReplace(bool const backwards = false);
75         /// Searches occurrence of string
76         void find(docstring const & search,
77                   bool casesensitive, bool matchword,
78                   bool forward, bool instant, bool wrap, bool onlysel);
79         /// Replaces occurrence of string
80         void replace(docstring const & search, docstring const & replace,
81                      bool casesensitive, bool matchword,
82                      bool forward, bool all, bool wrap, bool onlysel);
83         ///
84         void handleIndicators();
85         ///
86         BufferView const * bv_ = nullptr;
87         ///
88         bool minimized_ = false;
89         /// contains the search box
90         FancyLineEdit * findLE_;
91         /// The options menu
92         QMenu * menu_;
93         /// And its actions
94         QAction * act_casesense_ = new QAction(this);
95         ///
96         QAction * act_wholewords_ = new QAction(this);
97         ///
98         QAction * act_selection_ = new QAction(this);
99         ///
100         QAction * act_immediate_ = new QAction(this);
101         ///
102         QAction * act_wrap_ = new QAction(this);
103 };
104
105
106 class GuiSearch : public DockView
107 {
108         Q_OBJECT
109
110 public:
111         GuiSearch(
112                 GuiView & parent, ///< the main window where to dock.
113                 Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
114                 Qt::WindowFlags flags = {});
115
116         /// Controller inherited method.
117         ///@{
118         bool initialiseParams(std::string const & sdata) override
119                 { return widget_->initialiseParams(sdata); }
120         void clearParams() override {}
121         void dispatchParams() override {}
122         bool isBufferDependent() const override { return true; }
123         void updateView() override;
124         void saveSession(QSettings & settings) const override;
125         void restoreSession() override;
126         ///@}
127
128 protected:
129         bool wantInitialFocus() const override { return true; }
130     void mouseMoveEvent(QMouseEvent * event) override;
131     void mousePressEvent(QMouseEvent * event) override;
132         void mouseDoubleClickEvent(QMouseEvent *event) override;
133
134 public Q_SLOTS:
135         ///
136         void onBufferViewChanged() override;
137
138 private Q_SLOTS:
139         /// update title display
140         void updateTitle();
141         /// update dock size
142         void updateSize();
143
144 private:
145         /// The encapsulated widget.
146         GuiSearchWidget * widget_;
147         ///
148     QPoint dragPosition;
149 };
150
151 } // namespace frontend
152 } // namespace lyx
153
154 #endif // GUISEARCH_H