1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef Q3RICHTEXT_P_H
|
---|
43 | #define Q3RICHTEXT_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists for the convenience
|
---|
50 | // of a number of Qt sources files. This header file may change from
|
---|
51 | // version to version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "QtGui/qapplication.h"
|
---|
57 | #include "QtGui/qcolor.h"
|
---|
58 | #include "QtCore/qhash.h"
|
---|
59 | #include "QtGui/qfont.h"
|
---|
60 | #include "QtGui/qfontmetrics.h"
|
---|
61 | #include "QtGui/qlayout.h"
|
---|
62 | #include "QtCore/qmap.h"
|
---|
63 | #include "QtCore/qvector.h"
|
---|
64 | #include "QtCore/qstack.h"
|
---|
65 | #include "QtCore/qlist.h"
|
---|
66 | #include "QtCore/qobject.h"
|
---|
67 | #include "QtGui/qpainter.h"
|
---|
68 | #include "QtGui/qpixmap.h"
|
---|
69 | #include "QtCore/qrect.h"
|
---|
70 | #include "QtCore/qsize.h"
|
---|
71 | #include "QtCore/qstring.h"
|
---|
72 | #include "QtCore/qstringlist.h"
|
---|
73 | #include "Qt3Support/q3stylesheet.h"
|
---|
74 | #include "Qt3Support/q3mimefactory.h"
|
---|
75 |
|
---|
76 | QT_BEGIN_NAMESPACE
|
---|
77 |
|
---|
78 | #ifndef QT_NO_RICHTEXT
|
---|
79 |
|
---|
80 | class Q3TextDocument;
|
---|
81 | class Q3TextString;
|
---|
82 | class Q3TextPreProcessor;
|
---|
83 | class Q3TextFormat;
|
---|
84 | class Q3TextCursor;
|
---|
85 | class Q3TextParagraph;
|
---|
86 | class Q3TextFormatter;
|
---|
87 | class Q3TextIndent;
|
---|
88 | class Q3TextFormatCollection;
|
---|
89 | class Q3StyleSheetItem;
|
---|
90 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
91 | class Q3TextCustomItem;
|
---|
92 | #endif
|
---|
93 | class Q3TextFlow;
|
---|
94 | struct QBidiContext;
|
---|
95 |
|
---|
96 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
---|
97 |
|
---|
98 | class Q_COMPAT_EXPORT Q3TextStringChar
|
---|
99 | {
|
---|
100 | friend class Q3TextString;
|
---|
101 |
|
---|
102 | public:
|
---|
103 | // this is never called, initialize variables in Q3TextString::insert()!!!
|
---|
104 | Q3TextStringChar() : nobreak(false), lineStart(0), type(Regular) {p.format=0;}
|
---|
105 | ~Q3TextStringChar();
|
---|
106 |
|
---|
107 | struct CustomData
|
---|
108 | {
|
---|
109 | Q3TextFormat *format;
|
---|
110 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
111 | Q3TextCustomItem *custom;
|
---|
112 | #endif
|
---|
113 | QString anchorName;
|
---|
114 | QString anchorHref;
|
---|
115 | };
|
---|
116 | enum Type { Regular=0, Custom=1, Anchor=2, CustomAnchor=3 };
|
---|
117 |
|
---|
118 | QChar c;
|
---|
119 | // this is the same struct as in qtextengine_p.h. Don't change!
|
---|
120 | uchar softBreak :1; // Potential linebreak point
|
---|
121 | uchar whiteSpace :1; // A unicode whitespace character, except NBSP, ZWNBSP
|
---|
122 | uchar charStop :1; // Valid cursor position (for left/right arrow)
|
---|
123 | uchar nobreak :1;
|
---|
124 |
|
---|
125 | uchar lineStart : 1;
|
---|
126 | uchar /*Type*/ type : 2;
|
---|
127 | uchar bidiLevel :7;
|
---|
128 | uchar rightToLeft : 1;
|
---|
129 |
|
---|
130 | int x;
|
---|
131 | union {
|
---|
132 | Q3TextFormat* format;
|
---|
133 | CustomData* custom;
|
---|
134 | } p;
|
---|
135 |
|
---|
136 |
|
---|
137 | int height() const;
|
---|
138 | int ascent() const;
|
---|
139 | int descent() const;
|
---|
140 | bool isCustom() const { return (type & Custom) != 0; }
|
---|
141 | Q3TextFormat *format() const;
|
---|
142 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
143 | Q3TextCustomItem *customItem() const;
|
---|
144 | #endif
|
---|
145 | void setFormat(Q3TextFormat *f);
|
---|
146 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
147 | void setCustomItem(Q3TextCustomItem *i);
|
---|
148 | #endif
|
---|
149 |
|
---|
150 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
151 | void loseCustomItem();
|
---|
152 | #endif
|
---|
153 |
|
---|
154 |
|
---|
155 | bool isAnchor() const { return (type & Anchor) != 0; }
|
---|
156 | bool isLink() const { return isAnchor() && p.custom->anchorHref.count(); }
|
---|
157 | QString anchorName() const;
|
---|
158 | QString anchorHref() const;
|
---|
159 | void setAnchor(const QString& name, const QString& href);
|
---|
160 |
|
---|
161 | Q3TextStringChar(const Q3TextStringChar &) {
|
---|
162 | Q_ASSERT(false);
|
---|
163 | }
|
---|
164 | private:
|
---|
165 | Q3TextStringChar &operator=(const Q3TextStringChar &) {
|
---|
166 | //abort();
|
---|
167 | return *this;
|
---|
168 | }
|
---|
169 | friend class Q3TextParagraph;
|
---|
170 | };
|
---|
171 |
|
---|
172 | Q_DECLARE_TYPEINFO(Q3TextStringChar, Q_PRIMITIVE_TYPE);
|
---|
173 |
|
---|
174 | class Q_COMPAT_EXPORT Q3TextString
|
---|
175 | {
|
---|
176 | public:
|
---|
177 |
|
---|
178 | Q3TextString();
|
---|
179 | Q3TextString(const Q3TextString &s);
|
---|
180 | virtual ~Q3TextString();
|
---|
181 |
|
---|
182 | static QString toString(const QVector<Q3TextStringChar> &data);
|
---|
183 | QString toString() const;
|
---|
184 |
|
---|
185 | inline Q3TextStringChar &at(int i) const {
|
---|
186 | return const_cast<Q3TextString *>(this)->data[i];
|
---|
187 | }
|
---|
188 | inline int length() const { return data.size(); }
|
---|
189 |
|
---|
190 | int width(int idx) const;
|
---|
191 |
|
---|
192 | void insert(int index, const QString &s, Q3TextFormat *f);
|
---|
193 | void insert(int index, const QChar *unicode, int len, Q3TextFormat *f);
|
---|
194 | void insert(int index, Q3TextStringChar *c, bool doAddRefFormat = false);
|
---|
195 | void truncate(int index);
|
---|
196 | void remove(int index, int len);
|
---|
197 | void clear();
|
---|
198 |
|
---|
199 | void setFormat(int index, Q3TextFormat *f, bool useCollection);
|
---|
200 |
|
---|
201 | void setBidi(bool b) { bidi = b; }
|
---|
202 | bool isBidi() const;
|
---|
203 | bool isRightToLeft() const;
|
---|
204 | QChar::Direction direction() const;
|
---|
205 | void setDirection(QChar::Direction dr) { dir = dr; bidiDirty = true; }
|
---|
206 |
|
---|
207 | QVector<Q3TextStringChar> rawData() const { return data; }
|
---|
208 |
|
---|
209 | void operator=(const QString &s) { clear(); insert(0, s, 0); }
|
---|
210 | void operator+=(const QString &s) { insert(length(), s, 0); }
|
---|
211 | void prepend(const QString &s) { insert(0, s, 0); }
|
---|
212 | int appendParagraphs( Q3TextParagraph *start, Q3TextParagraph *end );
|
---|
213 |
|
---|
214 | // return next and previous valid cursor positions.
|
---|
215 | bool validCursorPosition(int idx);
|
---|
216 | int nextCursorPosition(int idx);
|
---|
217 | int previousCursorPosition(int idx);
|
---|
218 |
|
---|
219 | private:
|
---|
220 | void checkBidi() const;
|
---|
221 |
|
---|
222 | QVector<Q3TextStringChar> data;
|
---|
223 | QString stringCache;
|
---|
224 | uint bidiDirty : 1;
|
---|
225 | uint bidi : 1; // true when the paragraph has right to left characters
|
---|
226 | uint rightToLeft : 1;
|
---|
227 | uint dir : 5;
|
---|
228 | };
|
---|
229 |
|
---|
230 | inline bool Q3TextString::isBidi() const
|
---|
231 | {
|
---|
232 | if (bidiDirty)
|
---|
233 | checkBidi();
|
---|
234 | return bidi;
|
---|
235 | }
|
---|
236 |
|
---|
237 | inline bool Q3TextString::isRightToLeft() const
|
---|
238 | {
|
---|
239 | if (bidiDirty)
|
---|
240 | checkBidi();
|
---|
241 | return rightToLeft;
|
---|
242 | }
|
---|
243 |
|
---|
244 | inline QString Q3TextString::toString() const
|
---|
245 | {
|
---|
246 | if (bidiDirty)
|
---|
247 | checkBidi();
|
---|
248 | return stringCache;
|
---|
249 | }
|
---|
250 |
|
---|
251 | inline QChar::Direction Q3TextString::direction() const
|
---|
252 | {
|
---|
253 | return rightToLeft ? QChar::DirR : QChar::DirL;
|
---|
254 | }
|
---|
255 |
|
---|
256 | inline int Q3TextString::nextCursorPosition(int next)
|
---|
257 | {
|
---|
258 | if (bidiDirty)
|
---|
259 | checkBidi();
|
---|
260 |
|
---|
261 | const Q3TextStringChar *c = data.data();
|
---|
262 | int len = length();
|
---|
263 |
|
---|
264 | if (next < len - 1) {
|
---|
265 | next++;
|
---|
266 | while (next < len - 1 && !c[next].charStop)
|
---|
267 | next++;
|
---|
268 | }
|
---|
269 | return next;
|
---|
270 | }
|
---|
271 |
|
---|
272 | inline int Q3TextString::previousCursorPosition(int prev)
|
---|
273 | {
|
---|
274 | if (bidiDirty)
|
---|
275 | checkBidi();
|
---|
276 |
|
---|
277 | const Q3TextStringChar *c = data.data();
|
---|
278 |
|
---|
279 | if (prev) {
|
---|
280 | prev--;
|
---|
281 | while (prev && !c[prev].charStop)
|
---|
282 | prev--;
|
---|
283 | }
|
---|
284 | return prev;
|
---|
285 | }
|
---|
286 |
|
---|
287 | inline bool Q3TextString::validCursorPosition(int idx)
|
---|
288 | {
|
---|
289 | if (bidiDirty)
|
---|
290 | checkBidi();
|
---|
291 |
|
---|
292 | return (at(idx).charStop);
|
---|
293 | }
|
---|
294 |
|
---|
295 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
---|
296 |
|
---|
297 | class Q_COMPAT_EXPORT Q3TextCursor
|
---|
298 | {
|
---|
299 | public:
|
---|
300 | Q3TextCursor(Q3TextDocument * = 0);
|
---|
301 | Q3TextCursor(const Q3TextCursor &c);
|
---|
302 | Q3TextCursor &operator=(const Q3TextCursor &c);
|
---|
303 | virtual ~Q3TextCursor();
|
---|
304 |
|
---|
305 | bool operator==(const Q3TextCursor &c) const;
|
---|
306 | bool operator!=(const Q3TextCursor &c) const { return !(*this == c); }
|
---|
307 |
|
---|
308 | inline Q3TextParagraph *paragraph() const { return para; }
|
---|
309 |
|
---|
310 | Q3TextDocument *document() const;
|
---|
311 | int index() const;
|
---|
312 |
|
---|
313 | void gotoPosition(Q3TextParagraph* p, int index = 0);
|
---|
314 | void setIndex(int index) { gotoPosition(paragraph(), index); }
|
---|
315 | void setParagraph(Q3TextParagraph*p) { gotoPosition(p, 0); }
|
---|
316 |
|
---|
317 | void gotoLeft();
|
---|
318 | void gotoRight();
|
---|
319 | void gotoNextLetter();
|
---|
320 | void gotoPreviousLetter();
|
---|
321 | void gotoUp();
|
---|
322 | void gotoDown();
|
---|
323 | void gotoLineEnd();
|
---|
324 | void gotoLineStart();
|
---|
325 | void gotoHome();
|
---|
326 | void gotoEnd();
|
---|
327 | void gotoPageUp(int visibleHeight);
|
---|
328 | void gotoPageDown(int visibleHeight);
|
---|
329 | void gotoNextWord(bool onlySpace = false);
|
---|
330 | void gotoPreviousWord(bool onlySpace = false);
|
---|
331 | void gotoWordLeft();
|
---|
332 | void gotoWordRight();
|
---|
333 |
|
---|
334 | void insert(const QString &s, bool checkNewLine, QVector<Q3TextStringChar> *formatting = 0);
|
---|
335 | void splitAndInsertEmptyParagraph(bool ind = true, bool updateIds = true);
|
---|
336 | bool remove();
|
---|
337 | bool removePreviousChar();
|
---|
338 | void indent();
|
---|
339 |
|
---|
340 | bool atParagStart();
|
---|
341 | bool atParagEnd();
|
---|
342 |
|
---|
343 | int x() const; // x in current paragraph
|
---|
344 | int y() const; // y in current paragraph
|
---|
345 |
|
---|
346 | int globalX() const;
|
---|
347 | int globalY() const;
|
---|
348 |
|
---|
349 | Q3TextParagraph *topParagraph() const { return paras.isEmpty() ? para : paras.first(); }
|
---|
350 | int offsetX() const { return ox; } // inner document offset
|
---|
351 | int offsetY() const { return oy; } // inner document offset
|
---|
352 | int totalOffsetX() const; // total document offset
|
---|
353 | int totalOffsetY() const; // total document offset
|
---|
354 |
|
---|
355 | bool place(const QPoint &pos, Q3TextParagraph *s) { return place(pos, s, false); }
|
---|
356 | bool place(const QPoint &pos, Q3TextParagraph *s, bool link);
|
---|
357 | void restoreState();
|
---|
358 |
|
---|
359 |
|
---|
360 | int nestedDepth() const { return (int)indices.count(); } //### size_t/int cast
|
---|
361 | void oneUp() { if (!indices.isEmpty()) pop(); }
|
---|
362 | void setValid(bool b) { valid = b; }
|
---|
363 | bool isValid() const { return valid; }
|
---|
364 |
|
---|
365 | void fixCursorPosition();
|
---|
366 | private:
|
---|
367 | enum Operation { EnterBegin, EnterEnd, Next, Prev, Up, Down };
|
---|
368 |
|
---|
369 | void push();
|
---|
370 | void pop();
|
---|
371 | bool processNesting(Operation op);
|
---|
372 | void invalidateNested();
|
---|
373 | void gotoIntoNested(const QPoint &globalPos);
|
---|
374 |
|
---|
375 | Q3TextParagraph *para;
|
---|
376 | int idx, tmpX;
|
---|
377 | int ox, oy;
|
---|
378 | QStack<int> indices;
|
---|
379 | QStack<Q3TextParagraph*> paras;
|
---|
380 | QStack<int> xOffsets;
|
---|
381 | QStack<int> yOffsets;
|
---|
382 | uint valid : 1;
|
---|
383 |
|
---|
384 | };
|
---|
385 |
|
---|
386 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
---|
387 |
|
---|
388 | class Q_COMPAT_EXPORT Q3TextCommand
|
---|
389 | {
|
---|
390 | public:
|
---|
391 | enum Commands { Invalid, Insert, Delete, Format, Style };
|
---|
392 |
|
---|
393 | Q3TextCommand(Q3TextDocument *dc) : doc(dc), cursor(dc) {}
|
---|
394 | virtual ~Q3TextCommand();
|
---|
395 |
|
---|
396 | virtual Commands type() const;
|
---|
397 |
|
---|
398 | virtual Q3TextCursor *execute(Q3TextCursor *c) = 0;
|
---|
399 | virtual Q3TextCursor *unexecute(Q3TextCursor *c) = 0;
|
---|
400 |
|
---|
401 | protected:
|
---|
402 | Q3TextDocument *doc;
|
---|
403 | Q3TextCursor cursor;
|
---|
404 |
|
---|
405 | };
|
---|
406 |
|
---|
407 | class Q_COMPAT_EXPORT Q3TextCommandHistory
|
---|
408 | {
|
---|
409 | public:
|
---|
410 | Q3TextCommandHistory(int s) : current(-1), steps(s) { }
|
---|
411 | virtual ~Q3TextCommandHistory(); // ### why is it virtual?
|
---|
412 |
|
---|
413 | void clear();
|
---|
414 |
|
---|
415 | void addCommand(Q3TextCommand *cmd);
|
---|
416 | Q3TextCursor *undo(Q3TextCursor *c);
|
---|
417 | Q3TextCursor *redo(Q3TextCursor *c);
|
---|
418 |
|
---|
419 | bool isUndoAvailable();
|
---|
420 | bool isRedoAvailable();
|
---|
421 |
|
---|
422 | void setUndoDepth(int depth) { steps = depth; }
|
---|
423 | int undoDepth() const { return steps; }
|
---|
424 |
|
---|
425 | int historySize() const { return history.count(); }
|
---|
426 | int currentPosition() const { return current; }
|
---|
427 |
|
---|
428 | private:
|
---|
429 | QList<Q3TextCommand *> history;
|
---|
430 | int current, steps;
|
---|
431 | };
|
---|
432 |
|
---|
433 | inline Q3TextCommandHistory::~Q3TextCommandHistory()
|
---|
434 | {
|
---|
435 | clear();
|
---|
436 | }
|
---|
437 |
|
---|
438 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
---|
439 |
|
---|
440 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
441 | class Q_COMPAT_EXPORT Q3TextCustomItem
|
---|
442 | {
|
---|
443 | public:
|
---|
444 | Q3TextCustomItem(Q3TextDocument *p)
|
---|
445 | : xpos(0), ypos(-1), width(-1), height(0), parent(p)
|
---|
446 | {}
|
---|
447 | virtual ~Q3TextCustomItem();
|
---|
448 | virtual void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
|
---|
449 | const QPalette &pal, bool selected) = 0;
|
---|
450 |
|
---|
451 | virtual void adjustToPainter(QPainter*);
|
---|
452 |
|
---|
453 | enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
|
---|
454 | virtual Placement placement() const;
|
---|
455 | bool placeInline() { return placement() == PlaceInline; }
|
---|
456 |
|
---|
457 | virtual bool ownLine() const;
|
---|
458 | virtual void resize(int nwidth);
|
---|
459 | virtual void invalidate();
|
---|
460 | virtual int ascent() const { return height; }
|
---|
461 |
|
---|
462 | virtual bool isNested() const;
|
---|
463 | virtual int minimumWidth() const;
|
---|
464 |
|
---|
465 | virtual QString richText() const;
|
---|
466 |
|
---|
467 | int xpos; // used for floating items
|
---|
468 | int ypos; // used for floating items
|
---|
469 | int width;
|
---|
470 | int height;
|
---|
471 |
|
---|
472 | QRect geometry() const { return QRect(xpos, ypos, width, height); }
|
---|
473 |
|
---|
474 | virtual bool enter(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy, bool atEnd = false);
|
---|
475 | virtual bool enterAt(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy, const QPoint &);
|
---|
476 | virtual bool next(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
|
---|
477 | virtual bool prev(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
|
---|
478 | virtual bool down(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
|
---|
479 | virtual bool up(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
|
---|
480 |
|
---|
481 | void setParagraph(Q3TextParagraph *p) { parag = p; }
|
---|
482 | Q3TextParagraph *paragraph() const { return parag; }
|
---|
483 |
|
---|
484 | Q3TextDocument *parent;
|
---|
485 | Q3TextParagraph *parag;
|
---|
486 |
|
---|
487 | virtual void pageBreak(int y, Q3TextFlow* flow);
|
---|
488 | };
|
---|
489 | #endif
|
---|
490 |
|
---|
491 |
|
---|
492 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
493 | class Q_COMPAT_EXPORT Q3TextImage : public Q3TextCustomItem
|
---|
494 | {
|
---|
495 | public:
|
---|
496 | Q3TextImage(Q3TextDocument *p, const QMap<QString, QString> &attr, const QString& context,
|
---|
497 | Q3MimeSourceFactory &factory);
|
---|
498 | virtual ~Q3TextImage();
|
---|
499 |
|
---|
500 | Placement placement() const { return place; }
|
---|
501 | void adjustToPainter(QPainter*);
|
---|
502 | int minimumWidth() const { return width; }
|
---|
503 |
|
---|
504 | QString richText() const;
|
---|
505 |
|
---|
506 | void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
|
---|
507 | const QPalette &pal, bool selected);
|
---|
508 |
|
---|
509 | private:
|
---|
510 | QRegion* reg;
|
---|
511 | QPixmap pm;
|
---|
512 | Placement place;
|
---|
513 | int tmpwidth, tmpheight;
|
---|
514 | QMap<QString, QString> attributes;
|
---|
515 | QString imgId;
|
---|
516 |
|
---|
517 | };
|
---|
518 | #endif
|
---|
519 |
|
---|
520 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
521 | class Q_COMPAT_EXPORT Q3TextHorizontalLine : public Q3TextCustomItem
|
---|
522 | {
|
---|
523 | public:
|
---|
524 | Q3TextHorizontalLine(Q3TextDocument *p, const QMap<QString, QString> &attr, const QString& context,
|
---|
525 | Q3MimeSourceFactory &factory);
|
---|
526 | virtual ~Q3TextHorizontalLine();
|
---|
527 |
|
---|
528 | void adjustToPainter(QPainter*);
|
---|
529 | void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
|
---|
530 | const QPalette &pal, bool selected);
|
---|
531 | QString richText() const;
|
---|
532 |
|
---|
533 | bool ownLine() const { return true; }
|
---|
534 |
|
---|
535 | private:
|
---|
536 | int tmpheight;
|
---|
537 | QColor color;
|
---|
538 | bool shade;
|
---|
539 |
|
---|
540 | };
|
---|
541 | #endif
|
---|
542 |
|
---|
543 | class Q_COMPAT_EXPORT Q3TextFlow
|
---|
544 | {
|
---|
545 | friend class Q3TextDocument;
|
---|
546 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
547 | friend class Q3TextTableCell;
|
---|
548 | #endif
|
---|
549 |
|
---|
550 | public:
|
---|
551 | Q3TextFlow();
|
---|
552 | virtual ~Q3TextFlow();
|
---|
553 |
|
---|
554 | virtual void setWidth(int width);
|
---|
555 | int width() const;
|
---|
556 |
|
---|
557 | virtual void setPageSize(int ps);
|
---|
558 | int pageSize() const { return pagesize; }
|
---|
559 |
|
---|
560 | virtual int adjustLMargin(int yp, int h, int margin, int space);
|
---|
561 | virtual int adjustRMargin(int yp, int h, int margin, int space);
|
---|
562 |
|
---|
563 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
564 | virtual void registerFloatingItem(Q3TextCustomItem* item);
|
---|
565 | virtual void unregisterFloatingItem(Q3TextCustomItem* item);
|
---|
566 | #endif
|
---|
567 | virtual QRect boundingRect() const;
|
---|
568 | virtual void drawFloatingItems(QPainter* p, int cx, int cy, int cw, int ch,
|
---|
569 | const QPalette &pal, bool selected);
|
---|
570 |
|
---|
571 | virtual int adjustFlow(int y, int w, int h); // adjusts y according to the defined pagesize. Returns the shift.
|
---|
572 |
|
---|
573 | virtual bool isEmpty();
|
---|
574 |
|
---|
575 | void clear();
|
---|
576 |
|
---|
577 | private:
|
---|
578 | int w;
|
---|
579 | int pagesize;
|
---|
580 |
|
---|
581 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
582 | QList<Q3TextCustomItem *> leftItems;
|
---|
583 | QList<Q3TextCustomItem *> rightItems;
|
---|
584 | #endif
|
---|
585 | };
|
---|
586 |
|
---|
587 | inline int Q3TextFlow::width() const { return w; }
|
---|
588 |
|
---|
589 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
590 | class Q3TextTable;
|
---|
591 |
|
---|
592 | class Q_COMPAT_EXPORT Q3TextTableCell : public QLayoutItem
|
---|
593 | {
|
---|
594 | friend class Q3TextTable;
|
---|
595 |
|
---|
596 | public:
|
---|
597 | Q3TextTableCell(Q3TextTable* table,
|
---|
598 | int row, int column,
|
---|
599 | const QMap<QString, QString> &attr,
|
---|
600 | const Q3StyleSheetItem* style,
|
---|
601 | const Q3TextFormat& fmt, const QString& context,
|
---|
602 | Q3MimeSourceFactory &factory, Q3StyleSheet *sheet, const QString& doc);
|
---|
603 | virtual ~Q3TextTableCell();
|
---|
604 |
|
---|
605 | QSize sizeHint() const ;
|
---|
606 | QSize minimumSize() const ;
|
---|
607 | QSize maximumSize() const ;
|
---|
608 | Qt::Orientations expandingDirections() const;
|
---|
609 | bool isEmpty() const;
|
---|
610 | void setGeometry(const QRect&) ;
|
---|
611 | QRect geometry() const;
|
---|
612 |
|
---|
613 | bool hasHeightForWidth() const;
|
---|
614 | int heightForWidth(int) const;
|
---|
615 |
|
---|
616 | void adjustToPainter(QPainter*);
|
---|
617 |
|
---|
618 | int row() const { return row_; }
|
---|
619 | int column() const { return col_; }
|
---|
620 | int rowspan() const { return rowspan_; }
|
---|
621 | int colspan() const { return colspan_; }
|
---|
622 | int stretch() const { return stretch_; }
|
---|
623 |
|
---|
624 | Q3TextDocument* richText() const { return richtext; }
|
---|
625 | Q3TextTable* table() const { return parent; }
|
---|
626 |
|
---|
627 | void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
|
---|
628 | const QPalette &cg, bool selected);
|
---|
629 |
|
---|
630 | QBrush *backGround() const { return background; }
|
---|
631 | virtual void invalidate();
|
---|
632 |
|
---|
633 | int verticalAlignmentOffset() const;
|
---|
634 | int horizontalAlignmentOffset() const;
|
---|
635 |
|
---|
636 | private:
|
---|
637 | QRect geom;
|
---|
638 | Q3TextTable* parent;
|
---|
639 | Q3TextDocument* richtext;
|
---|
640 | int row_;
|
---|
641 | int col_;
|
---|
642 | int rowspan_;
|
---|
643 | int colspan_;
|
---|
644 | int stretch_;
|
---|
645 | int maxw;
|
---|
646 | int minw;
|
---|
647 | bool hasFixedWidth;
|
---|
648 | QBrush *background;
|
---|
649 | int cached_width;
|
---|
650 | int cached_sizehint;
|
---|
651 | QMap<QString, QString> attributes;
|
---|
652 | int align;
|
---|
653 | };
|
---|
654 | #endif
|
---|
655 |
|
---|
656 |
|
---|
657 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
658 | class Q_COMPAT_EXPORT Q3TextTable: public Q3TextCustomItem
|
---|
659 | {
|
---|
660 | friend class Q3TextTableCell;
|
---|
661 |
|
---|
662 | public:
|
---|
663 | Q3TextTable(Q3TextDocument *p, const QMap<QString, QString> &attr);
|
---|
664 | virtual ~Q3TextTable();
|
---|
665 |
|
---|
666 | void adjustToPainter(QPainter *p);
|
---|
667 | void pageBreak(int y, Q3TextFlow* flow);
|
---|
668 | void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
|
---|
669 | const QPalette &pal, bool selected);
|
---|
670 |
|
---|
671 | bool noErase() const { return true; }
|
---|
672 | bool ownLine() const { return true; }
|
---|
673 | Placement placement() const { return place; }
|
---|
674 | bool isNested() const { return true; }
|
---|
675 | void resize(int nwidth);
|
---|
676 | virtual void invalidate();
|
---|
677 |
|
---|
678 | virtual bool enter(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy, bool atEnd = false);
|
---|
679 | virtual bool enterAt(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy, const QPoint &pos);
|
---|
680 | virtual bool next(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
|
---|
681 | virtual bool prev(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
|
---|
682 | virtual bool down(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
|
---|
683 | virtual bool up(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
|
---|
684 |
|
---|
685 | QString richText() const;
|
---|
686 |
|
---|
687 | int minimumWidth() const;
|
---|
688 |
|
---|
689 | QList<Q3TextTableCell *> tableCells() const { return cells; }
|
---|
690 |
|
---|
691 | bool isStretching() const { return stretch; }
|
---|
692 |
|
---|
693 | private:
|
---|
694 | void format(int w);
|
---|
695 | void addCell(Q3TextTableCell* cell);
|
---|
696 |
|
---|
697 | private:
|
---|
698 | QGridLayout* layout;
|
---|
699 | QList<Q3TextTableCell *> cells;
|
---|
700 | int cachewidth;
|
---|
701 | int fixwidth;
|
---|
702 | int cellpadding;
|
---|
703 | int cellspacing;
|
---|
704 | int border;
|
---|
705 | int outerborder;
|
---|
706 | int stretch;
|
---|
707 | int innerborder;
|
---|
708 | int us_cp, us_ib, us_b, us_ob, us_cs;
|
---|
709 | int us_fixwidth;
|
---|
710 | QMap<QString, QString> attributes;
|
---|
711 | QMap<Q3TextCursor*, int> currCell;
|
---|
712 | Placement place;
|
---|
713 | void adjustCells(int y , int shift);
|
---|
714 | int pageBreakFor;
|
---|
715 | };
|
---|
716 | #endif
|
---|
717 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
---|
718 |
|
---|
719 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
720 | class Q3TextTableCell;
|
---|
721 | class Q3TextParagraph;
|
---|
722 | #endif
|
---|
723 |
|
---|
724 | struct Q_COMPAT_EXPORT Q3TextDocumentSelection
|
---|
725 | {
|
---|
726 | Q3TextCursor startCursor, endCursor;
|
---|
727 | bool swapped;
|
---|
728 | Q_DUMMY_COMPARISON_OPERATOR(Q3TextDocumentSelection)
|
---|
729 | };
|
---|
730 |
|
---|
731 | class Q_COMPAT_EXPORT Q3TextDocument : public QObject
|
---|
732 | {
|
---|
733 | Q_OBJECT
|
---|
734 |
|
---|
735 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
736 | friend class Q3TextTableCell;
|
---|
737 | #endif
|
---|
738 | friend class Q3TextCursor;
|
---|
739 | friend class Q3TextEdit;
|
---|
740 | friend class Q3TextParagraph;
|
---|
741 |
|
---|
742 | public:
|
---|
743 | enum SelectionIds {
|
---|
744 | Standard = 0,
|
---|
745 | Temp = 32000 // This selection must not be drawn, it's used e.g. by undo/redo to
|
---|
746 | // remove multiple lines with removeSelectedText()
|
---|
747 | };
|
---|
748 |
|
---|
749 | Q3TextDocument(Q3TextDocument *p);
|
---|
750 | virtual ~Q3TextDocument();
|
---|
751 |
|
---|
752 | Q3TextDocument *parent() const { return par; }
|
---|
753 | Q3TextParagraph *parentParagraph() const { return parentPar; }
|
---|
754 |
|
---|
755 | void setText(const QString &text, const QString &context);
|
---|
756 | QMap<QString, QString> attributes() const { return attribs; }
|
---|
757 | void setAttributes(const QMap<QString, QString> &attr) { attribs = attr; }
|
---|
758 |
|
---|
759 | QString text() const;
|
---|
760 | QString text(int parag) const;
|
---|
761 | QString originalText() const;
|
---|
762 |
|
---|
763 | int x() const;
|
---|
764 | int y() const;
|
---|
765 | int width() const;
|
---|
766 | int widthUsed() const;
|
---|
767 | int visibleWidth() const;
|
---|
768 | int height() const;
|
---|
769 | void setWidth(int w);
|
---|
770 | int minimumWidth() const;
|
---|
771 | bool setMinimumWidth(int needed, int used = -1, Q3TextParagraph *parag = 0);
|
---|
772 |
|
---|
773 | void setY(int y);
|
---|
774 | int leftMargin() const;
|
---|
775 | void setLeftMargin(int lm);
|
---|
776 | int rightMargin() const;
|
---|
777 | void setRightMargin(int rm);
|
---|
778 |
|
---|
779 | Q3TextParagraph *firstParagraph() const;
|
---|
780 | Q3TextParagraph *lastParagraph() const;
|
---|
781 | void setFirstParagraph(Q3TextParagraph *p);
|
---|
782 | void setLastParagraph(Q3TextParagraph *p);
|
---|
783 |
|
---|
784 | void invalidate();
|
---|
785 |
|
---|
786 | void setPreProcessor(Q3TextPreProcessor *sh);
|
---|
787 | Q3TextPreProcessor *preProcessor() const;
|
---|
788 |
|
---|
789 | void setFormatter(Q3TextFormatter *f);
|
---|
790 | Q3TextFormatter *formatter() const;
|
---|
791 |
|
---|
792 | void setIndent(Q3TextIndent *i);
|
---|
793 | Q3TextIndent *indent() const;
|
---|
794 |
|
---|
795 | QColor selectionColor(int id) const;
|
---|
796 | QColor selectionTextColor(int id) const;
|
---|
797 | bool hasSelectionTextColor(int id) const;
|
---|
798 | void setSelectionColor(int id, const QColor &c);
|
---|
799 | void setSelectionTextColor(int id, const QColor &b);
|
---|
800 | bool hasSelection(int id, bool visible = false) const;
|
---|
801 | void setSelectionStart(int id, const Q3TextCursor &cursor);
|
---|
802 | bool setSelectionEnd(int id, const Q3TextCursor &cursor);
|
---|
803 | void selectAll(int id);
|
---|
804 | bool removeSelection(int id);
|
---|
805 | void selectionStart(int id, int ¶gId, int &index);
|
---|
806 | Q3TextCursor selectionStartCursor(int id);
|
---|
807 | Q3TextCursor selectionEndCursor(int id);
|
---|
808 | void selectionEnd(int id, int ¶gId, int &index);
|
---|
809 | void setFormat(int id, Q3TextFormat *f, int flags);
|
---|
810 | int numSelections() const { return nSelections; }
|
---|
811 | void addSelection(int id);
|
---|
812 |
|
---|
813 | QString selectedText(int id, bool asRichText = false) const;
|
---|
814 | void removeSelectedText(int id, Q3TextCursor *cursor);
|
---|
815 | void indentSelection(int id);
|
---|
816 |
|
---|
817 | Q3TextParagraph *paragAt(int i) const;
|
---|
818 |
|
---|
819 | void addCommand(Q3TextCommand *cmd);
|
---|
820 | Q3TextCursor *undo(Q3TextCursor *c = 0);
|
---|
821 | Q3TextCursor *redo(Q3TextCursor *c = 0);
|
---|
822 | Q3TextCommandHistory *commands() const { return commandHistory; }
|
---|
823 |
|
---|
824 | Q3TextFormatCollection *formatCollection() const;
|
---|
825 |
|
---|
826 | bool find(Q3TextCursor &cursor, const QString &expr, bool cs, bool wo, bool forward);
|
---|
827 |
|
---|
828 | void setTextFormat(Qt::TextFormat f);
|
---|
829 | Qt::TextFormat textFormat() const;
|
---|
830 |
|
---|
831 | bool inSelection(int selId, const QPoint &pos) const;
|
---|
832 |
|
---|
833 | Q3StyleSheet *styleSheet() const { return sheet_; }
|
---|
834 | #ifndef QT_NO_MIME
|
---|
835 | Q3MimeSourceFactory *mimeSourceFactory() const { return factory_; }
|
---|
836 | #endif
|
---|
837 | QString context() const { return contxt; }
|
---|
838 |
|
---|
839 | void setStyleSheet(Q3StyleSheet *s);
|
---|
840 | void setDefaultFormat(const QFont &font, const QColor &color);
|
---|
841 | #ifndef QT_NO_MIME
|
---|
842 | void setMimeSourceFactory(Q3MimeSourceFactory *f) { if (f) factory_ = f; }
|
---|
843 | #endif
|
---|
844 | void setContext(const QString &c) { if (!c.isEmpty()) contxt = c; }
|
---|
845 |
|
---|
846 | void setUnderlineLinks(bool b);
|
---|
847 | bool underlineLinks() const { return underlLinks; }
|
---|
848 |
|
---|
849 | void setPaper(QBrush *brush) { if (backBrush) delete backBrush; backBrush = brush; }
|
---|
850 | QBrush *paper() const { return backBrush; }
|
---|
851 |
|
---|
852 | void doLayout(QPainter *p, int w);
|
---|
853 | void draw(QPainter *p, const QRect& rect, const QPalette &pal, const QBrush *paper = 0);
|
---|
854 |
|
---|
855 | void drawParagraph(QPainter *p, Q3TextParagraph *parag, int cx, int cy, int cw, int ch,
|
---|
856 | QPixmap *&doubleBuffer, const QPalette &pal,
|
---|
857 | bool drawCursor, Q3TextCursor *cursor, bool resetChanged = true);
|
---|
858 | Q3TextParagraph *draw(QPainter *p, int cx, int cy, int cw, int ch, const QPalette &pal,
|
---|
859 | bool onlyChanged = false, bool drawCursor = false, Q3TextCursor *cursor = 0,
|
---|
860 | bool resetChanged = true);
|
---|
861 |
|
---|
862 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
863 | static Q3TextCustomItem* tag(Q3StyleSheet *sheet, const QString& name,
|
---|
864 | const QMap<QString, QString> &attr,
|
---|
865 | const QString& context,
|
---|
866 | const Q3MimeSourceFactory& factory,
|
---|
867 | bool emptyTag, Q3TextDocument *doc);
|
---|
868 | #endif
|
---|
869 |
|
---|
870 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
871 | void registerCustomItem(Q3TextCustomItem *i, Q3TextParagraph *p);
|
---|
872 | void unregisterCustomItem(Q3TextCustomItem *i, Q3TextParagraph *p);
|
---|
873 | #endif
|
---|
874 |
|
---|
875 | void setFlow(Q3TextFlow *f);
|
---|
876 | void takeFlow();
|
---|
877 | Q3TextFlow *flow() const { return flow_; }
|
---|
878 | bool isPageBreakEnabled() const { return pages; }
|
---|
879 | void setPageBreakEnabled(bool b) { pages = b; }
|
---|
880 |
|
---|
881 | void setUseFormatCollection(bool b) { useFC = b; }
|
---|
882 | bool useFormatCollection() const { return useFC; }
|
---|
883 |
|
---|
884 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
885 | Q3TextTableCell *tableCell() const { return tc; }
|
---|
886 | void setTableCell(Q3TextTableCell *c) { tc = c; }
|
---|
887 | #endif
|
---|
888 |
|
---|
889 | void setPlainText(const QString &text);
|
---|
890 | void setRichText(const QString &text, const QString &context, const Q3TextFormat *initialFormat = 0);
|
---|
891 | QString richText() const;
|
---|
892 | QString plainText() const;
|
---|
893 |
|
---|
894 | bool focusNextPrevChild(bool next);
|
---|
895 |
|
---|
896 | int alignment() const;
|
---|
897 | void setAlignment(int a);
|
---|
898 |
|
---|
899 | int *tabArray() const;
|
---|
900 | int tabStopWidth() const;
|
---|
901 | void setTabArray(int *a);
|
---|
902 | void setTabStops(int tw);
|
---|
903 |
|
---|
904 | void setUndoDepth(int depth) { commandHistory->setUndoDepth(depth); }
|
---|
905 | int undoDepth() const { return commandHistory->undoDepth(); }
|
---|
906 |
|
---|
907 | int length() const;
|
---|
908 | void clear(bool createEmptyParag = false);
|
---|
909 |
|
---|
910 | virtual Q3TextParagraph *createParagraph(Q3TextDocument *, Q3TextParagraph *pr = 0, Q3TextParagraph *nx = 0, bool updateIds = true);
|
---|
911 | void insertChild(Q3TextDocument *dc) { childList.append(dc); }
|
---|
912 | void removeChild(Q3TextDocument *dc) { childList.removeAll(dc); }
|
---|
913 | QList<Q3TextDocument *> children() const { return childList; }
|
---|
914 |
|
---|
915 | bool hasFocusParagraph() const;
|
---|
916 | QString focusHref() const;
|
---|
917 | QString focusName() const;
|
---|
918 |
|
---|
919 | void invalidateOriginalText() { oTextValid = false; oText = QLatin1String(""); }
|
---|
920 |
|
---|
921 | Q_SIGNALS:
|
---|
922 | void minimumWidthChanged(int);
|
---|
923 |
|
---|
924 | private:
|
---|
925 | Q_DISABLE_COPY(Q3TextDocument)
|
---|
926 |
|
---|
927 | void init();
|
---|
928 | QPixmap *bufferPixmap(const QSize &s);
|
---|
929 | // HTML parser
|
---|
930 | bool hasPrefix(const QChar* doc, int length, int pos, QChar c);
|
---|
931 | bool hasPrefix(const QChar* doc, int length, int pos, const QString& s);
|
---|
932 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
933 | Q3TextCustomItem* parseTable(const QMap<QString, QString> &attr, const Q3TextFormat &fmt,
|
---|
934 | const QChar* doc, int length, int& pos, Q3TextParagraph *curpar);
|
---|
935 | #endif
|
---|
936 | bool eatSpace(const QChar* doc, int length, int& pos, bool includeNbsp = false);
|
---|
937 | bool eat(const QChar* doc, int length, int& pos, QChar c);
|
---|
938 | QString parseOpenTag(const QChar* doc, int length, int& pos, QMap<QString, QString> &attr, bool& emptyTag);
|
---|
939 | QString parseCloseTag(const QChar* doc, int length, int& pos);
|
---|
940 | QChar parseHTMLSpecialChar(const QChar* doc, int length, int& pos);
|
---|
941 | QString parseWord(const QChar* doc, int length, int& pos, bool lower = true);
|
---|
942 | QChar parseChar(const QChar* doc, int length, int& pos, Q3StyleSheetItem::WhiteSpaceMode wsm);
|
---|
943 | void setRichTextInternal(const QString &text, Q3TextCursor* cursor = 0, const Q3TextFormat *initialFormat = 0);
|
---|
944 | void setRichTextMarginsInternal(QList< QVector<Q3StyleSheetItem *> *>& styles, Q3TextParagraph* stylesPar);
|
---|
945 |
|
---|
946 | struct Q_COMPAT_EXPORT Focus {
|
---|
947 | Q3TextParagraph *parag;
|
---|
948 | int start, len;
|
---|
949 | QString href;
|
---|
950 | QString name;
|
---|
951 | };
|
---|
952 |
|
---|
953 | int cx, cy, cw, vw;
|
---|
954 | Q3TextParagraph *fParag, *lParag;
|
---|
955 | Q3TextPreProcessor *pProcessor;
|
---|
956 | struct SelectionColor {
|
---|
957 | QColor background;
|
---|
958 | QColor text;
|
---|
959 | };
|
---|
960 | QMap<int, SelectionColor> selectionColors;
|
---|
961 | QMap<int, Q3TextDocumentSelection> selections;
|
---|
962 | Q3TextCommandHistory *commandHistory;
|
---|
963 | Q3TextFormatter *pFormatter;
|
---|
964 | Q3TextIndent *indenter;
|
---|
965 | Q3TextFormatCollection *fCollection;
|
---|
966 | Qt::TextFormat txtFormat;
|
---|
967 | uint preferRichText : 1;
|
---|
968 | uint pages : 1;
|
---|
969 | uint useFC : 1;
|
---|
970 | uint withoutDoubleBuffer : 1;
|
---|
971 | uint underlLinks : 1;
|
---|
972 | uint nextDoubleBuffered : 1;
|
---|
973 | uint oTextValid : 1;
|
---|
974 | uint mightHaveCustomItems : 1;
|
---|
975 | int align;
|
---|
976 | int nSelections;
|
---|
977 | Q3TextFlow *flow_;
|
---|
978 | Q3TextDocument *par;
|
---|
979 | Q3TextParagraph *parentPar;
|
---|
980 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
981 | Q3TextTableCell *tc;
|
---|
982 | #endif
|
---|
983 | QBrush *backBrush;
|
---|
984 | QPixmap *buf_pixmap;
|
---|
985 | Focus focusIndicator;
|
---|
986 | int minw;
|
---|
987 | int wused;
|
---|
988 | int leftmargin;
|
---|
989 | int rightmargin;
|
---|
990 | Q3TextParagraph *minwParag, *curParag;
|
---|
991 | Q3StyleSheet* sheet_;
|
---|
992 | #ifndef QT_NO_MIME
|
---|
993 | Q3MimeSourceFactory* factory_;
|
---|
994 | #endif
|
---|
995 | QString contxt;
|
---|
996 | QMap<QString, QString> attribs;
|
---|
997 | int *tArray;
|
---|
998 | int tStopWidth;
|
---|
999 | int uDepth;
|
---|
1000 | QString oText;
|
---|
1001 | QList<Q3TextDocument *> childList;
|
---|
1002 | QColor linkColor, bodyText;
|
---|
1003 | double scaleFontsFactor;
|
---|
1004 |
|
---|
1005 | short list_tm,list_bm, list_lm, li_tm, li_bm, par_tm, par_bm;
|
---|
1006 | };
|
---|
1007 |
|
---|
1008 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
---|
1009 |
|
---|
1010 |
|
---|
1011 | class Q_COMPAT_EXPORT Q3TextDeleteCommand : public Q3TextCommand
|
---|
1012 | {
|
---|
1013 | public:
|
---|
1014 | Q3TextDeleteCommand(Q3TextDocument *dc, int i, int idx, const QVector<Q3TextStringChar> &str,
|
---|
1015 | const QByteArray& oldStyle);
|
---|
1016 | Q3TextDeleteCommand(Q3TextParagraph *p, int idx, const QVector<Q3TextStringChar> &str);
|
---|
1017 | virtual ~Q3TextDeleteCommand();
|
---|
1018 |
|
---|
1019 | Commands type() const { return Delete; }
|
---|
1020 | Q3TextCursor *execute(Q3TextCursor *c);
|
---|
1021 | Q3TextCursor *unexecute(Q3TextCursor *c);
|
---|
1022 |
|
---|
1023 | protected:
|
---|
1024 | int id, index;
|
---|
1025 | Q3TextParagraph *parag;
|
---|
1026 | QVector<Q3TextStringChar> text;
|
---|
1027 | QByteArray styleInformation;
|
---|
1028 |
|
---|
1029 | };
|
---|
1030 |
|
---|
1031 | class Q_COMPAT_EXPORT Q3TextInsertCommand : public Q3TextDeleteCommand
|
---|
1032 | {
|
---|
1033 | public:
|
---|
1034 | Q3TextInsertCommand(Q3TextDocument *dc, int i, int idx, const QVector<Q3TextStringChar> &str,
|
---|
1035 | const QByteArray& oldStyleInfo)
|
---|
1036 | : Q3TextDeleteCommand(dc, i, idx, str, oldStyleInfo) {}
|
---|
1037 | Q3TextInsertCommand(Q3TextParagraph *p, int idx, const QVector<Q3TextStringChar> &str)
|
---|
1038 | : Q3TextDeleteCommand(p, idx, str) {}
|
---|
1039 | virtual ~Q3TextInsertCommand() {}
|
---|
1040 |
|
---|
1041 | Commands type() const { return Insert; }
|
---|
1042 | Q3TextCursor *execute(Q3TextCursor *c) { return Q3TextDeleteCommand::unexecute(c); }
|
---|
1043 | Q3TextCursor *unexecute(Q3TextCursor *c) { return Q3TextDeleteCommand::execute(c); }
|
---|
1044 |
|
---|
1045 | };
|
---|
1046 |
|
---|
1047 | class Q_COMPAT_EXPORT Q3TextFormatCommand : public Q3TextCommand
|
---|
1048 | {
|
---|
1049 | public:
|
---|
1050 | Q3TextFormatCommand(Q3TextDocument *dc, int sid, int sidx, int eid, int eidx, const QVector<Q3TextStringChar> &old, Q3TextFormat *f, int fl);
|
---|
1051 | virtual ~Q3TextFormatCommand();
|
---|
1052 |
|
---|
1053 | Commands type() const { return Format; }
|
---|
1054 | Q3TextCursor *execute(Q3TextCursor *c);
|
---|
1055 | Q3TextCursor *unexecute(Q3TextCursor *c);
|
---|
1056 |
|
---|
1057 | protected:
|
---|
1058 | int startId, startIndex, endId, endIndex;
|
---|
1059 | Q3TextFormat *format;
|
---|
1060 | QVector<Q3TextStringChar> oldFormats;
|
---|
1061 | int flags;
|
---|
1062 |
|
---|
1063 | };
|
---|
1064 |
|
---|
1065 | class Q_COMPAT_EXPORT Q3TextStyleCommand : public Q3TextCommand
|
---|
1066 | {
|
---|
1067 | public:
|
---|
1068 | Q3TextStyleCommand(Q3TextDocument *dc, int fParag, int lParag, const QByteArray& beforeChange );
|
---|
1069 | virtual ~Q3TextStyleCommand() {}
|
---|
1070 |
|
---|
1071 | Commands type() const { return Style; }
|
---|
1072 | Q3TextCursor *execute(Q3TextCursor *c);
|
---|
1073 | Q3TextCursor *unexecute(Q3TextCursor *c);
|
---|
1074 |
|
---|
1075 | static QByteArray readStyleInformation( Q3TextDocument* dc, int fParag, int lParag);
|
---|
1076 | static void writeStyleInformation( Q3TextDocument* dc, int fParag, const QByteArray& style);
|
---|
1077 |
|
---|
1078 | private:
|
---|
1079 | int firstParag, lastParag;
|
---|
1080 | QByteArray before;
|
---|
1081 | QByteArray after;
|
---|
1082 | };
|
---|
1083 |
|
---|
1084 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
---|
1085 |
|
---|
1086 | struct Q_COMPAT_EXPORT Q3TextParagraphSelection
|
---|
1087 | {
|
---|
1088 | int start, end;
|
---|
1089 | Q_DUMMY_COMPARISON_OPERATOR(Q3TextParagraphSelection)
|
---|
1090 | };
|
---|
1091 |
|
---|
1092 | struct Q_COMPAT_EXPORT QTextLineStart
|
---|
1093 | {
|
---|
1094 | QTextLineStart() : y(0), baseLine(0), h(0)
|
---|
1095 | { }
|
---|
1096 | QTextLineStart(int y_, int bl, int h_) : y(y_), baseLine(bl), h(h_),
|
---|
1097 | w(0)
|
---|
1098 | { }
|
---|
1099 |
|
---|
1100 | public:
|
---|
1101 | int y, baseLine, h;
|
---|
1102 | int w;
|
---|
1103 | };
|
---|
1104 |
|
---|
1105 | class Q_COMPAT_EXPORT Q3TextParagraphData
|
---|
1106 | {
|
---|
1107 | public:
|
---|
1108 | Q3TextParagraphData() {}
|
---|
1109 | virtual ~Q3TextParagraphData();
|
---|
1110 | virtual void join(Q3TextParagraphData *);
|
---|
1111 | };
|
---|
1112 |
|
---|
1113 | class Q3TextParagraphPseudoDocument;
|
---|
1114 |
|
---|
1115 | class Q3SyntaxHighlighter;
|
---|
1116 |
|
---|
1117 | class Q_COMPAT_EXPORT Q3TextParagraph
|
---|
1118 | {
|
---|
1119 | friend class Q3TextDocument;
|
---|
1120 | friend class Q3TextCursor;
|
---|
1121 | friend class Q3SyntaxHighlighter;
|
---|
1122 |
|
---|
1123 | public:
|
---|
1124 | Q3TextParagraph(Q3TextDocument *dc, Q3TextParagraph *pr = 0, Q3TextParagraph *nx = 0, bool updateIds = true);
|
---|
1125 | ~Q3TextParagraph();
|
---|
1126 |
|
---|
1127 | Q3TextString *string() const;
|
---|
1128 | Q3TextStringChar *at(int i) const; // maybe remove later
|
---|
1129 | int leftGap() const;
|
---|
1130 | int length() const; // maybe remove later
|
---|
1131 |
|
---|
1132 | void setListStyle(Q3StyleSheetItem::ListStyle ls) { lstyle = ls; changed = true; }
|
---|
1133 | Q3StyleSheetItem::ListStyle listStyle() const { return (Q3StyleSheetItem::ListStyle)lstyle; }
|
---|
1134 | void setListItem(bool li);
|
---|
1135 | bool isListItem() const { return litem; }
|
---|
1136 | void setListValue(int v) { list_val = v; }
|
---|
1137 | int listValue() const { return list_val > 0 ? list_val : -1; }
|
---|
1138 |
|
---|
1139 | void setListDepth(int depth);
|
---|
1140 | int listDepth() const { return ldepth; }
|
---|
1141 |
|
---|
1142 | // void setFormat(Q3TextFormat *fm);
|
---|
1143 | // Q3TextFormat *paragFormat() const;
|
---|
1144 |
|
---|
1145 | inline Q3TextDocument *document() const {
|
---|
1146 | if (hasdoc) return (Q3TextDocument*) docOrPseudo;
|
---|
1147 | return 0;
|
---|
1148 | }
|
---|
1149 | Q3TextParagraphPseudoDocument *pseudoDocument() const;
|
---|
1150 |
|
---|
1151 | QRect rect() const;
|
---|
1152 | void setHeight(int h) { r.setHeight(h); }
|
---|
1153 | void show();
|
---|
1154 | void hide();
|
---|
1155 | bool isVisible() const { return visible; }
|
---|
1156 |
|
---|
1157 | Q3TextParagraph *prev() const;
|
---|
1158 | Q3TextParagraph *next() const;
|
---|
1159 | void setPrev(Q3TextParagraph *s);
|
---|
1160 | void setNext(Q3TextParagraph *s);
|
---|
1161 |
|
---|
1162 | void insert(int index, const QString &s);
|
---|
1163 | void insert(int index, const QChar *unicode, int len);
|
---|
1164 | void append(const QString &s, bool reallyAtEnd = false);
|
---|
1165 | void truncate(int index);
|
---|
1166 | void remove(int index, int len);
|
---|
1167 | void join(Q3TextParagraph *s);
|
---|
1168 |
|
---|
1169 | void invalidate(int chr);
|
---|
1170 |
|
---|
1171 | void move(int &dy);
|
---|
1172 | void format(int start = -1, bool doMove = true);
|
---|
1173 |
|
---|
1174 | bool isValid() const;
|
---|
1175 | bool hasChanged() const;
|
---|
1176 | void setChanged(bool b, bool recursive = false);
|
---|
1177 |
|
---|
1178 | int lineHeightOfChar(int i, int *bl = 0, int *y = 0) const;
|
---|
1179 | Q3TextStringChar *lineStartOfChar(int i, int *index = 0, int *line = 0) const;
|
---|
1180 | int lines() const;
|
---|
1181 | Q3TextStringChar *lineStartOfLine(int line, int *index = 0) const;
|
---|
1182 | int lineY(int l) const;
|
---|
1183 | int lineBaseLine(int l) const;
|
---|
1184 | int lineHeight(int l) const;
|
---|
1185 | void lineInfo(int l, int &y, int &h, int &bl) const;
|
---|
1186 |
|
---|
1187 | void setSelection(int id, int start, int end);
|
---|
1188 | void removeSelection(int id);
|
---|
1189 | int selectionStart(int id) const;
|
---|
1190 | int selectionEnd(int id) const;
|
---|
1191 | bool hasSelection(int id) const;
|
---|
1192 | bool hasAnySelection() const;
|
---|
1193 | bool fullSelected(int id) const;
|
---|
1194 |
|
---|
1195 | void setEndState(int s);
|
---|
1196 | int endState() const;
|
---|
1197 |
|
---|
1198 | void setParagId(int i);
|
---|
1199 | int paragId() const;
|
---|
1200 |
|
---|
1201 | bool firstPreProcess() const;
|
---|
1202 | void setFirstPreProcess(bool b);
|
---|
1203 |
|
---|
1204 | void indent(int *oldIndent = 0, int *newIndent = 0);
|
---|
1205 |
|
---|
1206 | void setExtraData(Q3TextParagraphData *data);
|
---|
1207 | Q3TextParagraphData *extraData() const;
|
---|
1208 |
|
---|
1209 | QMap<int, QTextLineStart*> &lineStartList();
|
---|
1210 |
|
---|
1211 | void setFormat(int index, int len, Q3TextFormat *f, bool useCollection = true, int flags = -1);
|
---|
1212 |
|
---|
1213 | void setAlignment(int a);
|
---|
1214 | int alignment() const;
|
---|
1215 |
|
---|
1216 | void paint(QPainter &painter, const QPalette &pal, Q3TextCursor *cursor = 0,
|
---|
1217 | bool drawSelections = false, int clipx = -1, int clipy = -1,
|
---|
1218 | int clipw = -1, int cliph = -1);
|
---|
1219 |
|
---|
1220 | int topMargin() const;
|
---|
1221 | int bottomMargin() const;
|
---|
1222 | int leftMargin() const;
|
---|
1223 | int firstLineMargin() const;
|
---|
1224 | int rightMargin() const;
|
---|
1225 | int lineSpacing() const;
|
---|
1226 |
|
---|
1227 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
1228 | void registerFloatingItem(Q3TextCustomItem *i);
|
---|
1229 | void unregisterFloatingItem(Q3TextCustomItem *i);
|
---|
1230 | #endif
|
---|
1231 |
|
---|
1232 | void setFullWidth(bool b) { fullWidth = b; }
|
---|
1233 | bool isFullWidth() const { return fullWidth; }
|
---|
1234 |
|
---|
1235 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
1236 | Q3TextTableCell *tableCell() const;
|
---|
1237 | #endif
|
---|
1238 |
|
---|
1239 | QBrush *background() const;
|
---|
1240 |
|
---|
1241 | int documentWidth() const;
|
---|
1242 | int documentVisibleWidth() const;
|
---|
1243 | int documentX() const;
|
---|
1244 | int documentY() const;
|
---|
1245 | Q3TextFormatCollection *formatCollection() const;
|
---|
1246 | Q3TextFormatter *formatter() const;
|
---|
1247 |
|
---|
1248 | int nextTab(int i, int x);
|
---|
1249 | int *tabArray() const;
|
---|
1250 | void setTabArray(int *a);
|
---|
1251 | void setTabStops(int tw);
|
---|
1252 |
|
---|
1253 | void adjustToPainter(QPainter *p);
|
---|
1254 |
|
---|
1255 | void setNewLinesAllowed(bool b);
|
---|
1256 | bool isNewLinesAllowed() const;
|
---|
1257 |
|
---|
1258 | QString richText() const;
|
---|
1259 |
|
---|
1260 | void addCommand(Q3TextCommand *cmd);
|
---|
1261 | Q3TextCursor *undo(Q3TextCursor *c = 0);
|
---|
1262 | Q3TextCursor *redo(Q3TextCursor *c = 0);
|
---|
1263 | Q3TextCommandHistory *commands() const;
|
---|
1264 | void copyParagData(Q3TextParagraph *parag);
|
---|
1265 |
|
---|
1266 | void setBreakable(bool b) { breakable = b; }
|
---|
1267 | bool isBreakable() const { return breakable; }
|
---|
1268 |
|
---|
1269 | void setBackgroundColor(const QColor &c);
|
---|
1270 | QColor *backgroundColor() const { return bgcol; }
|
---|
1271 | void clearBackgroundColor();
|
---|
1272 |
|
---|
1273 | void setMovedDown(bool b) { movedDown = b; }
|
---|
1274 | bool wasMovedDown() const { return movedDown; }
|
---|
1275 |
|
---|
1276 | void setDirection(QChar::Direction);
|
---|
1277 | QChar::Direction direction() const;
|
---|
1278 | void setPaintDevice(QPaintDevice *pd) { paintdevice = pd; }
|
---|
1279 |
|
---|
1280 | void readStyleInformation(QDataStream& stream);
|
---|
1281 | void writeStyleInformation(QDataStream& stream) const;
|
---|
1282 |
|
---|
1283 | protected:
|
---|
1284 | void setColorForSelection(QColor &c, QPainter &p, const QPalette &pal, int selection);
|
---|
1285 | void drawLabel(QPainter* p, int x, int y, int w, int h, int base, const QPalette &pal);
|
---|
1286 | void drawString(QPainter &painter, const QString &str, int start, int len, int xstart,
|
---|
1287 | int y, int baseLine, int w, int h, bool drawSelections, int fullSelectionWidth,
|
---|
1288 | Q3TextStringChar *formatChar, const QPalette &pal,
|
---|
1289 | bool rightToLeft);
|
---|
1290 |
|
---|
1291 | private:
|
---|
1292 | QMap<int, Q3TextParagraphSelection> &selections() const;
|
---|
1293 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
1294 | QList<Q3TextCustomItem *> &floatingItems() const;
|
---|
1295 | #endif
|
---|
1296 | inline QBrush backgroundBrush(const QPalette &pal) {
|
---|
1297 | if (bgcol)
|
---|
1298 | return *bgcol;
|
---|
1299 | return pal.brush(QPalette::Base);
|
---|
1300 | }
|
---|
1301 | void invalidateStyleCache();
|
---|
1302 |
|
---|
1303 | QMap<int, QTextLineStart*> lineStarts;
|
---|
1304 | QRect r;
|
---|
1305 | Q3TextParagraph *p, *n;
|
---|
1306 | void *docOrPseudo;
|
---|
1307 | uint changed : 1;
|
---|
1308 | uint firstFormat : 1;
|
---|
1309 | uint firstPProcess : 1;
|
---|
1310 | uint needPreProcess : 1;
|
---|
1311 | uint fullWidth : 1;
|
---|
1312 | uint lastInFrame : 1;
|
---|
1313 | uint visible : 1;
|
---|
1314 | uint breakable : 1;
|
---|
1315 | uint movedDown : 1;
|
---|
1316 | uint mightHaveCustomItems : 1;
|
---|
1317 | uint hasdoc : 1;
|
---|
1318 | uint litem : 1; // whether the paragraph is a list item
|
---|
1319 | uint rtext : 1; // whether the paragraph needs rich text margin
|
---|
1320 | signed int align : 5;
|
---|
1321 | uint /*Q3StyleSheetItem::ListStyle*/ lstyle : 4;
|
---|
1322 | int invalid;
|
---|
1323 | int state, id;
|
---|
1324 | Q3TextString *str;
|
---|
1325 | QMap<int, Q3TextParagraphSelection> *mSelections;
|
---|
1326 | #ifndef QT_NO_TEXTCUSTOMITEM
|
---|
1327 | QList<Q3TextCustomItem *> *mFloatingItems;
|
---|
1328 | #endif
|
---|
1329 | short utm, ubm, ulm, urm, uflm, ulinespacing;
|
---|
1330 | short tabStopWidth, minwidth;
|
---|
1331 | int *tArray;
|
---|
1332 | Q3TextParagraphData *eData;
|
---|
1333 | short list_val;
|
---|
1334 | ushort ldepth;
|
---|
|
---|