summaryrefslogtreecommitdiff
path: root/core/apps/textedit/qtextedit.h
Unidiff
Diffstat (limited to 'core/apps/textedit/qtextedit.h') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/qtextedit.h282
1 files changed, 282 insertions, 0 deletions
diff --git a/core/apps/textedit/qtextedit.h b/core/apps/textedit/qtextedit.h
new file mode 100644
index 0000000..b29a728
--- a/dev/null
+++ b/core/apps/textedit/qtextedit.h
@@ -0,0 +1,282 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef QTEXTEDIT_H
22#define QTEXTEDIT_H
23
24#include <qscrollview.h>
25#include <qstylesheet.h>
26#include <qpainter.h>
27
28class QPainter;
29class QTextDocument;
30class QTextCursor;
31class QKeyEvent;
32class QResizeEvent;
33class QMouseEvent;
34class QTimer;
35class QTextString;
36class QVBox;
37class QListBox;
38class QTextCommand;
39class QTextParag;
40class QTextFormat;
41class QFont;
42class QColor;
43
44class QTextEdit : public QScrollView
45{
46 Q_OBJECT
47
48public:
49 QTextEdit( QWidget *parent, const QString &fn, bool tabify = FALSE );
50 QTextEdit( QWidget *parent = 0, const char *name = 0 );
51 virtual ~QTextEdit();
52
53#if defined(QTEXTEDIT_OPEN_API)
54 QTextDocument *document() const;
55 QTextCursor *textCursor() const;
56#endif
57
58 QString text() const;
59 QString text( int parag, bool formatted = FALSE ) const;
60 Qt::TextFormat textFormat() const;
61 QString fileName() const;
62
63 void cursorPosition( int &parag, int &index );
64 void selection( int &parag_from, int &index_from,
65 int &parag_to, int &index_to );
66 virtual bool find( const QString &expr, bool cs, bool wo, bool forward = TRUE,
67 int *parag = 0, int *index = 0 );
68 void insert( const QString &text, bool indent = FALSE, bool checkNewLine = FALSE );
69
70 int paragraphs() const;
71 int lines() const;
72 int linesOfParagraph( int parag ) const;
73 int lineOfChar( int parag, int chr );
74
75 bool isModified() const;
76
77 bool italic() const;
78 bool bold() const;
79 bool underline() const;
80 QString family() const;
81 int pointSize() const;
82 QColor color() const;
83 QFont font() const;
84 int alignment() const;
85 int maxLines() const;
86
87 const QStyleSheet* styleSheet() const;
88 void setStyleSheet( const QStyleSheet* styleSheet );
89
90 void setPaper( const QBrush& pap);
91 QBrush paper() const;
92
93 void setLinkColor( const QColor& );
94 QColor linkColor() const;
95
96 void setLinkUnderline( bool );
97 bool linkUnderline() const;
98
99 void setMimeSourceFactory( const QMimeSourceFactory* factory );
100 const QMimeSourceFactory* mimeSourceFactory() const;
101
102 int heightForWidth( int w ) const;
103
104 void append( const QString& text );
105
106 bool hasSelectedText() const;
107 QString selectedText() const;
108
109 QString context() const;
110
111 QString documentTitle() const;
112
113 void scrollToAnchor( const QString& name );
114 QString anchorAt(const QPoint& pos);
115
116public slots:
117 virtual void undo();
118 virtual void redo();
119
120 virtual void cut();
121 virtual void copy();
122 virtual void paste();
123
124 virtual void indent();
125
126 virtual void setItalic( bool b );
127 virtual void setBold( bool b );
128 virtual void setUnderline( bool b );
129 virtual void setFamily( const QString &f );
130 virtual void setPointSize( int s );
131 virtual void setColor( const QColor &c );
132 virtual void setFont( const QFont &f );
133
134 virtual void setAlignment( int );
135
136 virtual void setParagType( QStyleSheetItem::DisplayMode, int listStyle );
137
138 virtual void setTextFormat( Qt::TextFormat f );
139 virtual void setText( const QString &txt, const QString &context = QString::null ) { setText( txt, context, FALSE ); }
140 virtual void setText( const QString &txt, const QString &context, bool tabify );
141
142 virtual void load( const QString &fn ) { load( fn, FALSE ); }
143 virtual void load( const QString &fn, bool tabify );
144 virtual void save( bool untabify = FALSE ) { save( QString::null, untabify ); }
145 virtual void save( const QString &fn, bool untabify = FALSE );
146
147 virtual void setCursorPosition( int parag, int index );
148 virtual void setSelection( int parag_from, int index_from,
149 int parag_to, int index_to );
150
151 virtual void setModified( bool m );
152 virtual void selectAll( bool select );
153
154 virtual void setMaxLines( int l );
155 virtual void resetFormat();
156
157signals:
158 void currentFontChanged( const QFont &f );
159 void currentColorChanged( const QColor &c );
160 void currentAlignmentChanged( int );
161 void textChanged();
162 void highlighted( const QString& );
163 void linkClicked( const QString& );
164
165protected:
166 void setFormat( QTextFormat *f, int flags );
167 void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
168 void keyPressEvent( QKeyEvent *e );
169 void resizeEvent( QResizeEvent *e );
170 void contentsMousePressEvent( QMouseEvent *e );
171 void contentsMouseMoveEvent( QMouseEvent *e );
172 void contentsMouseReleaseEvent( QMouseEvent *e );
173 void contentsMouseDoubleClickEvent( QMouseEvent *e );
174#ifndef QT_NO_DRAGANDDROP
175 void contentsDragEnterEvent( QDragEnterEvent *e );
176 void contentsDragMoveEvent( QDragMoveEvent *e );
177 void contentsDragLeaveEvent( QDragLeaveEvent *e );
178 void contentsDropEvent( QDropEvent *e );
179#endif
180 bool eventFilter( QObject *o, QEvent *e );
181 bool focusNextPrevChild( bool next );
182#if !defined(QTEXTEDIT_OPEN_API)
183 QTextDocument *document() const;
184 QTextCursor *textCursor() const;
185#endif
186
187private slots:
188 void formatMore();
189 void doResize();
190 void doAutoScroll();
191 void doChangeInterval();
192 void blinkCursor();
193 void setModified();
194 void startDrag();
195
196private:
197 enum MoveDirection {
198 MoveLeft,
199 MoveRight,
200 MoveUp,
201 MoveDown,
202 MoveHome,
203 MoveEnd,
204 MovePgUp,
205 MovePgDown
206 };
207 enum KeyboardAction {
208 ActionBackspace,
209 ActionDelete,
210 ActionReturn
211 };
212
213 struct UndoRedoInfo {
214 enum Type { Invalid, Insert, Delete, Backspace, Return, RemoveSelected };
215 UndoRedoInfo( QTextDocument *d ) : type( Invalid ), doc( d )
216 { text = QString::null; id = -1; index = -1; }
217 void clear();
218 inline bool valid() const { return !text.isEmpty() && id >= 0&& index >= 0; }
219
220 QString text;
221 int id;
222 int index;
223 Type type;
224 QTextDocument *doc;
225 };
226
227private:
228 virtual bool isReadOnly() const { return FALSE; }
229 virtual bool linksEnabled() const { return TRUE; }
230 void init();
231 void ensureCursorVisible();
232 void drawCursor( bool visible );
233 void placeCursor( const QPoint &pos, QTextCursor *c = 0 );
234 void moveCursor( int direction, bool shift, bool control );
235 void moveCursor( int direction, bool control );
236 void removeSelectedText();
237 void doKeyboardAction( int action );
238 bool doCompletion();
239 void checkUndoRedoInfo( UndoRedoInfo::Type t );
240 void repaintChanged();
241 void updateCurrentFormat();
242 void handleReadOnlyKeyEvent( QKeyEvent *e );
243 void makeParagVisible( QTextParag *p );
244
245private:
246 QTextDocument *doc;
247 QTextCursor *cursor;
248 bool drawAll;
249 bool mousePressed;
250 QTimer *formatTimer, *scrollTimer, *changeIntervalTimer, *blinkTimer, *dragStartTimer, *resizeTimer;
251 QTextParag *lastFormatted;
252 int interval;
253 QVBox *completionPopup;
254 QListBox *completionListBox;
255 int completionOffset;
256 UndoRedoInfo undoRedoInfo;
257 QTextFormat *currentFormat;
258 QPainter painter;
259 int currentAlignment;
260 bool inDoubleClick;
261 QPoint oldMousePos, mousePos;
262 QPixmap *buf_pixmap;
263 bool cursorVisible, blinkCursorVisible;
264 bool readOnly, modified, mightStartDrag;
265 QPoint dragStartPos;
266 int mLines;
267 bool firstResize;
268 QString onLink;
269
270};
271
272inline QTextDocument *QTextEdit::document() const
273{
274 return doc;
275}
276
277inline QTextCursor *QTextEdit::textCursor() const
278{
279 return cursor;
280}
281
282#endif