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