1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * This file has been copied from Lorenzo Bettini, with minor modifications
11 * made available under the LGPL version 3, as the original file was licensed
13 ****************************************************************************
15 * Copyright (C) 2009 Lorenzo Bettini <http://www.lorenzobettini.it>
16 * See COPYING file that comes with this distribution
19 #ifndef FINDREPLACEFORM_H
20 #define FINDREPLACEFORM_H
23 #include <QTextCursor>
24 #include <QPlainTextEdit>
27 class FindReplaceForm
;
34 * The form for the find/replace dialog. The form presents the typical
35 * widgets you find in standard find/replace dialogs, and it acts on a QTextEdit.
37 * \image html Screenshot-FindReplace.png
39 * You need to set the QTextEdit explicitly, using the method setTextEdit(QTextEdit *textEdit).
43 * m_findReplaceDialog = new FindReplaceDialog(this);
44 * m_findReplaceDialog->setModal(false);
45 * m_findReplaceDialog->setTextEdit(ui->textEdit);
48 * The find functionalities is available even if the find dialog is not shown: if something
49 * to search for was already specified, the application can call the methods findNext() and
50 * findPrev() (e.g., by connecting them to menu items).
52 * In case a regular expression is used as the search term, the form also checks whether the
53 * expression is a valid regular expression (You may want to take a look at the syntax of regular expressions:
54 * http://doc.trolltech.com/qregexp.html).
56 * The form provides also functionalities to save and restore its state using a QSettings object (i.e.,
57 * the last word searched for, the options of the form, etc.) via the methods writeSettings()
60 * You can take a look at the \ref examples page.
62 class FindReplaceForm
: public QWidget
{
65 FindReplaceForm(QWidget
*parent
= 0);
66 virtual ~FindReplaceForm();
69 * Associates the text editor where to perform the search
72 void setTextEdit(QPlainTextEdit
*textEdit_
);
74 /// hides replace widgets from the form
75 void hideReplaceWidgets();
78 * Writes the state of the form to the passed settings.
80 * @param prefix the prefix to insert in the settings
82 virtual void writeSettings(QSettings
&settings
, const QString
&prefix
= "FindReplaceDialog");
85 * Reads the state of the form from the passed settings.
87 * @param prefix the prefix to look for in the settings
89 virtual void readSettings(QSettings
&settings
, const QString
&prefix
= "FindReplaceDialog");
93 * performs the find task
94 * @param down whether to find the next or the previous
100 * Finds the next occurrence
105 * Finds the next occurrence
107 void findNext() { find(true); }
110 * Finds the previous occurrence
112 void findPrev() { find(false); }
115 * Replaces the found occurrences and goes to the next occurrence
120 * Replaces all the found occurrences
125 void changeEvent(QEvent
*e
);
127 /// shows an error in the dialog
128 void showError(const QString
&error
);
130 /// shows a message in the dialog
131 void showMessage(const QString
&message
);
134 /// when the text edit contents changed
135 void textToFindChanged();
137 /// checks whether the passed text is a valid regexp
138 void validateRegExp(const QString
&text
);
140 /// the regexp checkbox was selected
141 void regexpSelected(bool sel
);
144 Ui::FindReplaceForm
*ui
;
146 /// for searching into the text
147 QTextCursor textCursor
;
149 /// the text editor (possibly) associated with this form
150 QPlainTextEdit
*textEdit
;
153 #endif // FINDREPLACEFORM_H