2 * Copyright (C) 2009 Lorenzo Bettini <http://www.lorenzobettini.it>
3 * See COPYING file that comes with this distribution
6 #ifndef FINDREPLACEFORM_H
7 #define FINDREPLACEFORM_H
10 #include <QTextCursor>
12 #include "findreplace_global.h"
15 class FindReplaceForm
;
24 * The form for the find/replace dialog. The form presents the typical
25 * widgets you find in standard find/replace dialogs, and it acts on a QTextEdit.
27 * \image html Screenshot-FindReplace.png
29 * You need to set the QTextEdit explicitly, using the method setTextEdit(QTextEdit *textEdit).
33 * m_findReplaceDialog = new FindReplaceDialog(this);
34 * m_findReplaceDialog->setModal(false);
35 * m_findReplaceDialog->setTextEdit(ui->textEdit);
38 * The find functionalities is available even if the find dialog is not shown: if something
39 * to search for was already specified, the application can call the methods findNext() and
40 * findPrev() (e.g., by connecting them to menu items).
42 * In case a regular expression is used as the search term, the form also checks whether the
43 * expression is a valid regular expression (You may want to take a look at the syntax of regular expressions:
44 * http://doc.trolltech.com/qregexp.html).
46 * The form provides also functionalities to save and restore its state using a QSettings object (i.e.,
47 * the last word searched for, the options of the form, etc.) via the methods writeSettings()
50 * You can take a look at the \ref examples page.
52 class FINDREPLACESHARED_EXPORT FindReplaceForm
: public QWidget
{
55 FindReplaceForm(QWidget
*parent
= 0);
56 virtual ~FindReplaceForm();
59 * Associates the text editor where to perform the search
62 void setTextEdit(QTextEdit
*textEdit_
);
65 * Associates the text editor where to perform the search
68 void setTextEdit(QPlainTextEdit
*textEdit_
);
70 /// hides replace widgets from the form
71 void hideReplaceWidgets();
74 * Writes the state of the form to the passed settings.
76 * @param prefix the prefix to insert in the settings
78 virtual void writeSettings(QSettings
&settings
, const QString
&prefix
= "FindReplaceDialog");
81 * Reads the state of the form from the passed settings.
83 * @param prefix the prefix to look for in the settings
85 virtual void readSettings(QSettings
&settings
, const QString
&prefix
= "FindReplaceDialog");
89 * performs the find task
90 * @param down whether to find the next or the previous
96 * Finds the next occurrence
101 * Finds the next occurrence
103 void findNext() { find(true); }
106 * Finds the previous occurrence
108 void findPrev() { find(false); }
111 * Replaces the found occurrences and goes to the next occurrence
116 * Replaces all the found occurrences
121 void changeEvent(QEvent
*e
);
123 /// shows an error in the dialog
124 void showError(const QString
&error
);
126 /// shows a message in the dialog
127 void showMessage(const QString
&message
);
130 /// when the text edit contents changed
131 void textToFindChanged();
133 /// checks whether the passed text is a valid regexp
134 void validateRegExp(const QString
&text
);
136 /// the regexp checkbox was selected
137 void regexpSelected(bool sel
);
140 Ui::FindReplaceForm
*ui
;
142 /// for searching into the text
143 QTextCursor textCursor
;
145 /// the text editor (possibly) associated with this form
146 VariantEditor
*textEdit
;
149 #endif // FINDREPLACEFORM_H