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
00101 class KUTILS_EXPORT 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
00323
00324
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;
00369
int m_index;
00370
int m_matchedLength;
00371
bool m_dialogClosed;
00372
bool m_lastResult;
00373
00374
00375 struct Private;
00376 Private *d;
00377 };
00378
00379 #endif