QCodeEdit 2.2
lib/document/qdocumentsearch.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
00004 **
00005 ** This file is part of the Edyuk project <http://edyuk.org>
00006 ** 
00007 ** This file may be used under the terms of the GNU General Public License
00008 ** version 3 as published by the Free Software Foundation and appearing in the
00009 ** file GPL.txt included in the packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ****************************************************************************/
00015 
00016 #ifndef _QDOCUMENT_SEARCH_H_
00017 #define _QDOCUMENT_SEARCH_H_
00018 
00019 #include "qce-config.h"
00020 
00026 #include <QString>
00027 #include <QRegExp>
00028 #include <QPointer>
00029 #include <QCoreApplication>
00030 
00031 #include "qdocumentcursor.h"
00032 
00033 class QEditor;
00034 
00035 class QCE_EXPORT QDocumentSearch
00036 {
00037     Q_DECLARE_TR_FUNCTIONS(QDocumentSearch)
00038     
00039     public:
00040         enum Option
00041         {
00042             WholeWords      = 1,
00043             CaseSensitive   = 2,
00044             RegExp          = 4,
00045             Replace         = 8,
00046             Prompt          = 16,
00047             Silent          = 32,
00048             HighlightAll    = 64
00049         };
00050         
00051         Q_DECLARE_FLAGS(Options, Option);
00052         
00053         QDocumentSearch(QEditor *e, const QString& f, Options opt, const QString& r = QString());
00054         ~QDocumentSearch();
00055         
00056         int currentMatchIndex() const;
00057         int indexedMatchCount() const;
00058         QDocumentCursor match(int idx) const;
00059         
00060         QString searchText() const;
00061         void setSearchText(const QString& f);
00062         
00063         Options options() const;
00064         bool hasOption(Option opt) const;
00065         void setOption(Option opt, bool on);
00066         
00067         QString replaceText() const;
00068         void setReplaceText(const QString& r);
00069         
00070         QDocumentCursor origin() const;
00071         void setOrigin(const QDocumentCursor& c);
00072         
00073         QDocumentCursor cursor() const;
00074         void setCursor(const QDocumentCursor& c);
00075         
00076         QDocumentCursor scope() const;
00077         void setScope(const QDocumentCursor& c);
00078         
00079         void next(bool backward, bool all = false);
00080         
00081     private:
00082         bool end(bool backward) const;
00083         
00084         void clearMatches();
00085         
00086         int m_group;
00087         int m_index;
00088         Options m_option;
00089         QString m_string;
00090         QString m_replace;
00091         QPointer<QEditor> m_editor;
00092         QDocumentCursor m_cursor, m_scope, m_origin;
00093         QList<QDocumentCursor> m_highlight;
00094 };
00095 
00096 Q_DECLARE_OPERATORS_FOR_FLAGS(QDocumentSearch::Options)
00097 
00098 #endif // !_QDOCUMENT_SEARCH_H_