1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
/* This file is part of the KDE project
Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
Copyright (C) 2001, S.R.Haque <srhaque@iee.org>
Copyright (C) 2001, David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef kosearchdia_h
#define kosearchdia_h
#include <kfind.h>
#include <kfinddialog.h>
#include <kreplace.h>
#include <kreplacedialog.h>
#include "KoTextIterator.h"
#include "KoTextFormat.h"
#include <tqcolor.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <koffice_export.h>
class TQPushButton;
class TQRadioButton;
class TQGridLayout;
class TQCheckBox;
class TQComboBox;
class TQSpinBox;
class KColorButton;
class KMacroCommand;
class KoTextView;
class KoTextObject;
class KCommand;
class KoTextDocument;
class KoFindReplace;
class TDEFontCombo;
class KoTextCursor;
//
// This class represents the KWord-specific search extension items, and also the
// corresponding replace items.
//
class KOTEXT_EXPORT KoSearchContext
{
public:
// Options.
typedef enum
{
Family = 1 * KFindDialog::MinimumUserOption,
Color = 2 * KFindDialog::MinimumUserOption,
Size = 4 * KFindDialog::MinimumUserOption,
Bold = 8 * KFindDialog::MinimumUserOption,
Italic = 16 * KFindDialog::MinimumUserOption,
Underline = 32 * KFindDialog::MinimumUserOption,
VertAlign = 64 * KFindDialog::MinimumUserOption,
StrikeOut = 128 * KFindDialog::MinimumUserOption,
BgColor = 256 * KFindDialog::MinimumUserOption,
Shadow = 512 * KFindDialog::MinimumUserOption,
WordByWord = 1024 * KFindDialog::MinimumUserOption,
Attribute = 2048 * KFindDialog::MinimumUserOption,
Language = 4096 * KFindDialog::MinimumUserOption
} Options;
KoSearchContext();
~KoSearchContext();
TQString m_family;
TQColor m_color;
TQColor m_backGroundColor;
int m_size;
KoTextFormat::VerticalAlignment m_vertAlign;
KoTextFormat::UnderlineType m_underline;
KoTextFormat::StrikeOutType m_strikeOut;
KoTextFormat::AttributeStyle m_attribute;
TQStringList m_strings; // history
long m_optionsMask;
long m_options;
TQString m_language;
};
//
// This class represents the GUI elements that correspond to KWSearchContext.
//
class KoSearchContextUI : public TQObject
{
Q_OBJECT
public:
KoSearchContextUI( KoSearchContext *ctx, TQWidget *parent );
void setCtxOptions( long options );
void setCtxHistory( const TQStringList & history );
KoSearchContext *context() const { return m_ctx;}
bool optionSelected() const { return m_bOptionsShown;}
private slots:
void slotShowOptions();
private:
KoSearchContext *m_ctx;
TQGridLayout *m_grid;
bool m_bOptionsShown;
TQPushButton *m_btnShowOptions;
TQWidget *m_parent;
};
//
// This class is the KWord search dialog.
//
class KOTEXT_EXPORT KoSearchDia:
public KFindDialog
{
Q_OBJECT
public:
KoSearchDia( TQWidget *parent, const char *name, KoSearchContext *find, bool hasSelection, bool hasCursor );
KoSearchContext * searchContext() {
return m_findUI->context();
}
bool optionSelected() const { return m_findUI->optionSelected();}
protected slots:
void slotOk();
private:
KoSearchContextUI *m_findUI;
};
//
// This class is the kotext replace dialog.
//
class KOTEXT_EXPORT KoReplaceDia:
public KReplaceDialog
{
Q_OBJECT
public:
KoReplaceDia( TQWidget *parent, const char *name, KoSearchContext *find, KoSearchContext *replace, bool hasSelection, bool hasCursor );
KoSearchContext * searchContext() {
return m_findUI->context();
}
KoSearchContext * replaceContext() {
return m_replaceUI->context();
}
bool optionFindSelected() const { return m_findUI->optionSelected();}
bool optionReplaceSelected() const { return m_replaceUI->optionSelected();}
protected slots:
void slotOk();
private:
KoSearchContextUI *m_findUI;
KoSearchContextUI *m_replaceUI;
};
/**
* Reimplement KFind to provide our own validateMatch - for the formatting options
*/
class KoTextFind : public KFind
{
Q_OBJECT
public:
KoTextFind(const TQString &pattern, long options, KoFindReplace *_findReplace, TQWidget *parent = 0);
~KoTextFind();
virtual bool validateMatch( const TQString &text, int index, int matchedlength );
private:
KoFindReplace * m_findReplace;
};
/**
* Reimplement KoReplace to provide our own validateMatch - for the formatting options
*/
class KoTextReplace : public KReplace
{
Q_OBJECT
public:
KoTextReplace(const TQString &pattern, const TQString &replacement, long options, KoFindReplace *_findReplace, TQWidget *parent = 0);
~KoTextReplace();
virtual bool validateMatch( const TQString &text, int index, int matchedlength );
private:
KoFindReplace * m_findReplace;
};
/**
* This class implements the 'find' functionality ( the "search next, prompt" loop )
* and the 'replace' functionality. Same class, to allow centralizing the findNext() code.
*/
class KOTEXT_EXPORT KoFindReplace : public TQObject
{
Q_OBJECT
public:
KoFindReplace( TQWidget * parent, KoSearchDia * dialog, const TQValueList<KoTextObject *> & lstObject, KoTextView* textView );
KoFindReplace( TQWidget * parent, KoReplaceDia * dialog, const TQValueList<KoTextObject *> & lstObject, KoTextView* textView );
~KoFindReplace();
KoTextParag *currentParag() {
return m_textIterator.currentParag();
}
bool isReplace() const { return m_replace != 0L; }
bool shouldRestart();
//int numMatches() const;
//int numReplacements() const;
/** Look for the next match. Returns false if we're finished. */
bool findNext();
/** Look for the previous match. Returns false if we're finished. */
bool findPrevious();
/** Bring to front (e.g. when menuitem called twice) */
void setActiveWindow();
/** Emit undo/redo command for the last replacements made. */
void emitUndoRedo();
virtual void emitNewCommand(KCommand *) = 0;
/**
* Highlight a match.
*/
virtual void highlightPortion(KoTextParag * parag, int index, int length, KoTextDocument *textdoc, KDialogBase* dialog) = 0;
/** For KoTextFind and KoTextReplace */
bool validateMatch( const TQString &text, int index, int matchedlength );
protected:
void replaceWithAttribut( KoTextCursor * cursor, int index );
KMacroCommand* macroCommand();
long options() const;
void setOptions(long opt);
void removeHighlight();
bool needData() const { return m_find ? m_find->needData() : m_replace->needData(); }
void setData( const TQString& data, int startPos = -1 ) {
if ( m_find ) m_find->setData( data, startPos );
else m_replace->setData( data, startPos );
}
protected slots:
void slotFindNext();
void optionsChanged();
void dialogClosed();
void highlight( const TQString &text, int matchingIndex, int matchingLength );
void replace( const TQString &text, int replacementIndex, int replacedLength, int searchLength );
void slotCurrentParagraphModified( int, int, int );
private:
void connectFind( KFind* find );
// Only one of those two will be set
KoTextFind * m_find;
KoTextReplace * m_replace;
KoSearchContext m_searchContext;
KoSearchContext m_replaceContext;
bool m_searchContextEnabled;
bool m_doCounting;
bool m_bInit;
bool m_currentParagraphModified;
KMacroCommand *m_macroCmd;
int m_offset;
int m_matchingIndex; // can be removed once we use kde-3.2 (for kfind::index())
KoTextIterator m_textIterator;
// For removing the last highlight
KoTextObject* m_lastTextObjectHighlighted;
};
/**
* The separate dialog that pops up to ask for which formatting options
* should be used to match text, or when replacing text.
*/
class KoFormatDia: public KDialogBase
{
Q_OBJECT
public:
KoFormatDia( TQWidget* parent, const TQString & _caption, KoSearchContext *_ctx, const char* name=0L);
//apply to parameter to context !
void ctxOptions( );
protected slots:
void slotReset();
void slotClear();
private:
TQCheckBox *m_checkFamily;
TQCheckBox *m_checkSize;
TQCheckBox *m_checkColor;
TQCheckBox *m_checkBgColor;
TQCheckBox *m_checkBold;
TQCheckBox *m_checkItalic;
TQCheckBox *m_checkShadow;
TQCheckBox *m_checkWordByWord;
TQCheckBox *m_checkUnderline;
TQCheckBox *m_checkVertAlign;
TQCheckBox *m_checkStrikeOut;
TQCheckBox *m_checkFontAttribute;
TQCheckBox *m_checkLanguage;
TDEFontCombo *m_familyItem;
TQSpinBox *m_sizeItem;
KColorButton *m_colorItem;
KColorButton *m_bgColorItem;
TQRadioButton *m_boldYes;
TQRadioButton *m_boldNo;
TQRadioButton *m_italicYes;
TQRadioButton *m_italicNo;
TQRadioButton *m_shadowYes;
TQRadioButton *m_shadowNo;
TQRadioButton *m_wordByWordYes;
TQRadioButton *m_wordByWordNo;
TQComboBox *m_vertAlignItem;
TQComboBox *m_underlineItem;
TQComboBox *m_strikeOutItem;
TQComboBox *m_fontAttributeItem;
TQComboBox *m_languageItem;
KoSearchContext *m_ctx;
};
#endif
|