~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to kbabel/kbabel/mymultilineedit.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ****************************************************************************
2
 
  This file is part of KBabel
3
 
 
4
 
  Copyright (C) 1999-2000 by Matthias Kiefer
5
 
                            <matthias.kiefer@gmx.de>
6
 
                2001-2003 by Stanislav Visnovsky
7
 
                            <visnovsky@kde.org>
8
 
 
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.
13
 
 
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.
18
 
 
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.
22
 
 
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
32
 
  your version.
33
 
 
34
 
**************************************************************************** */
35
 
#ifndef MYMULTILINEEDIT_H
36
 
#define MYMULTILINEEDIT_H
37
 
 
38
 
#include <ktextedit.h>
39
 
#include <qptrvector.h>
40
 
 
41
 
namespace KBabel
42
 
{
43
 
    class EditCommand;
44
 
}
45
 
 
46
 
class KBabelHighlighter;
47
 
class KSpell;
48
 
class QPixmap;
49
 
 
50
 
class MyMultiLineEdit : public KTextEdit
51
 
{
52
 
   Q_OBJECT
53
 
public:
54
 
   MyMultiLineEdit(int ID,QWidget* parent,const char* name=0);
55
 
 
56
 
   /**
57
 
      applies cmd to the displayed text, but does not emit
58
 
      signalUndoCommand
59
 
   */
60
 
   void processCommand(KBabel::EditCommand* cmd, bool undo=false);
61
 
 
62
 
   /** 
63
 
        * @returns the position in text, where the marked text begins
64
 
        * -1, if there is no marked text
65
 
        */
66
 
   int beginOfMarkedText();
67
 
 
68
 
    /** 
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
72
 
    */
73
 
   int beginOfLastMarkedText();
74
 
 
75
 
    /** 
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
79
 
    */
80
 
   int endOfLastMarkedText();
81
 
 
82
 
   virtual void insertAt ( const QString & s, int line, int col, bool mark = false );
83
 
   virtual void removeLine ( int line );
84
 
 
85
 
   int pos2Offset(uint paragraph, uint index);
86
 
   void offset2Pos(int offset, int &row, int &col) const;
87
 
   /** 
88
 
        * @returns the current position in text, where the cursor is
89
 
        */
90
 
 
91
 
   int currentIndex();
92
 
   /** 
93
 
   * processes Del key
94
 
   */
95
 
   void my_del();
96
 
   void my_backspace();
97
 
   
98
 
   /**
99
 
    * need to override deleting of popup menus :-(
100
 
    */
101
 
   void contentsContextMenuEvent( QContextMenuEvent *e );
102
 
   
103
 
   /**
104
 
    * need to reimplement overwrite mode :-(
105
 
    */
106
 
   bool isOverwriteMode() { return _overwrite; }    
107
 
 
108
 
public slots:
109
 
   
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);
117
 
 
118
 
   virtual void onSelectionChanged();
119
 
   
120
 
   /**
121
 
   reimplemented overwrite mode, since QTextEdit handles this internally and does
122
 
   not use any accessible virtual methods :-((.
123
 
   */
124
 
   virtual void setOverwriteMode(bool b);
125
 
 
126
 
protected:
127
 
 
128
 
   virtual void focusInEvent(QFocusEvent*);
129
 
   virtual QPopupMenu *createPopupMenu();
130
 
   virtual QPopupMenu *createPopupMenu(const QPoint &pos);
131
 
   
132
 
   /* the parent handles this */
133
 
   virtual void wheelEvent(QWheelEvent*);
134
 
 
135
 
   bool emitUndo;
136
 
 
137
 
   /* First and the last line of the last change. They are only approximate. Used for faster display
138
 
    * highlighting etc.
139
 
    */
140
 
   uint _firstChangedLine;
141
 
   uint _lastChangedLine;
142
 
   
143
 
   /* This is a cache. _lastPragraphOffset always correctly corresponds to _lastParagraphOffset
144
 
    */
145
 
   uint _lastParagraph;
146
 
   uint _lastParagraphOffset;
147
 
 
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;
152
 
 
153
 
   /* flag to skip any work on updating, since it will be more changes */
154
 
   bool _dontUpdate;
155
 
 
156
 
protected slots:
157
 
   virtual void insert ( const QString & text, bool indent = FALSE, bool checkNewLine = TRUE, bool removeSelected = TRUE );
158
 
   virtual void emitCursorPosition();
159
 
 
160
 
signals:
161
 
   void signalUndoCmd(KBabel::EditCommand*);
162
 
   void signalSyntaxHighlightingChanged (bool enable);
163
 
 
164
 
protected:
165
 
   int _myID;
166
 
   
167
 
private:
168
 
   QPopupMenu *_menu;
169
 
   bool _overwrite;
170
 
};
171
 
 
172
 
 
173
 
class MsgMultiLineEdit : public MyMultiLineEdit
174
 
{   
175
 
   Q_OBJECT
176
 
public:
177
 
   enum TextColor { NormalColor, ErrorColor };
178
 
 
179
 
   MsgMultiLineEdit(int ID, KSpell* spell=0, QWidget* parent=0,const char* name=0);
180
 
   virtual ~MsgMultiLineEdit();
181
 
 
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);
186
 
 
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);
197
 
 
198
 
   bool spacePoints() const { return _spacePoints; }
199
 
   void setSpacePoints(bool on);
200
 
 
201
 
   bool highlightSyntax() const { return _hlSyntax; }
202
 
   void highlight();
203
 
   void setHighlightSyntax(bool on);
204
 
   void setHighlightColors(const QColor& quoteColor, const QColor& unquoteColor
205
 
             , const QColor& cformatColor, const QColor& accelColor, const QColor& tagColor);
206
 
 
207
 
   void setFont(const QFont& font);
208
 
 
209
 
   void setDiffMode(bool on);
210
 
   void setDiffDisplayMode(bool underlineAdded, bool strikeOutDeleted);
211
 
   void setDiffColors(const QColor& addColor, const QColor& delColor);
212
 
   
213
 
   void setTextColor(const QColor &color);
214
 
   void setErrorColor(const QColor &color);
215
 
   
216
 
   void setCurrentColor(const TextColor color);
217
 
   
218
 
   void setSpellChecker(KSpell* spell);
219
 
   
220
 
   void selectTag(int start, int length);
221
 
   
222
 
public slots:
223
 
   virtual void setText(const QString& s);
224
 
   void paintSpacePoints();
225
 
   void paintSpacePoints( int para, int pos ); // overloaded for signal QTextEdit::cursorPositionChanged
226
 
 
227
 
   /**
228
 
   *  reimplemented to call highlight()
229
 
   */
230
 
   void repaint(); 
231
 
   void forceUpdate();
232
 
   void emittedTextChanged();
233
 
   
234
 
   /**
235
 
   * reimplemented to skip in case of disabled updates
236
 
   */
237
 
   void ensureCursorVisible();
238
 
   
239
 
protected:
240
 
   virtual void paintEvent (QPaintEvent * event );
241
 
   virtual void drawContents( QPainter *painter, int clipx, int clipy, int clipw, int cliph );
242
 
   
243
 
   virtual void keyPressEvent(QKeyEvent*);
244
 
   virtual void keyReleaseEvent(QKeyEvent*);
245
 
 
246
 
private:
247
 
   /**
248
 
   * Computes the pixel position in line which corresponds to
249
 
   * character position xIndex
250
 
   */
251
 
   QRect mapToView( int para, int index );
252
 
 
253
 
   /**
254
 
    * tests if the character in string str at position col is masked with
255
 
    * '\' by counting the number of '\' backwards
256
 
    */
257
 
   static bool isMasked(QString *str,uint col);
258
 
 
259
 
private:
260
 
   bool _quotes;
261
 
   bool _cleverEditing;
262
 
   bool _highlightBg;
263
 
   bool _spacePoints;
264
 
   QColor _bgColor;
265
 
   QColor _textColor;
266
 
   QColor _errorColor;
267
 
   QColor _currentColor;
268
 
   
269
 
   QPixmap* _whitespace;
270
 
   QPixmap* _whitespaceNB;
271
 
   QPixmap* _errorWhitespace;
272
 
   QPixmap* _errorWhitespaceNB;
273
 
   
274
 
   int _wsOffsetX;
275
 
   int _wsOffsetY;
276
 
 
277
 
   bool _hlSyntax;
278
 
   QColor _quoteColor;
279
 
   QColor _unquoteColor;
280
 
   QColor _cformatColor;
281
 
   QColor _accelColor;
282
 
   QColor _tagColor;
283
 
 
284
 
   struct DiffInfo
285
 
   {
286
 
       bool add;
287
 
       int begin;
288
 
       int end;
289
 
   };
290
 
 
291
 
   QPtrVector< QValueList<DiffInfo> > diffPos;
292
 
   bool _showDiff;
293
 
   bool _diffUnderlineAdd;
294
 
   bool _diffStrikeOutDel;
295
 
   QColor _diffAddColor;
296
 
   QColor _diffDelColor;
297
 
   
298
 
   // for Alt+123 feature
299
 
   int _currentUnicodeNumber;
300
 
   
301
 
   KBabelHighlighter * highlighter;
302
 
   
303
 
   // next tag highlighting
304
 
   int _tagStartPara, _tagStartIndex, _tagEndPara, _tagEndIndex;
305
 
};
306
 
 
307
 
#endif // MYMULTILINEEDIT_H