Theme Editor: Added an edit menu with a find/replace function (copied from an LGPL...
[kugel-rb.git] / utils / themeeditor / findreplace / findreplaceform.h
blobf18052b7935fbb44078e0ed58f185e5d0de9da5a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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
22 #include <QWidget>
23 #include <QTextCursor>
24 #include <QPlainTextEdit>
26 namespace Ui {
27 class FindReplaceForm;
30 class QTextEdit;
31 class QSettings;
33 /**
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).
41 * For instance
42 * \code
43 * m_findReplaceDialog = new FindReplaceDialog(this);
44 * m_findReplaceDialog->setModal(false);
45 * m_findReplaceDialog->setTextEdit(ui->textEdit);
46 * \endcode
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()
58 * and readSettings().
60 * You can take a look at the \ref examples page.
62 class FindReplaceForm : public QWidget {
63 Q_OBJECT
64 public:
65 FindReplaceForm(QWidget *parent = 0);
66 virtual ~FindReplaceForm();
68 /**
69 * Associates the text editor where to perform the search
70 * @param textEdit_
72 void setTextEdit(QPlainTextEdit *textEdit_);
74 /// hides replace widgets from the form
75 void hideReplaceWidgets();
77 /**
78 * Writes the state of the form to the passed settings.
79 * @param settings
80 * @param prefix the prefix to insert in the settings
82 virtual void writeSettings(QSettings &settings, const QString &prefix = "FindReplaceDialog");
84 /**
85 * Reads the state of the form from the passed settings.
86 * @param settings
87 * @param prefix the prefix to look for in the settings
89 virtual void readSettings(QSettings &settings, const QString &prefix = "FindReplaceDialog");
91 public slots:
92 /**
93 * performs the find task
94 * @param down whether to find the next or the previous
95 * occurrence
97 void find(bool down);
99 /**
100 * Finds the next occurrence
102 void find();
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
117 void replace();
120 * Replaces all the found occurrences
122 void replaceAll();
124 protected:
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);
133 protected slots:
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);
143 protected:
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