1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
4 **
5 ** This file is part of the Edyuk project <http://edyuk.org>
6 **
7 ** This file may be used under the terms of the GNU General Public License
8 ** version 3 as published by the Free Software Foundation and appearing in the
9 ** file GPL.txt included in the packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ****************************************************************************/
15 
16 #ifndef Header_QSearch_Replace_Panel
17 #define Header_QSearch_Replace_Panel
18 
19 #include "mostQtHeaders.h"
20 #include "qdocumentcursor.h"
21 
22 #include "qpanel.h"
23 
24 /*!
25 	\file qsearchreplacepanel.h
26 	\brief Definition of the QSearchReplacePanel class.
27 
28 	\see QSearchReplacePanel
29 */
30 
31 
32 //class QDocumentCursor;
33 class QDocumentLine;
34 class QDocumentSearch;
35 
36 class QCE_EXPORT QSearchReplacePanel : public QPanel //, private Ui::SearchReplace
37 {
38 	Q_OBJECT
39 
40 	public:
41 		Q_PANEL(QSearchReplacePanel, "Search Replace Panel")
42 
43         QSearchReplacePanel(QWidget *p = nullptr);
44 		virtual ~QSearchReplacePanel();
45 
46 		virtual QString type() const;
47 		bool isReplaceModeActive() const;
48 		QDocumentCursor getSearchScope() const;
search()49 		QDocumentSearch * search(){
50 			return m_search;
51 		}
52 
53 		void setUseLineForSearch(bool b);
54 		bool getUseLineForSearch() const;
55 		void setSearchOnlyInSelection(bool b);
56 		bool getSearchOnlyInSelection() const;
57         QString getSearchText() const;
58         QString getReplaceText() const;
59         bool getSearchIsCase() const;
60         bool getSearchIsRegExp() const;
61         bool getSearchIsWords() const;
62 
63         void updateIcon();
64 
65 
66 	public slots:
67 		void display(int mode, bool replace);
68 		void closeElement(bool closeTogether);
69 
70 		void findNext();
71 		void findReplace(bool backward, bool replace=false, bool replaceAll=false, bool countOnly = false);
72 		void find(QString text, bool backward, bool highlight, bool regex, bool word, bool caseSensitive);
73 		void find(QString text, bool backward, bool highlight, bool regex, bool word, bool caseSensitive, bool fromCursor, bool selection);
74 		void selectAllMatches();
75 		void setOptions(int searchOptions, bool cursor, bool selection);
76 	signals:
77 		void onClose();
78         void showExtendedSearch();
79 	protected:
80 		virtual bool forward(QMouseEvent *e);
81 		virtual void editorChange(QEditor *e);
82 
83 		virtual bool eventFilter(QObject *o, QEvent *e);
84 
85         virtual void hideEvent(QHideEvent *e);
86         virtual void showEvent(QShowEvent *e);
87 		virtual void closeEvent(QCloseEvent *e);
88 
89 
90 	private slots:
91 		void cFind_textEdited(const QString& text);
92 		void cReplace_textEdited(const QString& text);
93 
94 		void on_cbCase_toggled(bool on);
95 		void on_cbWords_toggled(bool on);
96 		void on_cbRegExp_toggled(bool on);
97 		void on_cbCursor_toggled(bool on);
98 		void on_cbHighlight_toggled(bool on);
99 		void on_cbSelection_toggled(bool on);
100 		void on_cbEscapeSeq_toggled(bool on);
101 		void on_cbPrompt_toggled(bool on);
102 
103 		void filterChanged();
104 
105 		void on_bNext_clicked();
106 		void on_bPrevious_clicked();
107 		void on_bCount_clicked();
108 
109 		void on_bReplaceNext_clicked();
110 		void on_bReplacePrevious_clicked();
111 		void on_bReplaceAll_clicked();
112 
113 		void cursorPositionChanged();
114 		void updateReplacementHint();
115 
116 	private:
117 		void init();
118 		void updateSearchOptions(bool replace, bool replaceAll);
119 		void on_cFind_returnPressed(bool backward);
120 		void on_cReplace_returnPressed(bool backward);
121 		void updateButtonSizes();
122 		void setFilteredIconAndFormats(const char* icon, const std::initializer_list<const char*>& formats, bool inverted = false);
123 		QDocumentSearch *m_search;
124 		bool m_lastDirection;
125 		int minimum_width;
126         QStack<QDocumentCursor> m_initialCursorPos;
127 
128 	protected:
129 		QStringList getHistory(bool findHistory = true);
130 		void setHistory(const QStringList& newHistory, bool findHistory = true);
131 		void rememberLastSearch(QStringList& history, const QString& str, bool incremental);
132 		//protected to give unit tests access
133 		//find
134 		QToolButton *bClose;
135 		QComboBox *cFind;
136 		QToolButton *bNext, *bPrevious, *bCount;
137 		QGridLayout *layoutFindOptions;
138         QToolButton *cbCase;
139         QToolButton *cbWords;
140         QToolButton *cbRegExp;
141         QToolButton *cbHighlight;
142         QToolButton *cbCursor;
143         QToolButton *cbSelection;
144         QToolButton *cbFilter;
145         QToolButton *bExtend;
146 		// replace
147 		QWidget *replaceWidget;
148 		QCheckBox *cbReplace;
149 		QComboBox *cReplace;
150 		QToolButton *bReplaceNext;
151 		QToolButton *bReplacePrevious;
152 		QToolButton *bReplaceAll;
153 		QGridLayout *layoutReplaceOptions;
154         QToolButton *cbPrompt;
155         QToolButton *cbEscapeSeq;
156         QLabel *lReplacementText;
157 
158 		bool useLineForSearch, searchOnlyInSelection;
159 
160         QString currentFilter;
161 };
162 
163 #endif // _QSEARCH_REPLACE_PANEL_H_
164