lib

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