kutils Library API Documentation

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., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef KFIND_H
00022 #define KFIND_H
00023 
00024 #include <kdialogbase.h>
00025 #include <qrect.h>
00026 
00101 class KFind :
00102     public QObject
00103 {
00104     Q_OBJECT
00105 
00106 public:
00107 
00112     KFind(const QString &pattern, long options, QWidget *parent);
00113 
00120     KFind(const QString &pattern, long options, QWidget *parent, QWidget* findDialog);
00121     virtual ~KFind();
00122 
00123     enum Result { NoMatch, Match };
00124 
00131     bool needData() const;
00132 
00142     void setData( const QString& data, int startPos = -1 );
00143 
00157     void setData( int id, const QString& data, int startPos = -1 );
00158 
00164     Result find();
00165 
00174     long options() const { return m_options; }
00175 
00180     virtual void setOptions( long options );
00181 
00185     QString pattern() const { return m_pattern; }
00186 
00190     void setPattern( const QString& pattern );
00191 
00198     int numMatches() const { return m_matches; }
00199 
00206     virtual void resetCounts() { m_matches = 0; }
00207 
00218     virtual bool validateMatch( const QString & text, int index, int matchedlength ) {
00219         Q_UNUSED(text); Q_UNUSED(index); Q_UNUSED(matchedlength); return true; }
00220 
00234     virtual bool shouldRestart( bool forceAsking = false, bool showNumMatches = true ) const;
00235 
00250     static int find( const QString &text, const QString &pattern, int index, long options, int *matchedlength );
00251 
00252     static int find( const QString &text, const QRegExp &pattern, int index, long options, int *matchedlength );
00253 
00258     virtual void displayFinalDialog() const;
00259 
00267     KDialogBase* findNextDialog( bool create = false );
00268 
00277     void closeFindNextDialog();
00278 
00286     int index() const;
00287 
00288 signals:
00289 
00303     void highlight(const QString &text, int matchingIndex, int matchedLength);
00304 
00320     void highlight(int id, int matchingIndex, int matchedLength);
00321 
00322     // ## TODO docu
00323     // findprevious will also emit findNext, after temporarily switching the value
00324     // of FindBackwards
00325     void findNext();
00326 
00332     void optionsChanged();
00333 
00340     void dialogClosed();
00341 
00342 protected:
00343 
00344     QWidget* parentWidget() const { return (QWidget *)parent(); }
00345     QWidget* dialogsParent() const;
00346 
00347 protected slots:
00348 
00349     void slotFindNext();
00350     void slotDialogClosed();
00351 
00352 private:
00353     void init( const QString& pattern );
00354     void startNewIncrementalSearch();
00355 
00356     static bool isInWord( QChar ch );
00357     static bool isWholeWords( const QString &text, int starts, int matchedLength );
00358 
00359     friend class KReplace;
00360 
00361 
00362     QString m_pattern;
00363     QRegExp *m_regExp;
00364     KDialogBase* m_dialog;
00365     long m_options;
00366     unsigned m_matches;
00367 
00368     QString m_text; // the text set by setData
00369     int m_index;
00370     int m_matchedLength;
00371     bool m_dialogClosed;
00372     bool m_lastResult;
00373 
00374     // Binary compatible extensibility.
00375     class Private;
00376     Private *d;
00377 };
00378 
00379 #endif
KDE Logo
This file is part of the documentation for kutils Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Jul 22 10:17:47 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003