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 
00097 class KFind :
00098     public QObject
00099 {
00100     Q_OBJECT
00101 
00102 public:
00103 
00104     KFind(const QString &pattern, long options, QWidget *parent);
00105     virtual ~KFind();
00106 
00107     enum Result { NoMatch, Match };
00108 
00115     bool needData() const;
00125     void setData( const QString& data, int startPos = -1 );
00126 
00132     Result find();
00133 
00142     long options() const { return m_options; }
00143 
00148     virtual void setOptions( long options );
00149 
00156     int numMatches() const { return m_matches; }
00157 
00164     virtual void resetCounts() { m_matches = 0; }
00165 
00176     virtual bool validateMatch( const QString &/*text*/, int /*index*/, int /*matchedlength*/ ) { return true; }
00177 
00191     virtual bool shouldRestart( bool forceAsking = false, bool showNumMatches = true ) const;
00192 
00206     static int find( const QString &text, const QString &pattern, int index, long options, int *matchedlength );
00207     static int find( const QString &text, const QRegExp &pattern, int index, long options, int *matchedlength );
00208 
00213     virtual void displayFinalDialog() const;
00214 
00222     KDialogBase* findNextDialog( bool create = false );
00223 
00229     void closeFindNextDialog();
00230 
00231 signals:
00232 
00237     void highlight(const QString &text, int matchingIndex, int matchedLength);
00238 
00239     // ## TODO docu
00240     // findprevious will also emit findNext, after temporarily switching the value
00241     // of FindBackwards
00242     void findNext();
00243 
00249     void optionsChanged();
00250 
00257     void dialogClosed();
00258 
00259 protected:
00263     KFind(const QString &pattern, const QString &replacement, long options, QWidget *parent);
00264 
00265     QWidget* parentWidget() const { return (QWidget *)parent(); }
00266 
00267 protected slots:
00268 
00269     void slotFindNext();
00270     void slotDialogClosed();
00271 
00272 private:
00273     void init( const QString& pattern );
00274 
00275     static bool isInWord( QChar ch );
00276     static bool isWholeWords( const QString &text, int starts, int matchedLength );
00277 
00278     friend class KReplace;
00279 
00280 
00281     QString m_pattern;
00282     QRegExp *m_regExp;
00283     KDialogBase* m_dialog;
00284     long m_options;
00285     unsigned m_matches;
00286 
00287     QString m_text; // the text set by setData
00288     int m_index;
00289     int m_matchedLength;
00290     bool m_dialogClosed;
00291     bool m_lastResult;
00292 
00293     // Binary compatible extensibility.
00294     class KFindPrivate;
00295     KFindPrivate *d;
00296 };
00297 
00298 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:28:04 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001