F:/KPlato/koffice/libs/kotext/KoSearchDia.h

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003    Copyright (C) 2001, S.R.Haque <srhaque@iee.org>
00004    Copyright (C) 2001, David Faure <faure@kde.org>
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 as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef kosearchdia_h
00023 #define kosearchdia_h
00024 
00025 #include <kfind.h>
00026 #include <kfinddialog.h>
00027 #include <kreplace.h>
00028 #include <kreplacedialog.h>
00029 #include "KoTextIterator.h"
00030 #include "KoTextFormat.h"
00031 
00032 #include <QColor>
00033 #include <QString>
00034 #include <QStringList>
00035 //Added by qt3to4:
00036 #include <Q3GridLayout>
00037 #include <Q3ValueList>
00038 #include <koffice_export.h>
00039 
00040 class QPushButton;
00041 class QRadioButton;
00042 class Q3GridLayout;
00043 class QCheckBox;
00044 class QComboBox;
00045 class QSpinBox;
00046 class KColorButton;
00047 class KMacroCommand;
00048 class KoTextView;
00049 class KoTextObject;
00050 class KCommand;
00051 class KoTextDocument;
00052 class KoFindReplace;
00053 class QFontComboBox;
00054 class KoTextCursor;
00055 //
00056 // This class represents the KWord-specific search extension items, and also the
00057 // corresponding replace items.
00058 //
00059 class KOTEXT_EXPORT KoSearchContext
00060 {
00061 public:
00062 
00063     // Options.
00064 
00065     typedef enum
00066     {
00067         Family = 1 * KFind::MinimumUserOption,
00068         Color = 2 * KFind::MinimumUserOption,
00069         Size = 4 * KFind::MinimumUserOption,
00070         Bold = 8 * KFind::MinimumUserOption,
00071         Italic = 16 * KFind::MinimumUserOption,
00072         Underline = 32 * KFind::MinimumUserOption,
00073         VertAlign = 64 * KFind::MinimumUserOption,
00074         StrikeOut = 128 * KFind::MinimumUserOption,
00075         BgColor = 256 * KFind::MinimumUserOption,
00076         Shadow = 512 * KFind::MinimumUserOption,
00077         WordByWord = 1024 * KFind::MinimumUserOption,
00078         Attribute = 2048 * KFind::MinimumUserOption,
00079         Language = 4096 * KFind::MinimumUserOption
00080     } Options;
00081 
00082     KoSearchContext();
00083     ~KoSearchContext();
00084 
00085     QString m_family;
00086     QColor m_color;
00087     QColor m_backGroundColor;
00088     int m_size;
00089     KoTextFormat::VerticalAlignment m_vertAlign;
00090     KoTextFormat::UnderlineType m_underline;
00091     KoTextFormat::StrikeOutType m_strikeOut;
00092     KoTextFormat::AttributeStyle m_attribute;
00093 
00094     QStringList m_strings; // history
00095     long m_optionsMask;
00096     long m_options;
00097     QString m_language;
00098 };
00099 
00100 //
00101 // This class represents the GUI elements that correspond to KWSearchContext.
00102 //
00103 class KoSearchContextUI : public QObject
00104 {
00105     Q_OBJECT
00106 public:
00107     KoSearchContextUI( KoSearchContext *ctx, QWidget *parent );
00108     void setCtxOptions( long options );
00109     void setCtxHistory( const QStringList & history );
00110     KoSearchContext *context() const { return m_ctx;}
00111     bool optionSelected() const { return m_bOptionsShown;}
00112 private slots:
00113     void slotShowOptions();
00114 
00115 private:
00116     KoSearchContext *m_ctx;
00117     Q3GridLayout *m_grid;
00118     bool m_bOptionsShown;
00119     QPushButton *m_btnShowOptions;
00120     QWidget *m_parent;
00121 };
00122 
00123 //
00124 // This class is the KWord search dialog.
00125 //
00126 class KOTEXT_EXPORT KoSearchDia:
00127     public KFindDialog
00128 {
00129     Q_OBJECT
00130 
00131 public:
00132     KoSearchDia( QWidget *parent, const char *name, KoSearchContext *find, bool hasSelection, bool hasCursor );
00133     KoSearchContext * searchContext() {
00134         return m_findUI->context();
00135     }
00136     bool optionSelected() const { return m_findUI->optionSelected();}
00137 
00138 protected slots:
00139     void slotOk();
00140 
00141 private:
00142     KoSearchContextUI *m_findUI;
00143 };
00144 
00145 //
00146 // This class is the kotext replace dialog.
00147 //
00148 class KOTEXT_EXPORT KoReplaceDia:
00149     public KReplaceDialog
00150 {
00151     Q_OBJECT
00152 
00153 public:
00154 
00155     KoReplaceDia( QWidget *parent, const char *name, KoSearchContext *find, KoSearchContext *replace, bool hasSelection, bool hasCursor );
00156     KoSearchContext * searchContext() {
00157         return m_findUI->context();
00158     }
00159     KoSearchContext * replaceContext() {
00160         return m_replaceUI->context();
00161     }
00162     bool optionFindSelected() const { return m_findUI->optionSelected();}
00163     bool optionReplaceSelected() const { return m_replaceUI->optionSelected();}
00164 protected slots:
00165     void slotOk();
00166 
00167 private:
00168 
00169     KoSearchContextUI *m_findUI;
00170     KoSearchContextUI *m_replaceUI;
00171 };
00172 
00176 class KoTextFind : public KFind
00177 {
00178     Q_OBJECT
00179 public:
00180     KoTextFind(const QString &pattern, long options, KoFindReplace *_findReplace, QWidget *parent = 0);
00181     ~KoTextFind();
00182     virtual bool validateMatch( const QString &text, int index, int matchedlength );
00183 private:
00184     KoFindReplace * m_findReplace;
00185 };
00186 
00190 class KoTextReplace : public KReplace
00191 {
00192     Q_OBJECT
00193 public:
00194     KoTextReplace(const QString &pattern, const QString &replacement, long options, KoFindReplace *_findReplace, QWidget *parent = 0);
00195     ~KoTextReplace();
00196     virtual bool validateMatch( const QString &text, int index, int matchedlength );
00197 private:
00198     KoFindReplace * m_findReplace;
00199 };
00200 
00205 class KOTEXT_EXPORT KoFindReplace : public QObject
00206 {
00207     Q_OBJECT
00208 public:
00209     KoFindReplace( QWidget * parent, KoSearchDia * dialog, const Q3ValueList<KoTextObject *> & lstObject, KoTextView* textView );
00210     KoFindReplace( QWidget * parent, KoReplaceDia * dialog, const Q3ValueList<KoTextObject *> & lstObject, KoTextView* textView );
00211     ~KoFindReplace();
00212 
00213     KoTextParag *currentParag() {
00214         return m_textIterator.currentParag();
00215     }
00216 
00217     bool isReplace() const { return m_replace != 0L; }
00218 
00219     bool shouldRestart();
00220 
00221     //int numMatches() const;
00222     //int numReplacements() const;
00223 
00225     bool findNext();
00226 
00228     bool findPrevious();
00229 
00231     void setActiveWindow();
00232 
00234     void emitUndoRedo();
00235 
00236     virtual void emitNewCommand(KCommand *) = 0;
00237 
00241     virtual void highlightPortion(KoTextParag * parag, int index, int length, KoTextDocument *textdoc, KDialog* dialog) = 0;
00242 
00244     bool validateMatch( const QString &text, int index, int matchedlength );
00245 
00246 protected:
00247     void replaceWithAttribut( KoTextCursor * cursor, int index );
00248     KMacroCommand* macroCommand();
00249     long options() const;
00250     void setOptions(long opt);
00251     void removeHighlight();
00252     bool needData() const { return m_find ? m_find->needData() : m_replace->needData(); }
00253     void setData( const QString& data, int startPos = -1 ) {
00254         if ( m_find ) m_find->setData( data, startPos );
00255         else m_replace->setData( data, startPos );
00256     }
00257 
00258 protected slots:
00259     void slotFindNext();
00260     void optionsChanged();
00261     void dialogClosed();
00262     void highlight( const QString &text, int matchingIndex, int matchingLength );
00263     void replace( const QString &text, int replacementIndex, int replacedLength, int searchLength );
00264     void slotCurrentParagraphModified( int, int, int );
00265 
00266 private:
00267     void connectFind( KFind* find );
00268 
00269     // Only one of those two will be set
00270     KoTextFind * m_find;
00271     KoTextReplace * m_replace;
00272 
00273     KoSearchContext m_searchContext;
00274     KoSearchContext m_replaceContext;
00275     bool m_searchContextEnabled;
00276     bool m_doCounting;
00277     bool m_bInit;
00278     bool m_currentParagraphModified;
00279 
00280     KMacroCommand *m_macroCmd;
00281     int m_offset;
00282     int m_matchingIndex; // can be removed once we use kde-3.2 (for kfind::index())
00283 
00284     KoTextIterator m_textIterator;
00285 
00286     // For removing the last highlight
00287     KoTextObject* m_lastTextObjectHighlighted;
00288 };
00289 
00294 class KoFormatDia: public KDialog
00295 {
00296     Q_OBJECT
00297 public:
00298     KoFormatDia( QWidget* parent, const QString & _caption, KoSearchContext *_ctx, const char* name=0L);
00299     //apply to parameter to context !
00300     void ctxOptions( );
00301 
00302 protected slots:
00303     void slotReset();
00304     void slotClear();
00305 private:
00306     QCheckBox *m_checkFamily;
00307     QCheckBox *m_checkSize;
00308     QCheckBox *m_checkColor;
00309     QCheckBox *m_checkBgColor;
00310     QCheckBox *m_checkBold;
00311     QCheckBox *m_checkItalic;
00312     QCheckBox *m_checkShadow;
00313     QCheckBox *m_checkWordByWord;
00314     QCheckBox *m_checkUnderline;
00315     QCheckBox *m_checkVertAlign;
00316     QCheckBox *m_checkStrikeOut;
00317     QCheckBox *m_checkFontAttribute;
00318     QCheckBox *m_checkLanguage;
00319 
00320     QFontComboBox *m_familyItem;
00321     QSpinBox *m_sizeItem;
00322     KColorButton *m_colorItem;
00323     KColorButton *m_bgColorItem;
00324     QRadioButton *m_boldYes;
00325     QRadioButton *m_boldNo;
00326     QRadioButton *m_italicYes;
00327     QRadioButton *m_italicNo;
00328     QRadioButton *m_shadowYes;
00329     QRadioButton *m_shadowNo;
00330     QRadioButton *m_wordByWordYes;
00331     QRadioButton *m_wordByWordNo;
00332 
00333     QComboBox *m_vertAlignItem;
00334     QComboBox *m_underlineItem;
00335     QComboBox *m_strikeOutItem;
00336     QComboBox *m_fontAttributeItem;
00337     QComboBox *m_languageItem;
00338     KoSearchContext *m_ctx;
00339 };
00340 
00341 #endif

Généré le Wed Nov 22 23:41:08 2006 pour KPlato par  doxygen 1.5.1-p1