00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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.h>
00033 #include <qstring.h>
00034 #include <qstringlist.h>
00035
00036 class QPushButton;
00037 class QRadioButton;
00038 class QGridLayout;
00039 class QCheckBox;
00040 class QComboBox;
00041 class QSpinBox;
00042 class KColorButton;
00043 class KMacroCommand;
00044 class KoTextView;
00045 class KoTextObject;
00046 class KCommand;
00047 class KoTextDocument;
00048 class KoFindReplace;
00049 class KFontCombo;
00050 class KoTextCursor;
00051
00052
00053
00054
00055 class KoSearchContext
00056 {
00057 public:
00058
00059
00060
00061 typedef enum
00062 {
00063 Family = 1 * KFindDialog::MinimumUserOption,
00064 Color = 2 * KFindDialog::MinimumUserOption,
00065 Size = 4 * KFindDialog::MinimumUserOption,
00066 Bold = 8 * KFindDialog::MinimumUserOption,
00067 Italic = 16 * KFindDialog::MinimumUserOption,
00068 Underline = 32 * KFindDialog::MinimumUserOption,
00069 VertAlign = 64 * KFindDialog::MinimumUserOption,
00070 StrikeOut = 128 * KFindDialog::MinimumUserOption,
00071 BgColor = 256 * KFindDialog::MinimumUserOption,
00072 Shadow = 512 * KFindDialog::MinimumUserOption,
00073 WordByWord = 1024 * KFindDialog::MinimumUserOption,
00074 Attribute = 2048 * KFindDialog::MinimumUserOption,
00075 Language = 4096 * KFindDialog::MinimumUserOption
00076 } Options;
00077
00078 KoSearchContext();
00079 ~KoSearchContext();
00080
00081 QString m_family;
00082 QColor m_color;
00083 QColor m_backGroundColor;
00084 int m_size;
00085 KoTextFormat::VerticalAlignment m_vertAlign;
00086 KoTextFormat::UnderlineType m_underline;
00087 KoTextFormat::StrikeOutType m_strikeOut;
00088 KoTextFormat::AttributeStyle m_attribute;
00089
00090 QStringList m_strings;
00091 long m_optionsMask;
00092 long m_options;
00093 QString m_language;
00094 };
00095
00096
00097
00098
00099 class KoSearchContextUI : public QObject
00100 {
00101 Q_OBJECT
00102 public:
00103 KoSearchContextUI( KoSearchContext *ctx, QWidget *parent );
00104 void setCtxOptions( long options );
00105 void setCtxHistory( const QStringList & history );
00106 KoSearchContext *context() const { return m_ctx;}
00107 bool optionSelected() const { return m_bOptionsShown;}
00108 private slots:
00109 void slotShowOptions();
00110
00111 private:
00112 KoSearchContext *m_ctx;
00113 QGridLayout *m_grid;
00114 bool m_bOptionsShown;
00115 QPushButton *m_btnShowOptions;
00116 QWidget *m_parent;
00117 };
00118
00119
00120
00121
00122 class KoSearchDia:
00123 public KFindDialog
00124 {
00125 Q_OBJECT
00126
00127 public:
00128 KoSearchDia( QWidget *parent, const char *name, KoSearchContext *find, bool hasSelection, bool hasCursor );
00129 KoSearchContext * searchContext() {
00130 return m_findUI->context();
00131 }
00132 bool optionSelected() const { return m_findUI->optionSelected();}
00133
00134 protected slots:
00135 void slotOk();
00136
00137 private:
00138 KoSearchContextUI *m_findUI;
00139 };
00140
00141
00142
00143
00144 class KoReplaceDia:
00145 public KReplaceDialog
00146 {
00147 Q_OBJECT
00148
00149 public:
00150
00151 KoReplaceDia( QWidget *parent, const char *name, KoSearchContext *find, KoSearchContext *replace, bool hasSelection, bool hasCursor );
00152 KoSearchContext * searchContext() {
00153 return m_findUI->context();
00154 }
00155 KoSearchContext * replaceContext() {
00156 return m_replaceUI->context();
00157 }
00158 bool optionFindSelected() const { return m_findUI->optionSelected();}
00159 bool optionReplaceSelected() const { return m_replaceUI->optionSelected();}
00160 protected slots:
00161 void slotOk();
00162
00163 private:
00164
00165 KoSearchContextUI *m_findUI;
00166 KoSearchContextUI *m_replaceUI;
00167 };
00168
00172 class KoTextFind : public KFind
00173 {
00174 Q_OBJECT
00175 public:
00176 KoTextFind(const QString &pattern, long options, KoFindReplace *_findReplace, QWidget *parent = 0);
00177 ~KoTextFind();
00178 virtual bool validateMatch( const QString &text, int index, int matchedlength );
00179 private:
00180 KoFindReplace * m_findReplace;
00181 };
00182
00186 class KoTextReplace : public KReplace
00187 {
00188 Q_OBJECT
00189 public:
00190 KoTextReplace(const QString &pattern, const QString &replacement, long options, KoFindReplace *_findReplace, QWidget *parent = 0);
00191 ~KoTextReplace();
00192 virtual bool validateMatch( const QString &text, int index, int matchedlength );
00193 private:
00194 KoFindReplace * m_findReplace;
00195 };
00196
00201 class KoFindReplace : public QObject
00202 {
00203 Q_OBJECT
00204 public:
00205 KoFindReplace( QWidget * parent, KoSearchDia * dialog, const QValueList<KoTextObject *> & lstObject, KoTextView* textView );
00206 KoFindReplace( QWidget * parent, KoReplaceDia * dialog, const QValueList<KoTextObject *> & lstObject, KoTextView* textView );
00207 ~KoFindReplace();
00208
00209 KoTextParag *currentParag() {
00210 return m_textIterator.currentParag();
00211 }
00212
00213 bool isReplace() const { return m_replace != 0L; }
00214
00215 bool shouldRestart();
00216
00217
00218
00219
00221 bool findNext();
00222
00224 bool findPrevious();
00225
00227 void setActiveWindow();
00228
00230 void emitUndoRedo();
00231
00232 virtual void emitNewCommand(KCommand *) = 0;
00233
00237 virtual void highlightPortion(KoTextParag * parag, int index, int length, KoTextDocument *textdoc, KDialogBase* dialog) = 0;
00238
00240 bool validateMatch( const QString &text, int index, int matchedlength );
00241
00242 protected:
00243 void replaceWithAttribut( KoTextCursor * cursor, int index );
00244 KMacroCommand* macroCommand();
00245 long options() const;
00246 void setOptions(long opt);
00247 void removeHighlight();
00248 bool needData() const { return m_find ? m_find->needData() : m_replace->needData(); }
00249 void setData( const QString& data, int startPos = -1 ) {
00250 if ( m_find ) m_find->setData( data, startPos );
00251 else m_replace->setData( data, startPos );
00252 }
00253
00254 protected slots:
00255 void slotFindNext();
00256 void optionsChanged();
00257 void dialogClosed();
00258 void highlight( const QString &text, int matchingIndex, int matchingLength );
00259 void replace( const QString &text, int replacementIndex, int replacedLength, int searchLength );
00260 void slotCurrentParagraphModified( int, int, int );
00261
00262 private:
00263 void connectFind( KFind* find );
00264
00265
00266 KoTextFind * m_find;
00267 KoTextReplace * m_replace;
00268
00269 KoSearchContext m_searchContext;
00270 KoSearchContext m_replaceContext;
00271 bool m_searchContextEnabled;
00272 bool m_doCounting;
00273 bool m_bInit;
00274 bool m_currentParagraphModified;
00275
00276 KMacroCommand *m_macroCmd;
00277 int m_offset;
00278 int m_matchingIndex;
00279
00280 KoTextIterator m_textIterator;
00281
00282
00283 KoTextObject* m_lastTextObjectHighlighted;
00284 };
00285
00290 class KoFormatDia: public KDialogBase
00291 {
00292 Q_OBJECT
00293 public:
00294 KoFormatDia( QWidget* parent, const QString & _caption, KoSearchContext *_ctx, const char* name=0L);
00295
00296 void ctxOptions( );
00297
00298 protected slots:
00299 void slotReset();
00300 void slotClear();
00301 private:
00302 QCheckBox *m_checkFamily;
00303 QCheckBox *m_checkSize;
00304 QCheckBox *m_checkColor;
00305 QCheckBox *m_checkBgColor;
00306 QCheckBox *m_checkBold;
00307 QCheckBox *m_checkItalic;
00308 QCheckBox *m_checkShadow;
00309 QCheckBox *m_checkWordByWord;
00310 QCheckBox *m_checkUnderline;
00311 QCheckBox *m_checkVertAlign;
00312 QCheckBox *m_checkStrikeOut;
00313 QCheckBox *m_checkFontAttribute;
00314 QCheckBox *m_checkLanguage;
00315
00316 KFontCombo *m_familyItem;
00317 QSpinBox *m_sizeItem;
00318 KColorButton *m_colorItem;
00319 KColorButton *m_bgColorItem;
00320 QRadioButton *m_boldYes;
00321 QRadioButton *m_boldNo;
00322 QRadioButton *m_italicYes;
00323 QRadioButton *m_italicNo;
00324 QRadioButton *m_shadowYes;
00325 QRadioButton *m_shadowNo;
00326 QRadioButton *m_wordByWordYes;
00327 QRadioButton *m_wordByWordNo;
00328
00329 QComboBox *m_vertAlignItem;
00330 QComboBox *m_underlineItem;
00331 QComboBox *m_strikeOutItem;
00332 QComboBox *m_fontAttributeItem;
00333 QComboBox *m_languageItem;
00334 KoSearchContext *m_ctx;
00335 };
00336
00337 #endif