Diffstat (limited to 'noncore/apps/opie-write/qtextedit.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-write/qtextedit.h | 448 |
1 files changed, 448 insertions, 0 deletions
diff --git a/noncore/apps/opie-write/qtextedit.h b/noncore/apps/opie-write/qtextedit.h new file mode 100644 index 0000000..b4e5701 --- a/dev/null +++ b/noncore/apps/opie-write/qtextedit.h | |||
@@ -0,0 +1,448 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Definition of the QTextEdit class | ||
5 | ** | ||
6 | ** Created : 990101 | ||
7 | ** | ||
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | ||
9 | ** | ||
10 | ** This file is part of the widgets module of the Qt GUI Toolkit. | ||
11 | ** | ||
12 | ** This file may be distributed under the terms of the Q Public License | ||
13 | ** as defined by Trolltech AS of Norway and appearing in the file | ||
14 | ** LICENSE.QPL included in the packaging of this file. | ||
15 | ** | ||
16 | ** This file may be distributed and/or modified under the terms of the | ||
17 | ** GNU General Public License version 2 as published by the Free Software | ||
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
19 | ** packaging of this file. | ||
20 | ** | ||
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
22 | ** licenses may use this file in accordance with the Qt Commercial License | ||
23 | ** Agreement provided with the Software. | ||
24 | ** | ||
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
27 | ** | ||
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
29 | ** information about Qt Commercial License Agreements. | ||
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
32 | ** | ||
33 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
34 | ** not clear to you. | ||
35 | ** | ||
36 | **********************************************************************/ | ||
37 | |||
38 | #ifndef QTEXTEDIT_H | ||
39 | #define QTEXTEDIT_H | ||
40 | |||
41 | #ifndef QT_H | ||
42 | #include "qscrollview.h" | ||
43 | #include "qstylesheet.h" | ||
44 | #include "qvector.h" | ||
45 | #include "qvaluelist.h" | ||
46 | #endif // QT_H | ||
47 | |||
48 | class QPainter; | ||
49 | class QKeyEvent; | ||
50 | class QResizeEvent; | ||
51 | class QMouseEvent; | ||
52 | class QTimer; | ||
53 | class QFont; | ||
54 | class QColor; | ||
55 | struct QUndoRedoInfoPrivate; | ||
56 | class QPopupMenu; | ||
57 | |||
58 | namespace Qt3 { | ||
59 | |||
60 | class QTextString; | ||
61 | class QTextDocument; | ||
62 | class QTextCursor; | ||
63 | class QTextCommand; | ||
64 | class QTextParag; | ||
65 | class QTextFormat; | ||
66 | class QTextBrowser; | ||
67 | class QTextEditPrivate; | ||
68 | |||
69 | class Q_EXPORT QTextEdit : public QScrollView | ||
70 | { | ||
71 | friend class QTextBrowser; | ||
72 | |||
73 | Q_OBJECT | ||
74 | Q_ENUMS( WordWrap WrapPolicy ) | ||
75 | Q_PROPERTY( TextFormat textFormat READ textFormat WRITE setTextFormat ) | ||
76 | Q_PROPERTY( QString text READ text WRITE setText ) | ||
77 | Q_PROPERTY( QBrush paper READ paper WRITE setPaper ) | ||
78 | Q_PROPERTY( bool linkUnderline READ linkUnderline WRITE setLinkUnderline ) | ||
79 | Q_PROPERTY( QString documentTitle READ documentTitle ) | ||
80 | Q_PROPERTY( int length READ length ) | ||
81 | Q_PROPERTY( WordWrap wordWrap READ wordWrap WRITE setWordWrap ) | ||
82 | Q_PROPERTY( int wrapColumnOrWidth READ wrapColumnOrWidth WRITE setWrapColumnOrWidth ) | ||
83 | Q_PROPERTY( WrapPolicy wrapPolicy READ wrapPolicy WRITE setWrapPolicy ) | ||
84 | Q_PROPERTY( bool hasSelectedText READ hasSelectedText ) | ||
85 | Q_PROPERTY( QString selectedText READ selectedText ) | ||
86 | Q_PROPERTY( int undoDepth READ undoDepth WRITE setUndoDepth ) | ||
87 | Q_PROPERTY( bool overwriteMode READ isOverwriteMode WRITE setOverwriteMode ) | ||
88 | Q_PROPERTY( bool modified READ isModified WRITE setModified DESIGNABLE false ) | ||
89 | Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly ) | ||
90 | Q_PROPERTY( bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled ) | ||
91 | Q_PROPERTY( int tabStopWidth READ tabStopWidth WRITE setTabStopWidth ) | ||
92 | |||
93 | public: | ||
94 | enum WordWrap { | ||
95 | NoWrap, | ||
96 | WidgetWidth, | ||
97 | FixedPixelWidth, | ||
98 | FixedColumnWidth | ||
99 | }; | ||
100 | |||
101 | enum WrapPolicy { | ||
102 | AtWordBoundary, | ||
103 | Anywhere, | ||
104 | AtWhiteSpace = AtWordBoundary // deprecated, don't use | ||
105 | }; | ||
106 | |||
107 | enum KeyboardAction { | ||
108 | ActionBackspace, | ||
109 | ActionDelete, | ||
110 | ActionReturn, | ||
111 | ActionKill | ||
112 | }; | ||
113 | |||
114 | enum CursorAction { | ||
115 | MoveBackward, | ||
116 | MoveForward, | ||
117 | MoveWordBackward, | ||
118 | MoveWordForward, | ||
119 | MoveUp, | ||
120 | MoveDown, | ||
121 | MoveLineStart, | ||
122 | MoveLineEnd, | ||
123 | MoveHome, | ||
124 | MoveEnd, | ||
125 | MovePgUp, | ||
126 | MovePgDown | ||
127 | }; | ||
128 | |||
129 | enum VerticalAlignment { | ||
130 | AlignNormal, | ||
131 | AlignSuperScript, | ||
132 | AlignSubScript | ||
133 | }; | ||
134 | |||
135 | QTextEdit( const QString& text, const QString& context = QString::null, | ||
136 | QWidget* parent=0, const char* name=0); | ||
137 | QTextEdit( QWidget* parent=0, const char* name=0 ); | ||
138 | virtual ~QTextEdit(); | ||
139 | void setPalette( const QPalette & ); | ||
140 | |||
141 | QString text() const; | ||
142 | QString text( int para ) const; | ||
143 | TextFormat textFormat() const; | ||
144 | QString context() const; | ||
145 | QString documentTitle() const; | ||
146 | |||
147 | void getSelection( int *paraFrom, int *indexFrom, | ||
148 | int *paraTo, int *indexTo, int selNum = 0 ) const; | ||
149 | virtual bool find( const QString &expr, bool cs, bool wo, bool forward = TRUE, | ||
150 | int *para = 0, int *index = 0 ); | ||
151 | |||
152 | int paragraphs() const; | ||
153 | int lines() const; | ||
154 | int linesOfParagraph( int para ) const; | ||
155 | int lineOfChar( int para, int chr ); | ||
156 | int length() const; | ||
157 | QRect paragraphRect( int para ) const; | ||
158 | int paragraphAt( const QPoint &pos ) const; | ||
159 | int charAt( const QPoint &pos, int *para ) const; | ||
160 | int paragraphLength( int para ) const; | ||
161 | |||
162 | QStyleSheet* styleSheet() const; | ||
163 | QMimeSourceFactory* mimeSourceFactory() const; | ||
164 | |||
165 | QBrush paper() const; | ||
166 | bool linkUnderline() const; | ||
167 | |||
168 | int heightForWidth( int w ) const; | ||
169 | |||
170 | bool hasSelectedText() const; | ||
171 | QString selectedText() const; | ||
172 | bool isUndoAvailable() const; | ||
173 | bool isRedoAvailable() const; | ||
174 | |||
175 | WordWrap wordWrap() const; | ||
176 | int wrapColumnOrWidth() const; | ||
177 | WrapPolicy wrapPolicy() const; | ||
178 | |||
179 | int tabStopWidth() const; | ||
180 | |||
181 | QString anchorAt( const QPoint& pos ); | ||
182 | |||
183 | QSize sizeHint() const; | ||
184 | |||
185 | bool isReadOnly() const { return readonly; } | ||
186 | |||
187 | void getCursorPosition( int *parag, int *index ) const; | ||
188 | |||
189 | bool isModified() const; | ||
190 | bool italic() const; | ||
191 | bool bold() const; | ||
192 | bool underline() const; | ||
193 | QString family() const; | ||
194 | int pointSize() const; | ||
195 | QColor color() const; | ||
196 | QFont font() const; | ||
197 | int alignment() const; | ||
198 | int undoDepth() const; | ||
199 | virtual bool getFormat( int para, int index, QFont *font, QColor *color, VerticalAlignment *verticalAlignment ); | ||
200 | virtual bool getParagraphFormat( int para, QFont *font, QColor *color, | ||
201 | VerticalAlignment *verticalAlignment, int *alignment, | ||
202 | QStyleSheetItem::DisplayMode *displayMode, | ||
203 | QStyleSheetItem::ListStyle *listStyle, | ||
204 | int *listDepth ); | ||
205 | bool isOverwriteMode() const { return overWrite; } | ||
206 | QColor paragraphBackgroundColor( int para ) const; | ||
207 | |||
208 | bool isUndoRedoEnabled() const; | ||
209 | bool eventFilter( QObject *o, QEvent *e ); | ||
210 | |||
211 | public slots: | ||
212 | void setEnabled( bool ); | ||
213 | virtual void setMimeSourceFactory( QMimeSourceFactory* factory ); | ||
214 | virtual void setStyleSheet( QStyleSheet* styleSheet ); | ||
215 | virtual void scrollToAnchor( const QString& name ); | ||
216 | virtual void setPaper( const QBrush& pap ); | ||
217 | virtual void setLinkUnderline( bool ); | ||
218 | |||
219 | virtual void setWordWrap( WordWrap mode ); | ||
220 | virtual void setWrapColumnOrWidth( int ); | ||
221 | virtual void setWrapPolicy( WrapPolicy policy ); | ||
222 | |||
223 | virtual void copy(); | ||
224 | virtual void append( const QString& text ); | ||
225 | |||
226 | void setText( const QString &txt ) { setText( txt, QString::null ); } | ||
227 | virtual void setText( const QString &txt, const QString &context ); | ||
228 | virtual void setTextFormat( TextFormat f ); | ||
229 | |||
230 | virtual void selectAll( bool select = TRUE ); | ||
231 | virtual void setTabStopWidth( int ts ); | ||
232 | virtual void zoomIn( int range ); | ||
233 | virtual void zoomIn() { zoomIn( 1 ); } | ||
234 | virtual void zoomOut( int range ); | ||
235 | virtual void zoomOut() { zoomOut( 1 ); } | ||
236 | virtual void zoomTo( int size ); | ||
237 | |||
238 | virtual void sync(); | ||
239 | virtual void setReadOnly( bool b ); | ||
240 | |||
241 | virtual void undo(); | ||
242 | virtual void redo(); | ||
243 | virtual void cut(); | ||
244 | virtual void paste(); | ||
245 | #ifndef QT_NO_CLIPBOARD | ||
246 | virtual void pasteSubType( const QCString &subtype ); | ||
247 | #endif | ||
248 | virtual void clear(); | ||
249 | virtual void del(); | ||
250 | virtual void indent(); | ||
251 | virtual void setItalic( bool b ); | ||
252 | virtual void setBold( bool b ); | ||
253 | virtual void setUnderline( bool b ); | ||
254 | virtual void setFamily( const QString &f ); | ||
255 | virtual void setPointSize( int s ); | ||
256 | virtual void setColor( const QColor &c ); | ||
257 | virtual void setFont( const QFont &f ); | ||
258 | virtual void setVerticalAlignment( VerticalAlignment a ); | ||
259 | virtual void setAlignment( int a ); | ||
260 | virtual void setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::ListStyle listStyle ); | ||
261 | virtual void setCursorPosition( int parag, int index ); | ||
262 | virtual void setSelection( int parag_from, int index_from, int parag_to, int index_to, int selNum = 0 ); | ||
263 | virtual void setSelectionAttributes( int selNum, const QColor &back, bool invertText ); | ||
264 | virtual void setModified( bool m ); | ||
265 | virtual void resetFormat(); | ||
266 | virtual void setUndoDepth( int d ); | ||
267 | virtual void setFormat( QTextFormat *f, int flags ); | ||
268 | virtual void ensureCursorVisible(); | ||
269 | virtual void placeCursor( const QPoint &pos, QTextCursor *c = 0 ); | ||
270 | virtual void moveCursor( CursorAction action, bool select ); | ||
271 | virtual void doKeyboardAction( KeyboardAction action ); | ||
272 | virtual void removeSelectedText( int selNum = 0 ); | ||
273 | virtual void removeSelection( int selNum = 0 ); | ||
274 | virtual void setCurrentFont( const QFont &f ); | ||
275 | virtual void setOverwriteMode( bool b ) { overWrite = b; } | ||
276 | |||
277 | virtual void scrollToBottom(); | ||
278 | |||
279 | virtual void insert( const QString &text, bool indent, bool checkNewLine, bool removeSelected ); | ||
280 | virtual void insertAt( const QString &text, int para, int index ); | ||
281 | virtual void removeParagraph( int para ); | ||
282 | virtual void insertParagraph( const QString &text, int para ); | ||
283 | |||
284 | virtual void setParagraphBackgroundColor( int para, const QColor &bg ); | ||
285 | virtual void clearParagraphBackground( int para ); | ||
286 | |||
287 | virtual void setUndoRedoEnabled( bool b ); | ||
288 | |||
289 | signals: | ||
290 | void textChanged(); | ||
291 | void selectionChanged(); | ||
292 | void copyAvailable( bool ); | ||
293 | void undoAvailable( bool yes ); | ||
294 | void redoAvailable( bool yes ); | ||
295 | void currentFontChanged( const QFont &f ); | ||
296 | void currentColorChanged( const QColor &c ); | ||
297 | void currentAlignmentChanged( int a ); | ||
298 | void currentVerticalAlignmentChanged( VerticalAlignment a ); | ||
299 | void cursorPositionChanged( QTextCursor *c ); | ||
300 | void cursorPositionChanged( int para, int pos ); | ||
301 | void returnPressed(); | ||
302 | void modificationChanged( bool m ); | ||
303 | |||
304 | protected: | ||
305 | void repaintChanged(); | ||
306 | void updateStyles(); | ||
307 | void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); | ||
308 | bool event( QEvent *e ); | ||
309 | void keyPressEvent( QKeyEvent *e ); | ||
310 | void resizeEvent( QResizeEvent *e ); | ||
311 | void viewportResizeEvent( QResizeEvent* ); | ||
312 | void contentsMousePressEvent( QMouseEvent *e ); | ||
313 | void contentsMouseMoveEvent( QMouseEvent *e ); | ||
314 | void contentsMouseReleaseEvent( QMouseEvent *e ); | ||
315 | void contentsMouseDoubleClickEvent( QMouseEvent *e ); | ||
316 | #ifndef QT_NO_WHEELEVENT | ||
317 | void contentsWheelEvent( QWheelEvent *e ); | ||
318 | #endif | ||
319 | #ifndef QT_NO_DRAGANDDROP | ||
320 | void contentsDragEnterEvent( QDragEnterEvent *e ); | ||
321 | void contentsDragMoveEvent( QDragMoveEvent *e ); | ||
322 | void contentsDragLeaveEvent( QDragLeaveEvent *e ); | ||
323 | void contentsDropEvent( QDropEvent *e ); | ||
324 | #endif | ||
325 | bool focusNextPrevChild( bool next ); | ||
326 | QTextDocument *document() const; | ||
327 | QTextCursor *textCursor() const; | ||
328 | void setDocument( QTextDocument *doc ); | ||
329 | virtual QPopupMenu *createPopupMenu( const QPoint& pos ); | ||
330 | virtual QPopupMenu *createPopupMenu(); | ||
331 | void drawCursor( bool visible ); | ||
332 | |||
333 | void windowActivationChange( bool ); | ||
334 | |||
335 | protected slots: | ||
336 | virtual void doChangeInterval(); | ||
337 | |||
338 | private slots: | ||
339 | void formatMore(); | ||
340 | void doResize(); | ||
341 | void autoScrollTimerDone(); | ||
342 | void blinkCursor(); | ||
343 | void setModified(); | ||
344 | void startDrag(); | ||
345 | void documentWidthChanged( int w ); | ||
346 | |||
347 | private: | ||
348 | struct Q_EXPORT UndoRedoInfo { | ||
349 | enum Type { Invalid, Insert, Delete, Backspace, Return, RemoveSelected, Format, Alignment, ParagType }; | ||
350 | |||
351 | UndoRedoInfo( QTextDocument *dc ); | ||
352 | ~UndoRedoInfo(); | ||
353 | void clear(); | ||
354 | bool valid() const; | ||
355 | |||
356 | QUndoRedoInfoPrivate *d; | ||
357 | int id; | ||
358 | int index; | ||
359 | int eid; | ||
360 | int eindex; | ||
361 | QTextFormat *format; | ||
362 | int flags; | ||
363 | Type type; | ||
364 | QTextDocument *doc; | ||
365 | QMemArray<int> oldAligns; | ||
366 | int newAlign; | ||
367 | bool list; | ||
368 | QStyleSheetItem::ListStyle listStyle; | ||
369 | QValueList< QPtrVector<QStyleSheetItem> > oldStyles; | ||
370 | QValueList<QStyleSheetItem::ListStyle> oldListStyles; | ||
371 | }; | ||
372 | |||
373 | private: | ||
374 | void updateCursor( const QPoint & pos ); | ||
375 | void handleMouseMove( const QPoint& pos ); | ||
376 | void drawContents( QPainter * ); | ||
377 | virtual bool linksEnabled() const { return FALSE; } | ||
378 | void init(); | ||
379 | void checkUndoRedoInfo( UndoRedoInfo::Type t ); | ||
380 | void updateCurrentFormat(); | ||
381 | bool handleReadOnlyKeyEvent( QKeyEvent *e ); | ||
382 | void makeParagVisible( QTextParag *p ); | ||
383 | #ifndef QT_NO_MIME | ||
384 | QCString pickSpecial(QMimeSource* ms, bool always_ask, const QPoint&); | ||
385 | #endif | ||
386 | #ifndef QT_NO_MIMECLIPBOARD | ||
387 | void pasteSpecial(const QPoint&); | ||
388 | #endif | ||
389 | void setFontInternal( const QFont &f ); | ||
390 | |||
391 | virtual void emitHighlighted( const QString & ) {} | ||
392 | virtual void emitLinkClicked( const QString & ) {} | ||
393 | |||
394 | void readFormats( QTextCursor &c1, QTextCursor &c2, int oldLen, QTextString &text, bool fillStyles = FALSE ); | ||
395 | void clearUndoRedo(); | ||
396 | void paintDocument( bool drawAll, QPainter *p, int cx = -1, int cy = -1, int cw = -1, int ch = -1 ); | ||
397 | void moveCursor( CursorAction action ); | ||
398 | void ensureFormatted( QTextParag *p ); | ||
399 | void placeCursor( const QPoint &pos, QTextCursor *c, bool link ); | ||
400 | |||
401 | private: | ||
402 | QTextDocument *doc; | ||
403 | QTextCursor *cursor; | ||
404 | QTimer *formatTimer, *scrollTimer, *changeIntervalTimer, *blinkTimer, *dragStartTimer; | ||
405 | QTextParag *lastFormatted; | ||
406 | int interval; | ||
407 | UndoRedoInfo undoRedoInfo; | ||
408 | QTextFormat *currentFormat; | ||
409 | int currentAlignment; | ||
410 | QPoint oldMousePos, mousePos; | ||
411 | QPoint dragStartPos; | ||
412 | QString onLink; | ||
413 | WordWrap wrapMode; | ||
414 | WrapPolicy wPolicy; | ||
415 | int wrapWidth; | ||
416 | QString pressedLink; | ||
417 | QTextEditPrivate *d; | ||
418 | bool inDoubleClick : 1; | ||
419 | bool mousePressed : 1; | ||
420 | bool cursorVisible : 1; | ||
421 | bool blinkCursorVisible : 1; | ||
422 | bool readOnly : 1; | ||
423 | bool modified : 1; | ||
424 | bool mightStartDrag : 1; | ||
425 | bool inDnD : 1; | ||
426 | bool readonly : 1; | ||
427 | bool undoEnabled : 1; | ||
428 | bool overWrite : 1; | ||
429 | }; | ||
430 | |||
431 | inline QTextDocument *QTextEdit::document() const | ||
432 | { | ||
433 | return doc; | ||
434 | } | ||
435 | |||
436 | inline QTextCursor *QTextEdit::textCursor() const | ||
437 | { | ||
438 | return cursor; | ||
439 | } | ||
440 | |||
441 | inline void QTextEdit::setCurrentFont( const QFont &f ) | ||
442 | { | ||
443 | QTextEdit::setFontInternal( f ); | ||
444 | } | ||
445 | |||
446 | } | ||
447 | |||
448 | #endif //QTEXTVIEW_H | ||