1
/* ****************************************************************************
2
This file is part of KBabel
4
Copyright (C) 1999-2000 by Matthias Kiefer
5
<matthias.kiefer@gmx.de>
6
2001-2003 by Stanislav Visnovsky
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
In addition, as a special exception, the copyright holders give
24
permission to link the code of this program with any edition of
25
the Qt library by Trolltech AS, Norway (or with modified versions
26
of Qt that use the same license as Qt), and distribute linked
27
combinations including the two. You must obey the GNU General
28
Public License in all respects for all of the code used other than
29
Qt. If you modify this file, you may extend this exception to
30
your version of the file, but you are not obligated to do so. If
31
you do not wish to do so, delete this exception statement from
34
**************************************************************************** */
35
#ifndef MYMULTILINEEDIT_H
36
#define MYMULTILINEEDIT_H
38
#include <ktextedit.h>
39
#include <qptrvector.h>
46
class KBabelHighlighter;
50
class MyMultiLineEdit : public KTextEdit
54
MyMultiLineEdit(int ID,QWidget* parent,const char* name=0);
57
applies cmd to the displayed text, but does not emit
60
void processCommand(KBabel::EditCommand* cmd, bool undo=false);
63
* @returns the position in text, where the marked text begins
64
* -1, if there is no marked text
66
int beginOfMarkedText();
69
* @returns the position in text, where the last marked text began
70
* or the current cursor position if there was no marked text.
71
* This is used for getting the start position for a text replacement
73
int beginOfLastMarkedText();
76
* @returns the position in text, where the last marked text ended
77
* or the current cursor position if there was no marked text.
78
* This is used for getting the end position for a text replacement
80
int endOfLastMarkedText();
82
virtual void insertAt ( const QString & s, int line, int col, bool mark = false );
83
virtual void removeLine ( int line );
85
int pos2Offset(uint paragraph, uint index);
86
void offset2Pos(int offset, int &row, int &col) const;
88
* @returns the current position in text, where the cursor is
99
* need to override deleting of popup menus :-(
101
void contentsContextMenuEvent( QContextMenuEvent *e );
104
* need to reimplement overwrite mode :-(
106
bool isOverwriteMode() { return _overwrite; }
110
virtual void clear();
111
virtual void paste();
112
virtual void setReadOnly(bool on);
113
virtual void setContextMenu( QPopupMenu *menu );
114
virtual void setText(const QString& s);
115
virtual void doKeyboardAction( KeyboardAction action );
116
virtual void removeSelectedText(int selNum = 0);
118
virtual void onSelectionChanged();
121
reimplemented overwrite mode, since QTextEdit handles this internally and does
122
not use any accessible virtual methods :-((.
124
virtual void setOverwriteMode(bool b);
128
virtual void focusInEvent(QFocusEvent*);
129
virtual QPopupMenu *createPopupMenu();
130
virtual QPopupMenu *createPopupMenu(const QPoint &pos);
132
/* the parent handles this */
133
virtual void wheelEvent(QWheelEvent*);
137
/* First and the last line of the last change. They are only approximate. Used for faster display
140
uint _firstChangedLine;
141
uint _lastChangedLine;
143
/* This is a cache. _lastPragraphOffset always correctly corresponds to _lastParagraphOffset
146
uint _lastParagraphOffset;
148
/* We save the last selection positions. This is needed when a tag is inserted to get the
149
left cursor position of the originally used selection */
150
int _lastSelectionStart;
151
int _lastSelectionEnd;
153
/* flag to skip any work on updating, since it will be more changes */
157
virtual void insert ( const QString & text, bool indent = FALSE, bool checkNewLine = TRUE, bool removeSelected = TRUE );
158
virtual void emitCursorPosition();
161
void signalUndoCmd(KBabel::EditCommand*);
162
void signalSyntaxHighlightingChanged (bool enable);
173
class MsgMultiLineEdit : public MyMultiLineEdit
177
enum TextColor { NormalColor, ErrorColor };
179
MsgMultiLineEdit(int ID, KSpell* spell=0, QWidget* parent=0,const char* name=0);
180
virtual ~MsgMultiLineEdit();
182
/** is displaying surrounding quotes enabled? */
183
bool quotes() const { return _quotes;}
184
/** enable or disable displaying of surrounding quotes */
185
void setQuotes(bool on);
187
/** is clever editing enabled? */
188
bool cleverEditing() const { return _cleverEditing; }
189
/** enable or disable clever editing */
190
void setCleverEditing(bool on);
191
/** is highlighting background enabled? */
192
bool highlightBg() const { return _highlightBg; }
193
/** enable or disable highlighting background*/
194
void setHighlightBg(bool on);
195
QColor bgColor() const { return _bgColor; }
196
void setBgColor(const QColor& color);
198
bool spacePoints() const { return _spacePoints; }
199
void setSpacePoints(bool on);
201
bool highlightSyntax() const { return _hlSyntax; }
203
void setHighlightSyntax(bool on);
204
void setHighlightColors(const QColor& quoteColor, const QColor& unquoteColor
205
, const QColor& cformatColor, const QColor& accelColor, const QColor& tagColor);
207
void setFont(const QFont& font);
209
void setDiffMode(bool on);
210
void setDiffDisplayMode(bool underlineAdded, bool strikeOutDeleted);
211
void setDiffColors(const QColor& addColor, const QColor& delColor);
213
void setTextColor(const QColor &color);
214
void setErrorColor(const QColor &color);
216
void setCurrentColor(const TextColor color);
218
void setSpellChecker(KSpell* spell);
220
void selectTag(int start, int length);
223
virtual void setText(const QString& s);
224
void paintSpacePoints();
225
void paintSpacePoints( int para, int pos ); // overloaded for signal QTextEdit::cursorPositionChanged
228
* reimplemented to call highlight()
232
void emittedTextChanged();
235
* reimplemented to skip in case of disabled updates
237
void ensureCursorVisible();
240
virtual void paintEvent (QPaintEvent * event );
241
virtual void drawContents( QPainter *painter, int clipx, int clipy, int clipw, int cliph );
243
virtual void keyPressEvent(QKeyEvent*);
244
virtual void keyReleaseEvent(QKeyEvent*);
248
* Computes the pixel position in line which corresponds to
249
* character position xIndex
251
QRect mapToView( int para, int index );
254
* tests if the character in string str at position col is masked with
255
* '\' by counting the number of '\' backwards
257
static bool isMasked(QString *str,uint col);
267
QColor _currentColor;
269
QPixmap* _whitespace;
270
QPixmap* _whitespaceNB;
271
QPixmap* _errorWhitespace;
272
QPixmap* _errorWhitespaceNB;
279
QColor _unquoteColor;
280
QColor _cformatColor;
291
QPtrVector< QValueList<DiffInfo> > diffPos;
293
bool _diffUnderlineAdd;
294
bool _diffStrikeOutDel;
295
QColor _diffAddColor;
296
QColor _diffDelColor;
298
// for Alt+123 feature
299
int _currentUnicodeNumber;
301
KBabelHighlighter * highlighter;
303
// next tag highlighting
304
int _tagStartPara, _tagStartIndex, _tagEndPara, _tagEndIndex;
307
#endif // MYMULTILINEEDIT_H