1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
/****************************************************************************
**
** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
**
** This file is part of the Edyuk project <http://edyuk.org>
**
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation and appearing in the
** file GPL.txt included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef _QDOCUMENT_SEARCH_H_
#define _QDOCUMENT_SEARCH_H_
#include "qce-config.h"
/*!
\file qdocumentsearch.h
\brief Definition of the QDocumentSearch class
*/
#include <QString>
#include <QRegExp>
#include <QPointer>
#include <QAbstractScrollArea>
#include <QWidget>
#include <QCoreApplication>
#include "qdocumentcursor.h"
#include "qdocumentline.h"
class QEditor;
class QCE_EXPORT QDocumentSearch: public QObject
{
Q_OBJECT
public:
enum Option
{
WholeWords = 1,
CaseSensitive = 2,
RegExp = 4,
Replace = 8,
Prompt = 16,
Silent = 32,
HighlightAll = 64,
EscapeSeq = 128,
HighlightReplacements = 64
};
Q_DECLARE_FLAGS(Options, Option);
QDocumentSearch(QEditor *e, const QString& f, Options opt, const QString& r = QString());
~QDocumentSearch();
QString searchText() const;
void setSearchText(const QString& f);
Options options() const;
bool hasOption(Option opt) const;
void setOption(Option opt, bool on);
void setOptions(Options options);
QString replaceText() const;
void setReplaceText(const QString& r);
QString replaceTextExpanded() const;
QDocumentCursor lastReplacedPosition() const;
QDocumentCursor cursor() const;
void setCursor(const QDocumentCursor& c);
QDocumentCursor scope() const;
void setScope(const QDocumentCursor& c);
int next(bool backward, bool all = false, bool again=false, bool allowWrapAround=true, const QDocumentCursor* overrideScope = 0);
void highlightSelection(const QDocumentCursor& subHighlightScope=QDocumentCursor());
QDocument* currentDocument();
private:
void connectToEditor();
void replaceCursorText(bool backward);
QList<QPair<QDocumentSelection, QDocumentSelection> > m_newReplacementOverlays;
void updateReplacementOverlays();
void searchMatches(const QDocumentCursor& subHighlightScope=QDocumentCursor(), bool clearAll=true, bool clearSubScope=true);
void clearMatches();
void clearReplacements();
void recreateRegExp();
// int m_index;
Options m_option;
QString m_string;
QRegExp m_regexp;
QString m_replace;
QPointer<QEditor> m_editor;
QDocumentCursor m_cursor, m_scope, m_highlightedScope, m_searchedScope, m_lastReplacedPosition;
QSet<QDocumentLineHandle*> m_highlights, m_highlightedReplacements;
int m_replaced,m_replaceDeltaLength,m_replaceDeltaLines;
private slots:
void documentContentChanged(int line, int n);
void visibleLinesChanged();
void lineDeleted(QDocumentLineHandle* line);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QDocumentSearch::Options)
#endif // !_QDOCUMENT_SEARCH_H_
|