kfind.h
00001 /* 00002 Copyright (C) 2001, S.R.Haque <srhaque@iee.org>. 00003 Copyright (C) 2002, David Faure <david@mandrakesoft.com> 00004 This file is part of the KDE project 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2, as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 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 // ## TODO docu 00370 // findprevious will also emit findNext, after temporarily switching the value 00371 // of FindBackwards 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; // the text set by setData 00416 int m_index; 00417 int m_matchedLength; 00418 bool m_dialogClosed; 00419 bool m_lastResult; 00420 00421 // Binary compatible extensibility. 00422 struct Private; 00423 Private *d; 00424 }; 00425 00426 #endif