skin_engine: ease the restrictions on %x/%xl
[maemo-rb.git] / utils / themeeditor / qtfindreplacedialog / findreplaceform.h
blob5ed85a7d60b787fb3a9eb8b3ad52abe12af569c0
1 /*
2 * Copyright (C) 2009 Lorenzo Bettini <http://www.lorenzobettini.it>
3 * See COPYING file that comes with this distribution
4 */
6 #ifndef FINDREPLACEFORM_H
7 #define FINDREPLACEFORM_H
9 #include <QWidget>
10 #include <QTextCursor>
12 #include "findreplace_global.h"
14 namespace Ui {
15 class FindReplaceForm;
18 class QTextEdit;
19 class QPlainTextEdit;
20 class QSettings;
21 class VariantEditor;
23 /**
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).
31 * For instance
32 * \code
33 * m_findReplaceDialog = new FindReplaceDialog(this);
34 * m_findReplaceDialog->setModal(false);
35 * m_findReplaceDialog->setTextEdit(ui->textEdit);
36 * \endcode
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()
48 * and readSettings().
50 * You can take a look at the \ref examples page.
52 class FINDREPLACESHARED_EXPORT FindReplaceForm : public QWidget {
53 Q_OBJECT
54 public:
55 FindReplaceForm(QWidget *parent = 0);
56 virtual ~FindReplaceForm();
58 /**
59 * Associates the text editor where to perform the search
60 * @param textEdit_
62 void setTextEdit(QTextEdit *textEdit_);
64 /**
65 * Associates the text editor where to perform the search
66 * @param textEdit_
68 void setTextEdit(QPlainTextEdit *textEdit_);
70 /// hides replace widgets from the form
71 void hideReplaceWidgets();
73 /**
74 * Writes the state of the form to the passed settings.
75 * @param settings
76 * @param prefix the prefix to insert in the settings
78 virtual void writeSettings(QSettings &settings, const QString &prefix = "FindReplaceDialog");
80 /**
81 * Reads the state of the form from the passed settings.
82 * @param settings
83 * @param prefix the prefix to look for in the settings
85 virtual void readSettings(QSettings &settings, const QString &prefix = "FindReplaceDialog");
87 public slots:
88 /**
89 * performs the find task
90 * @param down whether to find the next or the previous
91 * occurrence
93 void find(bool down);
95 /**
96 * Finds the next occurrence
98 void find();
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
113 void replace();
116 * Replaces all the found occurrences
118 void replaceAll();
120 protected:
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);
129 protected slots:
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);
139 protected:
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