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 <tqrect.h>
00026
00103 class TDEUTILS_EXPORT KFind :
00104 public TQObject
00105 {
00106 Q_OBJECT
00107
00108
00109 public:
00110
00118 KFind(const TQString &pattern, long options, TQWidget *parent);
00119
00130 KFind(const TQString &pattern, long options, TQWidget *parent, TQWidget* findDialog);
00131
00135 virtual ~KFind();
00136
00140 enum Result {
00141 NoMatch,
00142 Match
00143 };
00144
00151 bool needData() const;
00152
00162 void setData( const TQString& data, int startPos = -1 );
00163
00177 void setData( int id, const TQString& data, int startPos = -1 );
00178
00185 Result find();
00186
00196 long options() const { return m_options; }
00197
00204 virtual void setOptions( long options );
00205
00209 TQString pattern() const { return m_pattern; }
00210
00215 void setPattern( const TQString& pattern );
00216
00224 int numMatches() const { return m_matches; }
00225
00232 virtual void resetCounts() { m_matches = 0; }
00233
00244 virtual bool validateMatch( const TQString & text, int index, int matchedlength ) {
00245 Q_UNUSED(text); Q_UNUSED(index); Q_UNUSED(matchedlength); return true; }
00246
00262 virtual bool shouldRestart( bool forceAsking = false, bool showNumMatches = true ) const;
00263
00278 static int find( const TQString &text, const TQString &pattern, int index, long options, int *matchedlength );
00279
00293 static int find( const TQString &text, const TQRegExp &pattern, int index, long options, int *matchedlength );
00294
00299 virtual void displayFinalDialog() const;
00300
00309 KDialogBase* findNextDialog( bool create = false );
00310
00319 void closeFindNextDialog();
00320
00328 int index() const;
00329
00330 signals:
00331
00348 void highlight(const TQString &text, int matchingIndex, int matchedLength);
00349
00368 void highlight(int id, int matchingIndex, int matchedLength);
00369
00370
00371
00372
00373 void findNext();
00374
00380 void optionsChanged();
00381
00388 void dialogClosed();
00389
00390 protected:
00391
00392 TQWidget* parentWidget() const { return (TQWidget *)parent(); }
00393 TQWidget* dialogsParent() const;
00394
00395 protected slots:
00396
00397 void slotFindNext();
00398 void slotDialogClosed();
00399
00400 private:
00401 void init( const TQString& pattern );
00402 void startNewIncrementalSearch();
00403
00404 static bool isInWord( TQChar ch );
00405 static bool isWholeWords( const TQString &text, int starts, int matchedLength );
00406
00407 friend class KReplace;
00408
00409
00410 TQString m_pattern;
00411 TQRegExp *m_regExp;
00412 KDialogBase* m_dialog;
00413 long m_options;
00414 unsigned m_matches;
00415
00416 TQString m_text;
00417 int m_index;
00418 int m_matchedLength;
00419 bool m_dialogClosed;
00420 bool m_lastResult;
00421
00422
00423 struct Private;
00424 Private *d;
00425 };
00426
00427 #endif