]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiSearch.h
Transform simple search dialog to dock widget (#2625)
[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 isMinimized() { return minimized_; }
42
43 private Q_SLOTS:
44         void findChanged();
45         void findClicked(bool const backwards = false);
46         void findPrevClicked();
47         void replaceClicked(bool const backwards = false);
48         void replacePrevClicked();
49         void replaceallClicked();
50         void minimizeClicked(bool const toggle = true);
51 Q_SIGNALS:
52         void needTitleBarUpdate() const;
53         void needSizeUpdate() const;
54
55 private:
56         ///
57         void keyPressEvent(QKeyEvent * e) override;
58         ///
59         void showEvent(QShowEvent * e) override;
60         /// Searches occurrence of string
61         void find(docstring const & search,
62                   bool casesensitive, bool matchword, bool forward);
63         /// Replaces occurrence of string
64         void replace(docstring const & search, docstring const & replace,
65                      bool casesensitive, bool matchword,
66                      bool forward, bool all);
67         ///
68         BufferView const * bv_;
69         ///
70         bool minimized_ = false;
71 };
72
73
74 class GuiSearch : public DockView
75 {
76         Q_OBJECT
77
78 public:
79         GuiSearch(
80                 GuiView & parent, ///< the main window where to dock.
81                 Qt::DockWidgetArea area = Qt::BottomDockWidgetArea, ///< Position of the dock (and also drawer)
82                 Qt::WindowFlags flags = {});
83
84         /// Controller inherited method.
85         ///@{
86         bool initialiseParams(std::string const &) override { return true; }
87         void clearParams() override {}
88         void dispatchParams() override {}
89         bool isBufferDependent() const override { return true; }
90         void updateView() override;
91         void saveSession(QSettings & settings) const override;
92         void restoreSession() override;
93         bool wantInitialFocus() const override { return true; }
94         ///@}
95
96 public Q_SLOTS:
97         ///
98         void onBufferViewChanged() override;
99
100 private Q_SLOTS:
101         /// update title display
102         void updateTitle();
103         /// update dock size
104         void updateSize();
105
106 private:
107         /// The encapsulated widget.
108         GuiSearchWidget * widget_;
109 };
110
111 } // namespace frontend
112 } // namespace lyx
113
114 #endif // GUISEARCH_H