KDevelop API Documentation

koFind.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2001, S.R.Haque <srhaque@iee.org>.
00003     This file is part of the KDE project
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
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 KOFIND_H
00022 #define KOFIND_H
00023 
00024 #include <kdialogbase.h>
00025 
00026 class KHistoryCombo;
00027 class QCheckBox;
00028 class QGroupBox;
00029 class QLabel;
00030 class QPopupMenu;
00031 class QPushButton;
00032 class QRect;
00033 class QGridLayout;
00034 
00063 class KoFindDialog:
00064     public KDialogBase
00065 {
00066     Q_OBJECT
00067 
00068 public:
00069 
00070     // Options.
00071 
00072     typedef enum
00073     {
00074         WholeWordsOnly = 1,     // Match whole words only.
00075         FromCursor = 2,         // Start from current cursor position.
00076         SelectedText = 4,       // Only search selected area.
00077         CaseSensitive = 8,      // Consider case when matching.
00078         FindBackwards = 16,     // Go backwards.
00079         RegularExpression = 32, // Interpret the pattern as a regular expression.
00080         // User extensions can use boolean options above this value.
00081         MinimumUserOption = 65536
00082     } Options;
00083 
00093     KoFindDialog( QWidget *parent = 0, const char *name = 0, long options = 0,
00094                   const QStringList &findStrings = QStringList(), bool hasSelection = true );
00095 
00099     virtual ~KoFindDialog();
00100 
00109     void setFindHistory( const QStringList &strings );
00110 
00116     QStringList findHistory() const;
00117 
00124     void setHasSelection( bool hasSelection );
00125 
00131     void setOptions( long options );
00132 
00139     long options() const;
00140 
00144     QString pattern() const;
00145 
00152     QWidget *findExtension();
00153 
00154 signals:
00155 
00160     void okClicked();
00161 
00162 protected slots:
00163 
00164     void slotOk();
00165     void slotSelectedTextToggled(bool);
00166     void showPatterns();
00167     void showPlaceholders();
00168     void textSearchChanged( const QString &);
00169   
00170 public:        
00171     KHistoryCombo *m_find;
00172     KHistoryCombo *m_replace;
00173 
00174 private:
00175     QGroupBox *m_findGrp;
00176     QLabel *m_findLabel;
00177     QCheckBox *m_regExp;
00178     QPushButton *m_regExpItem;
00179     QGridLayout *m_findLayout;
00180     QWidget *m_findExtension;
00181 
00182     QGroupBox *m_optionGrp;
00183     QCheckBox *m_wholeWordsOnly;
00184     QCheckBox *m_fromCursor;
00185     QCheckBox *m_selectedText;
00186     QCheckBox *m_caseSensitive;
00187     QCheckBox *m_findBackwards;
00188 
00189     QPopupMenu *m_patterns;
00190 
00191     // Our dirty little secret is that we also implement the "replace" dialog. But we
00192     // keep that fact hidden from all but our friends.
00193 
00194     friend class KoReplaceDialog;
00195 
00204     KoFindDialog( QWidget *parent, const char *name, bool forReplace );
00205     void init( bool forReplace, const QStringList &findStrings, bool hasSelection );
00206 
00207     QGroupBox *m_replaceGrp;
00208     QLabel *m_replaceLabel;
00209     QCheckBox* m_backRef;
00210     QPushButton* m_backRefItem;
00211     QGridLayout *m_replaceLayout;
00212     QWidget *m_replaceExtension;
00213 
00214     QCheckBox* m_promptOnReplace;
00215 
00216     QPopupMenu *m_placeholders;
00217 
00218     // Binary compatible extensibility.
00219     class KoFindDialogPrivate;
00220     KoFindDialogPrivate *d;
00221 };
00222 
00260 class KoFind :
00261     public KDialogBase
00262 {
00263     Q_OBJECT
00264 
00265 public:
00266 
00267     // Will create a prompt dialog and use it as needed.
00268     KoFind(const QString &pattern, long options, QWidget *parent = 0);
00269     ~KoFind();
00270 
00280     bool find(const QString &text, const QRect &expose);
00281 
00282     virtual bool validateMatch( const QString &/*text*/, int /*index*/, int /*matchedlength*/ ) { return true; }
00283 
00298     static int find( const QString &text, const QString &pattern, int index, long options, int *matchedlength );
00299     static int find( const QString &text, const QRegExp &pattern, int index, long options, int *matchedlength );
00300 
00305     void abort();
00306 
00307 signals:
00308 
00309     // Connect to this signal to implement highlighting of found text during the find
00310     // operation.
00311     void highlight(const QString &text, int matchingIndex, int matchedLength, const QRect &expose);
00312 
00313 private:
00314 
00315     QString m_pattern;
00316     QRegExp *m_regExp;
00317     long m_options;
00318     QWidget *m_parent;
00319     unsigned m_matches;
00320     QString m_text;
00321     int m_index;
00322     QRect m_expose;
00323     int m_matchedLength;
00324     bool m_cancelled;
00325 
00326     static bool isInWord( QChar ch );
00327     static bool isWholeWords( const QString &text, int starts, int matchedLength );
00328 
00329     // Binary compatible extensibility.
00330     class KoFindPrivate;
00331     KoFindPrivate *d;
00332 
00333 private slots:
00334 
00335     virtual void slotUser1();   // Yes
00336     virtual void slotClose();
00337 };
00338 
00339 #endif
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003