KUtils
kfind.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KFIND_H
00022 #define KFIND_H
00023
00024 #include <kdialogbase.h>
00025 #include <qrect.h>
00026
00103 class KUTILS_EXPORT KFind :
00104 public QObject
00105 {
00106 Q_OBJECT
00107
00108 public:
00109
00117 KFind(const QString &pattern, long options, QWidget *parent);
00118
00129 KFind(const QString &pattern, long options, QWidget *parent, QWidget* findDialog);
00130
00134 virtual ~KFind();
00135
00139 enum Result {
00140 NoMatch,
00141 Match
00142 };
00143
00150 bool needData() const;
00151
00161 void setData( const QString& data, int startPos = -1 );
00162
00176 void setData( int id, const QString& data, int startPos = -1 );
00177
00184 Result find();
00185
00195 long options() const { return m_options; }
00196
00203 virtual void setOptions( long options );
00204
00208 QString pattern() const { return m_pattern; }
00209
00214 void setPattern( const QString& pattern );
00215
00223 int numMatches() const { return m_matches; }
00224
00231 virtual void resetCounts() { m_matches = 0; }
00232
00243 virtual bool validateMatch( const QString & text, int index, int matchedlength ) {
00244 Q_UNUSED(text); Q_UNUSED(index); Q_UNUSED(matchedlength); return true; }
00245
00261 virtual bool shouldRestart( bool forceAsking = false, bool showNumMatches = true ) const;
00262
00277 static int find( const QString &text, const QString &pattern, int index, long options, int *matchedlength );
00278
00292 static int find( const QString &text, const QRegExp &pattern, int index, long options, int *matchedlength );
00293
00298 virtual void displayFinalDialog() const;
00299
00308 KDialogBase* findNextDialog( bool create = false );
00309
00318 void closeFindNextDialog();
00319
00327 int index() const;
00328
00329 signals:
00330
00347 void highlight(const QString &text, int matchingIndex, int matchedLength);
00348
00367 void highlight(int id, int matchingIndex, int matchedLength);
00368
00369
00370
00371
00372 void findNext();
00373
00379 void optionsChanged();
00380
00387 void dialogClosed();
00388
00389 protected:
00390
00391 QWidget* parentWidget() const { return (QWidget *)parent(); }
00392 QWidget* dialogsParent() const;
00393
00394 protected slots:
00395
00396 void slotFindNext();
00397 void slotDialogClosed();
00398
00399 private:
00400 void init( const QString& pattern );
00401 void startNewIncrementalSearch();
00402
00403 static bool isInWord( QChar ch );
00404 static bool isWholeWords( const QString &text, int starts, int matchedLength );
00405
00406 friend class KReplace;
00407
00408
00409 QString m_pattern;
00410 QRegExp *m_regExp;
00411 KDialogBase* m_dialog;
00412 long m_options;
00413 unsigned m_matches;
00414
00415 QString m_text;
00416 int m_index;
00417 int m_matchedLength;
00418 bool m_dialogClosed;
00419 bool m_lastResult;
00420
00421
00422 struct Private;
00423 Private *d;
00424 };
00425
00426 #endif