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