Warning, file /office/calligra/libs/main/KoFindText.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 0022 0023 #ifndef KOFINDTEXT_H 0024 #define KOFINDTEXT_H 0025 0026 #include "KoFindBase.h" 0027 #include "komain_export.h" 0028 0029 #include <QMetaType> 0030 #include <QTextCursor> 0031 0032 class QTextDocument; 0033 class QTextCharFormat; 0034 class KoShape; 0035 /** 0036 * \brief KoFindBase implementation for searching within text shapes. 0037 * 0038 * This class provides a link between KoFindBase and QTextDocument for searching. 0039 * It uses a list of QTextDocument instances and searches through them using 0040 * QTextDocument::find(). 0041 * 0042 * The following options are defined: 0043 * <ul> 0044 * <li><strong>caseSensitive</strong>: Boolean. Default false. Use case-sensitive searching.</li> 0045 * <li><strong>wholeWords</strong>: Boolean. Default false. Only match whole words, not parts.</li> 0046 * <li><strong>fromCursor</strong>: Boolean. Default true. Start searching from the current cursor 0047 * set through setCurrentCursor().</li> 0048 * </ul> 0049 * 0050 * \note Before you can use this class, be sure to set a list of QTextDocuments 0051 * using setDocuments(). 0052 * 0053 * Matches created by this implementation use QTextDocument for the container and 0054 * QTextCursor for the location. 0055 */ 0056 class KOMAIN_EXPORT KoFindText : public KoFindBase 0057 { 0058 Q_OBJECT 0059 public: 0060 enum FormatType { 0061 HighlightFormat, 0062 CurrentMatchFormat, 0063 SelectionFormat, 0064 ReplacedFormat 0065 }; 0066 0067 /** 0068 * Constructor. 0069 */ 0070 explicit KoFindText(QObject *parent = 0); 0071 ~KoFindText() override; 0072 0073 /** 0074 * Overridden from KoFindBase 0075 */ 0076 void findNext() override; 0077 /** 0078 * Overridden from KoFindBase 0079 */ 0080 void findPrevious() override; 0081 0082 /** 0083 * Retrieve the list of documents currently in use. 0084 */ 0085 QList<QTextDocument*> documents() const; 0086 0087 /** 0088 * Set the current cursor. 0089 * Used for the "Start from cursor" find option. 0090 * 0091 * \param cursor The current cursor. 0092 */ 0093 virtual void setCurrentCursor(const QTextCursor &cursor); 0094 0095 /** 0096 * Set the format to use. 0097 * 0098 * Use this function if you want to overwrite the default formatting options. 0099 */ 0100 static void setFormat(FormatType formatType, const QTextCharFormat &format); 0101 0102 /** 0103 * Helper function to retrieve all QTextDocument objects from a list of shapes. 0104 * 0105 * This method will search the list of shapes passed to it recursively for any 0106 * text shapes. If it encounters any text shapes it will add the QTextDocument 0107 * object used by that shape to the list passed. 0108 * 0109 * \param shapes The shapes to search for text. 0110 * \param append A list to append the found QTextDocument objects to. 0111 */ 0112 static void findTextInShapes(const QList<KoShape*> &shapes, QList<QTextDocument*> &append); 0113 0114 public Q_SLOTS: 0115 /** 0116 * Set the list of documents that can be searched. 0117 * 0118 * Since there is no way of knowing how an application deals with text shapes 0119 * and the QTextDocument instances inside those shapes, it is important to 0120 * update the list of documents whenever something changes. 0121 * 0122 * \param documents The list of documents to search through. 0123 */ 0124 void setDocuments(const QList<QTextDocument*> &documents); 0125 0126 protected: 0127 /** 0128 * The actual implementation of the searching, overridden from KoFindBase. 0129 */ 0130 void findImplementation(const QString &pattern, KoFindMatchList &matchList) override; 0131 /** 0132 * The actual implementation of replacing, overridden from KoFindBase. 0133 */ 0134 void replaceImplementation(const KoFindMatch &match, const QVariant &value) override; 0135 /** 0136 * Clear the list of matches properly. Overridden from KoFindBase. 0137 */ 0138 void clearMatches() override; 0139 0140 private: 0141 class Private; 0142 Private * const d; 0143 0144 Q_PRIVATE_SLOT(d, void documentDestroyed(QObject* object)) 0145 }; 0146 0147 Q_DECLARE_METATYPE(QTextDocument *) 0148 Q_DECLARE_METATYPE(QTextCursor) 0149 0150 #endif // KOFINDTEXT_H