| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 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;
|
|---|
| 1335 | QColor *bgcol;
|
|---|
| 1336 | QPaintDevice *paintdevice;
|
|---|
| 1337 | };
|
|---|
| 1338 |
|
|---|
| 1339 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1340 |
|
|---|
| 1341 | class Q_COMPAT_EXPORT Q3TextFormatter
|
|---|
| 1342 | {
|
|---|
| 1343 | public:
|
|---|
| 1344 | Q3TextFormatter();
|
|---|
| 1345 | virtual ~Q3TextFormatter();
|
|---|
| 1346 |
|
|---|
| 1347 | virtual int format(Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts) = 0;
|
|---|
| 1348 | virtual int formatVertically(Q3TextDocument* doc, Q3TextParagraph* parag);
|
|---|
| 1349 |
|
|---|
| 1350 | bool isWrapEnabled(Q3TextParagraph *p) const { if (!wrapEnabled) return false; if (p && !p->isBreakable()) return false; return true;}
|
|---|
| 1351 | int wrapAtColumn() const { return wrapColumn;}
|
|---|
| 1352 | virtual void setWrapEnabled(bool b);
|
|---|
| 1353 | virtual void setWrapAtColumn(int c);
|
|---|
| 1354 | virtual void setAllowBreakInWords(bool b) { biw = b; }
|
|---|
| 1355 | bool allowBreakInWords() const { return biw; }
|
|---|
| 1356 |
|
|---|
| 1357 | int minimumWidth() const { return thisminw; }
|
|---|
| 1358 | int widthUsed() const { return thiswused; }
|
|---|
| 1359 |
|
|---|
| 1360 | protected:
|
|---|
| 1361 | virtual QTextLineStart *formatLine(Q3TextParagraph *parag, Q3TextString *string, QTextLineStart *line, Q3TextStringChar *start,
|
|---|
| 1362 | Q3TextStringChar *last, int align = Qt::AlignAuto, int space = 0);
|
|---|
| 1363 | #ifndef QT_NO_COMPLEXTEXT
|
|---|
| 1364 | virtual QTextLineStart *bidiReorderLine(Q3TextParagraph *parag, Q3TextString *string, QTextLineStart *line, Q3TextStringChar *start,
|
|---|
| 1365 | Q3TextStringChar *last, int align, int space);
|
|---|
| 1366 | #endif
|
|---|
| 1367 | void insertLineStart(Q3TextParagraph *parag, int index, QTextLineStart *ls);
|
|---|
| 1368 |
|
|---|
| 1369 | int thisminw;
|
|---|
| 1370 | int thiswused;
|
|---|
| 1371 |
|
|---|
| 1372 | private:
|
|---|
| 1373 | bool wrapEnabled;
|
|---|
| 1374 | int wrapColumn;
|
|---|
| 1375 | bool biw;
|
|---|
| 1376 | };
|
|---|
| 1377 |
|
|---|
| 1378 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1379 |
|
|---|
| 1380 | class Q_COMPAT_EXPORT Q3TextFormatterBreakInWords : public Q3TextFormatter
|
|---|
| 1381 | {
|
|---|
| 1382 | public:
|
|---|
| 1383 | Q3TextFormatterBreakInWords();
|
|---|
| 1384 | virtual ~Q3TextFormatterBreakInWords() {}
|
|---|
| 1385 |
|
|---|
| 1386 | int format(Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts);
|
|---|
| 1387 |
|
|---|
| 1388 | };
|
|---|
| 1389 |
|
|---|
| 1390 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1391 |
|
|---|
| 1392 | class Q_COMPAT_EXPORT Q3TextFormatterBreakWords : public Q3TextFormatter
|
|---|
| 1393 | {
|
|---|
| 1394 | public:
|
|---|
| 1395 | Q3TextFormatterBreakWords();
|
|---|
| 1396 | virtual ~Q3TextFormatterBreakWords() {}
|
|---|
| 1397 |
|
|---|
| 1398 | int format(Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts);
|
|---|
| 1399 |
|
|---|
| 1400 | };
|
|---|
| 1401 |
|
|---|
| 1402 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1403 |
|
|---|
| 1404 | class Q_COMPAT_EXPORT Q3TextIndent
|
|---|
| 1405 | {
|
|---|
| 1406 | public:
|
|---|
| 1407 | Q3TextIndent();
|
|---|
| 1408 | virtual ~Q3TextIndent() {}
|
|---|
| 1409 |
|
|---|
| 1410 | virtual void indent(Q3TextDocument *doc, Q3TextParagraph *parag, int *oldIndent = 0, int *newIndent = 0) = 0;
|
|---|
| 1411 |
|
|---|
| 1412 | };
|
|---|
| 1413 |
|
|---|
| 1414 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1415 |
|
|---|
| 1416 | class Q_COMPAT_EXPORT Q3TextPreProcessor
|
|---|
| 1417 | {
|
|---|
| 1418 | public:
|
|---|
| 1419 | enum Ids {
|
|---|
| 1420 | Standard = 0
|
|---|
| 1421 | };
|
|---|
| 1422 |
|
|---|
| 1423 | Q3TextPreProcessor();
|
|---|
| 1424 | virtual ~Q3TextPreProcessor() {}
|
|---|
| 1425 |
|
|---|
| 1426 | virtual void process(Q3TextDocument *doc, Q3TextParagraph *, int, bool = true) = 0;
|
|---|
| 1427 | virtual Q3TextFormat *format(int id) = 0;
|
|---|
| 1428 |
|
|---|
| 1429 | };
|
|---|
| 1430 |
|
|---|
| 1431 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1432 |
|
|---|
| 1433 | class Q_COMPAT_EXPORT Q3TextFormat
|
|---|
| 1434 | {
|
|---|
| 1435 | friend class Q3TextFormatCollection;
|
|---|
| 1436 | friend class Q3TextDocument;
|
|---|
| 1437 |
|
|---|
| 1438 | public:
|
|---|
| 1439 | enum Flags {
|
|---|
| 1440 | NoFlags,
|
|---|
| 1441 | Bold = 1,
|
|---|
| 1442 | Italic = 2,
|
|---|
| 1443 | Underline = 4,
|
|---|
| 1444 | Family = 8,
|
|---|
| 1445 | Size = 16,
|
|---|
| 1446 | Color = 32,
|
|---|
| 1447 | Misspelled = 64,
|
|---|
| 1448 | VAlign = 128,
|
|---|
| 1449 | StrikeOut= 256,
|
|---|
| 1450 | Font = Bold | Italic | Underline | Family | Size | StrikeOut,
|
|---|
| 1451 | Format = Font | Color | Misspelled | VAlign
|
|---|
| 1452 | };
|
|---|
| 1453 |
|
|---|
| 1454 | enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript };
|
|---|
| 1455 |
|
|---|
| 1456 | Q3TextFormat();
|
|---|
| 1457 | virtual ~Q3TextFormat();
|
|---|
| 1458 |
|
|---|
| 1459 | Q3TextFormat(const Q3StyleSheetItem *s);
|
|---|
| 1460 | Q3TextFormat(const QFont &f, const QColor &c, Q3TextFormatCollection *parent = 0);
|
|---|
| 1461 | Q3TextFormat(const Q3TextFormat &fm);
|
|---|
| 1462 | Q3TextFormat makeTextFormat(const Q3StyleSheetItem *style, const QMap<QString,QString>& attr, double scaleFontsFactor) const;
|
|---|
| 1463 | Q3TextFormat& operator=(const Q3TextFormat &fm);
|
|---|
| 1464 | QColor color() const;
|
|---|
| 1465 | QFont font() const;
|
|---|
| 1466 | QFontMetrics fontMetrics() const { return fm; }
|
|---|
| 1467 | bool isMisspelled() const;
|
|---|
| 1468 | VerticalAlignment vAlign() const;
|
|---|
| 1469 | int minLeftBearing() const;
|
|---|
| 1470 | int minRightBearing() const;
|
|---|
| 1471 | int width(const QChar &c) const;
|
|---|
| 1472 | int width(const QString &str, int pos) const;
|
|---|
| 1473 | int height() const;
|
|---|
| 1474 | int ascent() const;
|
|---|
| 1475 | int descent() const;
|
|---|
| 1476 | int leading() const;
|
|---|
| 1477 | bool useLinkColor() const;
|
|---|
| 1478 |
|
|---|
| 1479 | void setBold(bool b);
|
|---|
| 1480 | void setItalic(bool b);
|
|---|
| 1481 | void setUnderline(bool b);
|
|---|
| 1482 | void setStrikeOut(bool b);
|
|---|
| 1483 | void setFamily(const QString &f);
|
|---|
| 1484 | void setPointSize(int s);
|
|---|
| 1485 | void setFont(const QFont &f);
|
|---|
| 1486 | void setColor(const QColor &c);
|
|---|
| 1487 | void setMisspelled(bool b);
|
|---|
| 1488 | void setVAlign(VerticalAlignment a);
|
|---|
| 1489 |
|
|---|
| 1490 | bool operator==(const Q3TextFormat &f) const;
|
|---|
| 1491 | Q3TextFormatCollection *parent() const;
|
|---|
| 1492 | const QString &key() const;
|
|---|
| 1493 |
|
|---|
| 1494 | static QString getKey(const QFont &f, const QColor &c, bool misspelled, VerticalAlignment vAlign);
|
|---|
| 1495 |
|
|---|
| 1496 | void addRef();
|
|---|
| 1497 | void removeRef();
|
|---|
| 1498 |
|
|---|
| 1499 | QString makeFormatChangeTags(Q3TextFormat* defaultFormat, Q3TextFormat *f, const QString& oldAnchorHref, const QString& anchorHref) const;
|
|---|
| 1500 | QString makeFormatEndTags(Q3TextFormat* defaultFormat, const QString& anchorHref) const;
|
|---|
| 1501 |
|
|---|
| 1502 | static void setPainter(QPainter *p);
|
|---|
| 1503 | static QPainter* painter();
|
|---|
| 1504 |
|
|---|
| 1505 | bool fontSizesInPixels() { return usePixelSizes; }
|
|---|
| 1506 |
|
|---|
| 1507 | protected:
|
|---|
| 1508 | virtual void generateKey();
|
|---|
| 1509 |
|
|---|
| 1510 | private:
|
|---|
| 1511 | void update();
|
|---|
| 1512 | static void applyFont(const QFont &f);
|
|---|
| 1513 |
|
|---|
| 1514 | private:
|
|---|
| 1515 | QFont fn;
|
|---|
| 1516 | QColor col;
|
|---|
| 1517 | QFontMetrics fm;
|
|---|
| 1518 | uint missp : 1;
|
|---|
| 1519 | uint linkColor : 1;
|
|---|
| 1520 | uint usePixelSizes : 1;
|
|---|
| 1521 | int leftBearing, rightBearing;
|
|---|
| 1522 | VerticalAlignment ha;
|
|---|
| 1523 | uchar widths[256];
|
|---|
| 1524 | int hei, asc, dsc;
|
|---|
| 1525 | Q3TextFormatCollection *collection;
|
|---|
| 1526 | int ref;
|
|---|
| 1527 | QString k;
|
|---|
| 1528 | int logicalFontSize;
|
|---|
| 1529 | int stdSize;
|
|---|
| 1530 | static QPainter *pntr;
|
|---|
| 1531 | static QFontMetrics *pntr_fm;
|
|---|
| 1532 | static int pntr_asc;
|
|---|
| 1533 | static int pntr_hei;
|
|---|
| 1534 | static int pntr_ldg;
|
|---|
| 1535 | static int pntr_dsc;
|
|---|
| 1536 |
|
|---|
| 1537 | };
|
|---|
| 1538 |
|
|---|
| 1539 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1540 |
|
|---|
| 1541 | class Q_COMPAT_EXPORT Q3TextFormatCollection
|
|---|
| 1542 | {
|
|---|
| 1543 | friend class Q3TextDocument;
|
|---|
| 1544 | friend class Q3TextFormat;
|
|---|
| 1545 |
|
|---|
| 1546 | public:
|
|---|
| 1547 | Q3TextFormatCollection();
|
|---|
| 1548 | virtual ~Q3TextFormatCollection();
|
|---|
| 1549 |
|
|---|
| 1550 | void setDefaultFormat(Q3TextFormat *f);
|
|---|
| 1551 | Q3TextFormat *defaultFormat() const;
|
|---|
| 1552 | virtual Q3TextFormat *format(Q3TextFormat *f);
|
|---|
| 1553 | virtual Q3TextFormat *format(Q3TextFormat *of, Q3TextFormat *nf, int flags);
|
|---|
| 1554 | virtual Q3TextFormat *format(const QFont &f, const QColor &c);
|
|---|
| 1555 | virtual void remove(Q3TextFormat *f);
|
|---|
| 1556 | virtual Q3TextFormat *createFormat(const Q3TextFormat &f) { return new Q3TextFormat(f); }
|
|---|
| 1557 | virtual Q3TextFormat *createFormat(const QFont &f, const QColor &c) { return new Q3TextFormat(f, c, this); }
|
|---|
| 1558 |
|
|---|
| 1559 | void updateDefaultFormat(const QFont &font, const QColor &c, Q3StyleSheet *sheet);
|
|---|
| 1560 |
|
|---|
| 1561 | QPaintDevice *paintDevice() const { return paintdevice; }
|
|---|
| 1562 | void setPaintDevice(QPaintDevice *);
|
|---|
| 1563 |
|
|---|
| 1564 | private:
|
|---|
| 1565 | void updateKeys();
|
|---|
| 1566 |
|
|---|
| 1567 | private:
|
|---|
| 1568 | Q3TextFormat *defFormat, *lastFormat, *cachedFormat;
|
|---|
| 1569 | QHash<QString, Q3TextFormat *> cKey;
|
|---|
| 1570 | Q3TextFormat *cres;
|
|---|
| 1571 | QFont cfont;
|
|---|
| 1572 | QColor ccol;
|
|---|
| 1573 | QString kof, knf;
|
|---|
| 1574 | int cflags;
|
|---|
| 1575 |
|
|---|
| 1576 | QPaintDevice *paintdevice;
|
|---|
| 1577 | };
|
|---|
| 1578 |
|
|---|
| 1579 | class Q_COMPAT_EXPORT Q3TextParagraphPseudoDocument
|
|---|
| 1580 | {
|
|---|
| 1581 | public:
|
|---|
| 1582 | Q3TextParagraphPseudoDocument();
|
|---|
| 1583 | ~Q3TextParagraphPseudoDocument();
|
|---|
| 1584 | QRect docRect;
|
|---|
| 1585 | Q3TextFormatter *pFormatter;
|
|---|
| 1586 | Q3TextCommandHistory *commandHistory;
|
|---|
| 1587 | int minw;
|
|---|
| 1588 | int wused;
|
|---|
| 1589 | Q3TextFormatCollection collection;
|
|---|
| 1590 | };
|
|---|
| 1591 |
|
|---|
| 1592 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1593 |
|
|---|
| 1594 | inline int Q3TextParagraph::length() const
|
|---|
| 1595 | {
|
|---|
| 1596 | return str->length();
|
|---|
| 1597 | }
|
|---|
| 1598 |
|
|---|
| 1599 | inline QRect Q3TextParagraph::rect() const
|
|---|
| 1600 | {
|
|---|
| 1601 | return r;
|
|---|
| 1602 | }
|
|---|
| 1603 |
|
|---|
| 1604 | inline int Q3TextCursor::index() const
|
|---|
| 1605 | {
|
|---|
| 1606 | return idx;
|
|---|
| 1607 | }
|
|---|
| 1608 |
|
|---|
| 1609 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1610 |
|
|---|
| 1611 | inline int Q3TextDocument::x() const
|
|---|
| 1612 | {
|
|---|
| 1613 | return cx;
|
|---|
| 1614 | }
|
|---|
| 1615 |
|
|---|
| 1616 | inline int Q3TextDocument::y() const
|
|---|
| 1617 | {
|
|---|
| 1618 | return cy;
|
|---|
| 1619 | }
|
|---|
| 1620 |
|
|---|
| 1621 | inline int Q3TextDocument::width() const
|
|---|
| 1622 | {
|
|---|
| 1623 | return qMax(cw, flow_->width());
|
|---|
| 1624 | }
|
|---|
| 1625 |
|
|---|
| 1626 | inline int Q3TextDocument::visibleWidth() const
|
|---|
| 1627 | {
|
|---|
| 1628 | return vw;
|
|---|
| 1629 | }
|
|---|
| 1630 |
|
|---|
| 1631 | inline Q3TextParagraph *Q3TextDocument::firstParagraph() const
|
|---|
| 1632 | {
|
|---|
| 1633 | return fParag;
|
|---|
| 1634 | }
|
|---|
| 1635 |
|
|---|
| 1636 | inline Q3TextParagraph *Q3TextDocument::lastParagraph() const
|
|---|
| 1637 | {
|
|---|
| 1638 | return lParag;
|
|---|
| 1639 | }
|
|---|
| 1640 |
|
|---|
| 1641 | inline void Q3TextDocument::setFirstParagraph(Q3TextParagraph *p)
|
|---|
| 1642 | {
|
|---|
| 1643 | fParag = p;
|
|---|
| 1644 | }
|
|---|
| 1645 |
|
|---|
| 1646 | inline void Q3TextDocument::setLastParagraph(Q3TextParagraph *p)
|
|---|
| 1647 | {
|
|---|
| 1648 | lParag = p;
|
|---|
| 1649 | }
|
|---|
| 1650 |
|
|---|
| 1651 | inline void Q3TextDocument::setWidth(int w)
|
|---|
| 1652 | {
|
|---|
| 1653 | cw = qMax(w, minw);
|
|---|
| 1654 | flow_->setWidth(cw);
|
|---|
| 1655 | vw = w;
|
|---|
| 1656 | }
|
|---|
| 1657 |
|
|---|
| 1658 | inline int Q3TextDocument::minimumWidth() const
|
|---|
| 1659 | {
|
|---|
| 1660 | return minw;
|
|---|
| 1661 | }
|
|---|
| 1662 |
|
|---|
| 1663 | inline void Q3TextDocument::setY(int y)
|
|---|
| 1664 | {
|
|---|
| 1665 | cy = y;
|
|---|
| 1666 | }
|
|---|
| 1667 |
|
|---|
| 1668 | inline int Q3TextDocument::leftMargin() const
|
|---|
| 1669 | {
|
|---|
| 1670 | return leftmargin;
|
|---|
| 1671 | }
|
|---|
| 1672 |
|
|---|
| 1673 | inline void Q3TextDocument::setLeftMargin(int lm)
|
|---|
| 1674 | {
|
|---|
| 1675 | leftmargin = lm;
|
|---|
| 1676 | }
|
|---|
| 1677 |
|
|---|
| 1678 | inline int Q3TextDocument::rightMargin() const
|
|---|
| 1679 | {
|
|---|
| 1680 | return rightmargin;
|
|---|
| 1681 | }
|
|---|
| 1682 |
|
|---|
| 1683 | inline void Q3TextDocument::setRightMargin(int rm)
|
|---|
| 1684 | {
|
|---|
| 1685 | rightmargin = rm;
|
|---|
| 1686 | }
|
|---|
| 1687 |
|
|---|
| 1688 | inline Q3TextPreProcessor *Q3TextDocument::preProcessor() const
|
|---|
| 1689 | {
|
|---|
| 1690 | return pProcessor;
|
|---|
| 1691 | }
|
|---|
| 1692 |
|
|---|
| 1693 | inline void Q3TextDocument::setPreProcessor(Q3TextPreProcessor * sh)
|
|---|
| 1694 | {
|
|---|
| 1695 | pProcessor = sh;
|
|---|
| 1696 | }
|
|---|
| 1697 |
|
|---|
| 1698 | inline void Q3TextDocument::setFormatter(Q3TextFormatter *f)
|
|---|
| 1699 | {
|
|---|
| 1700 | delete pFormatter;
|
|---|
| 1701 | pFormatter = f;
|
|---|
| 1702 | }
|
|---|
| 1703 |
|
|---|
| 1704 | inline Q3TextFormatter *Q3TextDocument::formatter() const
|
|---|
| 1705 | {
|
|---|
| 1706 | return pFormatter;
|
|---|
| 1707 | }
|
|---|
| 1708 |
|
|---|
| 1709 | inline void Q3TextDocument::setIndent(Q3TextIndent *i)
|
|---|
| 1710 | {
|
|---|
| 1711 | indenter = i;
|
|---|
| 1712 | }
|
|---|
| 1713 |
|
|---|
| 1714 | inline Q3TextIndent *Q3TextDocument::indent() const
|
|---|
| 1715 | {
|
|---|
| 1716 | return indenter;
|
|---|
| 1717 | }
|
|---|
| 1718 |
|
|---|
| 1719 | inline QColor Q3TextDocument::selectionColor(int id) const
|
|---|
| 1720 | {
|
|---|
| 1721 | const Q3TextDocument *p = this;
|
|---|
| 1722 | while (p->par)
|
|---|
| 1723 | p = p->par;
|
|---|
| 1724 | return p->selectionColors[id].background;
|
|---|
| 1725 | }
|
|---|
| 1726 |
|
|---|
| 1727 | inline QColor Q3TextDocument::selectionTextColor(int id) const
|
|---|
| 1728 | {
|
|---|
| 1729 | const Q3TextDocument *p = this;
|
|---|
| 1730 | while (p->par)
|
|---|
| 1731 | p = p->par;
|
|---|
| 1732 | return p->selectionColors[id].text;
|
|---|
| 1733 | }
|
|---|
| 1734 |
|
|---|
| 1735 | inline bool Q3TextDocument::hasSelectionTextColor(int id) const
|
|---|
| 1736 | {
|
|---|
| 1737 | const Q3TextDocument *p = this;
|
|---|
| 1738 | while (p->par)
|
|---|
| 1739 | p = p->par;
|
|---|
| 1740 | return p->selectionColors.contains(id);
|
|---|
| 1741 | }
|
|---|
| 1742 |
|
|---|
| 1743 | inline void Q3TextDocument::setSelectionColor(int id, const QColor &c)
|
|---|
| 1744 | {
|
|---|
| 1745 | Q3TextDocument *p = this;
|
|---|
| 1746 | while (p->par)
|
|---|
| 1747 | p = p->par;
|
|---|
| 1748 | p->selectionColors[id].background = c;
|
|---|
| 1749 | }
|
|---|
| 1750 |
|
|---|
| 1751 | inline void Q3TextDocument::setSelectionTextColor(int id, const QColor &c)
|
|---|
| 1752 | {
|
|---|
| 1753 | Q3TextDocument *p = this;
|
|---|
| 1754 | while (p->par)
|
|---|
| 1755 | p = p->par;
|
|---|
| 1756 | p->selectionColors[id].text = c;
|
|---|
| 1757 | }
|
|---|
| 1758 |
|
|---|
| 1759 | inline Q3TextFormatCollection *Q3TextDocument::formatCollection() const
|
|---|
| 1760 | {
|
|---|
| 1761 | return fCollection;
|
|---|
| 1762 | }
|
|---|
| 1763 |
|
|---|
| 1764 | inline int Q3TextDocument::alignment() const
|
|---|
| 1765 | {
|
|---|
| 1766 | return align;
|
|---|
| 1767 | }
|
|---|
| 1768 |
|
|---|
| 1769 | inline void Q3TextDocument::setAlignment(int a)
|
|---|
| 1770 | {
|
|---|
| 1771 | align = a;
|
|---|
| 1772 | }
|
|---|
| 1773 |
|
|---|
| 1774 | inline int *Q3TextDocument::tabArray() const
|
|---|
| 1775 | {
|
|---|
| 1776 | return tArray;
|
|---|
| 1777 | }
|
|---|
| 1778 |
|
|---|
| 1779 | inline int Q3TextDocument::tabStopWidth() const
|
|---|
| 1780 | {
|
|---|
| 1781 | return tStopWidth;
|
|---|
| 1782 | }
|
|---|
| 1783 |
|
|---|
| 1784 | inline void Q3TextDocument::setTabArray(int *a)
|
|---|
| 1785 | {
|
|---|
| 1786 | tArray = a;
|
|---|
| 1787 | }
|
|---|
| 1788 |
|
|---|
| 1789 | inline void Q3TextDocument::setTabStops(int tw)
|
|---|
| 1790 | {
|
|---|
| 1791 | tStopWidth = tw;
|
|---|
| 1792 | }
|
|---|
| 1793 |
|
|---|
| 1794 | inline QString Q3TextDocument::originalText() const
|
|---|
| 1795 | {
|
|---|
| 1796 | if (oTextValid)
|
|---|
| 1797 | return oText;
|
|---|
| 1798 | return text();
|
|---|
| 1799 | }
|
|---|
| 1800 |
|
|---|
| 1801 | inline void Q3TextDocument::setFlow(Q3TextFlow *f)
|
|---|
| 1802 | {
|
|---|
| 1803 | if (flow_)
|
|---|
| 1804 | delete flow_;
|
|---|
| 1805 | flow_ = f;
|
|---|
| 1806 | }
|
|---|
| 1807 |
|
|---|
| 1808 | inline void Q3TextDocument::takeFlow()
|
|---|
| 1809 | {
|
|---|
| 1810 | flow_ = 0;
|
|---|
| 1811 | }
|
|---|
| 1812 |
|
|---|
| 1813 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 1814 |
|
|---|
| 1815 | inline QColor Q3TextFormat::color() const
|
|---|
| 1816 | {
|
|---|
| 1817 | return col;
|
|---|
| 1818 | }
|
|---|
| 1819 |
|
|---|
| 1820 | inline QFont Q3TextFormat::font() const
|
|---|
| 1821 | {
|
|---|
| 1822 | return fn;
|
|---|
| 1823 | }
|
|---|
| 1824 |
|
|---|
| 1825 | inline bool Q3TextFormat::isMisspelled() const
|
|---|
| 1826 | {
|
|---|
| 1827 | return missp;
|
|---|
| 1828 | }
|
|---|
| 1829 |
|
|---|
| 1830 | inline Q3TextFormat::VerticalAlignment Q3TextFormat::vAlign() const
|
|---|
| 1831 | {
|
|---|
| 1832 | return ha;
|
|---|
| 1833 | }
|
|---|
| 1834 |
|
|---|
| 1835 | inline bool Q3TextFormat::operator==(const Q3TextFormat &f) const
|
|---|
| 1836 | {
|
|---|
| 1837 | return k == f.k;
|
|---|
| 1838 | }
|
|---|
| 1839 |
|
|---|
| 1840 | inline Q3TextFormatCollection *Q3TextFormat::parent() const
|
|---|
| 1841 | {
|
|---|
| 1842 | return collection;
|
|---|
| 1843 | }
|
|---|
| 1844 |
|
|---|
| 1845 | inline void Q3TextFormat::addRef()
|
|---|
| 1846 | {
|
|---|
| 1847 | ref++;
|
|---|
| 1848 | }
|
|---|
| 1849 |
|
|---|
| 1850 | inline void Q3TextFormat::removeRef()
|
|---|
| 1851 | {
|
|---|
| 1852 | ref--;
|
|---|
| 1853 | if (!collection)
|
|---|
| 1854 | return;
|
|---|
| 1855 | if (this == collection->defFormat)
|
|---|
| 1856 | return;
|
|---|
| 1857 | if (ref == 0)
|
|---|
| 1858 | collection->remove(this);
|
|---|
| 1859 | }
|
|---|
| 1860 |
|
|---|
| 1861 | inline const QString &Q3TextFormat::key() const
|
|---|
| 1862 | {
|
|---|
| 1863 | return k;
|
|---|
| 1864 | }
|
|---|
| 1865 |
|
|---|
| 1866 | inline bool Q3TextFormat::useLinkColor() const
|
|---|
| 1867 | {
|
|---|
| 1868 | return linkColor;
|
|---|
| 1869 | }
|
|---|
| 1870 |
|
|---|
| 1871 | inline Q3TextStringChar *Q3TextParagraph::at(int i) const
|
|---|
| 1872 | {
|
|---|
| 1873 | return &str->at(i);
|
|---|
| 1874 | }
|
|---|
| 1875 |
|
|---|
| 1876 | inline bool Q3TextParagraph::isValid() const
|
|---|
| 1877 | {
|
|---|
| 1878 | return invalid == -1;
|
|---|
| 1879 | }
|
|---|
| 1880 |
|
|---|
| 1881 | inline bool Q3TextParagraph::hasChanged() const
|
|---|
| 1882 | {
|
|---|
| 1883 | return changed;
|
|---|
| 1884 | }
|
|---|
| 1885 |
|
|---|
| 1886 | inline void Q3TextParagraph::setBackgroundColor(const QColor & c)
|
|---|
| 1887 | {
|
|---|
| 1888 | delete bgcol;
|
|---|
| 1889 | bgcol = new QColor(c);
|
|---|
| 1890 | setChanged(true);
|
|---|
| 1891 | }
|
|---|
| 1892 |
|
|---|
| 1893 | inline void Q3TextParagraph::clearBackgroundColor()
|
|---|
| 1894 | {
|
|---|
| 1895 | delete bgcol; bgcol = 0; setChanged(true);
|
|---|
| 1896 | }
|
|---|
| 1897 |
|
|---|
| 1898 | inline void Q3TextParagraph::append(const QString &s, bool reallyAtEnd)
|
|---|
| 1899 | {
|
|---|
| 1900 | if (reallyAtEnd) {
|
|---|
| 1901 | insert(str->length(), s);
|
|---|
| 1902 | } else {
|
|---|
| 1903 | int str_end = str->length() - 1;
|
|---|
| 1904 | insert(str_end > 0 ? str_end : 0, s);
|
|---|
| 1905 | }
|
|---|
| 1906 | }
|
|---|
| 1907 |
|
|---|
| 1908 | inline Q3TextParagraph *Q3TextParagraph::prev() const
|
|---|
| 1909 | {
|
|---|
| 1910 | return p;
|
|---|
| 1911 | }
|
|---|
| 1912 |
|
|---|
| 1913 | inline Q3TextParagraph *Q3TextParagraph::next() const
|
|---|
| 1914 | {
|
|---|
| 1915 | return n;
|
|---|
| 1916 | }
|
|---|
| 1917 |
|
|---|
| 1918 | inline bool Q3TextParagraph::hasAnySelection() const
|
|---|
| 1919 | {
|
|---|
| 1920 | return mSelections ? !selections().isEmpty() : false;
|
|---|
| 1921 | }
|
|---|
| 1922 |
|
|---|
| 1923 | inline void Q3TextParagraph::setEndState(int s)
|
|---|
| 1924 | {
|
|---|
| 1925 | if (s == state)
|
|---|
| 1926 | return;
|
|---|
| 1927 | state = s;
|
|---|
| 1928 | }
|
|---|
| 1929 |
|
|---|
| 1930 | inline int Q3TextParagraph::endState() const
|
|---|
| 1931 | {
|
|---|
| 1932 | return state;
|
|---|
| 1933 | }
|
|---|
| 1934 |
|
|---|
| 1935 | inline void Q3TextParagraph::setParagId(int i)
|
|---|
| 1936 | {
|
|---|
| 1937 | id = i;
|
|---|
| 1938 | }
|
|---|
| 1939 |
|
|---|
| 1940 | inline int Q3TextParagraph::paragId() const
|
|---|
| 1941 | {
|
|---|
| 1942 | if (id == -1)
|
|---|
| 1943 | qWarning("invalid parag id!!!!!!!! (%p)", (void*)this);
|
|---|
| 1944 | return id;
|
|---|
| 1945 | }
|
|---|
| 1946 |
|
|---|
| 1947 | inline bool Q3TextParagraph::firstPreProcess() const
|
|---|
| 1948 | {
|
|---|
| 1949 | return firstPProcess;
|
|---|
| 1950 | }
|
|---|
| 1951 |
|
|---|
| 1952 | inline void Q3TextParagraph::setFirstPreProcess(bool b)
|
|---|
| 1953 | {
|
|---|
| 1954 | firstPProcess = b;
|
|---|
| 1955 | }
|
|---|
| 1956 |
|
|---|
| 1957 | inline QMap<int, QTextLineStart*> &Q3TextParagraph::lineStartList()
|
|---|
| 1958 | {
|
|---|
| 1959 | return lineStarts;
|
|---|
| 1960 | }
|
|---|
| 1961 |
|
|---|
| 1962 | inline Q3TextString *Q3TextParagraph::string() const
|
|---|
| 1963 | {
|
|---|
| 1964 | return str;
|
|---|
| 1965 | }
|
|---|
| 1966 |
|
|---|
| 1967 | inline Q3TextParagraphPseudoDocument *Q3TextParagraph::pseudoDocument() const
|
|---|
| 1968 | {
|
|---|
| 1969 | if (hasdoc)
|
|---|
| 1970 | return 0;
|
|---|
| 1971 | return (Q3TextParagraphPseudoDocument*) docOrPseudo;
|
|---|
| 1972 | }
|
|---|
| 1973 |
|
|---|
| 1974 |
|
|---|
| 1975 | #ifndef QT_NO_TEXTCUSTOMITEM
|
|---|
| 1976 | inline Q3TextTableCell *Q3TextParagraph::tableCell() const
|
|---|
| 1977 | {
|
|---|
| 1978 | return hasdoc ? document()->tableCell () : 0;
|
|---|
| 1979 | }
|
|---|
| 1980 | #endif
|
|---|
| 1981 |
|
|---|
| 1982 | inline Q3TextCommandHistory *Q3TextParagraph::commands() const
|
|---|
| 1983 | {
|
|---|
| 1984 | return hasdoc ? document()->commands() : pseudoDocument()->commandHistory;
|
|---|
| 1985 | }
|
|---|
| 1986 |
|
|---|
| 1987 |
|
|---|
| 1988 | inline int Q3TextParagraph::alignment() const
|
|---|
| 1989 | {
|
|---|
| 1990 | return align;
|
|---|
| 1991 | }
|
|---|
| 1992 |
|
|---|
| 1993 | #ifndef QT_NO_TEXTCUSTOMITEM
|
|---|
| 1994 | inline void Q3TextParagraph::registerFloatingItem(Q3TextCustomItem *i)
|
|---|
| 1995 | {
|
|---|
| 1996 | floatingItems().append(i);
|
|---|
| 1997 | }
|
|---|
| 1998 |
|
|---|
| 1999 | inline void Q3TextParagraph::unregisterFloatingItem(Q3TextCustomItem *i)
|
|---|
| 2000 | {
|
|---|
| 2001 | floatingItems().removeAll(i);
|
|---|
| 2002 | }
|
|---|
| 2003 | #endif
|
|---|
| 2004 |
|
|---|
| 2005 | inline QBrush *Q3TextParagraph::background() const
|
|---|
| 2006 | {
|
|---|
| 2007 | #ifndef QT_NO_TEXTCUSTOMITEM
|
|---|
| 2008 | return tableCell() ? tableCell()->backGround() : 0;
|
|---|
| 2009 | #else
|
|---|
| 2010 | return 0;
|
|---|
| 2011 | #endif
|
|---|
| 2012 | }
|
|---|
| 2013 |
|
|---|
| 2014 | inline int Q3TextParagraph::documentWidth() const
|
|---|
| 2015 | {
|
|---|
| 2016 | return hasdoc ? document()->width() : pseudoDocument()->docRect.width();
|
|---|
| 2017 | }
|
|---|
| 2018 |
|
|---|
| 2019 | inline int Q3TextParagraph::documentVisibleWidth() const
|
|---|
| 2020 | {
|
|---|
| 2021 | return hasdoc ? document()->visibleWidth() : pseudoDocument()->docRect.width();
|
|---|
| 2022 | }
|
|---|
| 2023 |
|
|---|
| 2024 | inline int Q3TextParagraph::documentX() const
|
|---|
| 2025 | {
|
|---|
| 2026 | return hasdoc ? document()->x() : pseudoDocument()->docRect.x();
|
|---|
| 2027 | }
|
|---|
| 2028 |
|
|---|
| 2029 | inline int Q3TextParagraph::documentY() const
|
|---|
| 2030 | {
|
|---|
| 2031 | return hasdoc ? document()->y() : pseudoDocument()->docRect.y();
|
|---|
| 2032 | }
|
|---|
| 2033 |
|
|---|
| 2034 | inline void Q3TextParagraph::setExtraData(Q3TextParagraphData *data)
|
|---|
| 2035 | {
|
|---|
| 2036 | eData = data;
|
|---|
| 2037 | }
|
|---|
| 2038 |
|
|---|
| 2039 | inline Q3TextParagraphData *Q3TextParagraph::extraData() const
|
|---|
| 2040 | {
|
|---|
| 2041 | return eData;
|
|---|
| 2042 | }
|
|---|
| 2043 |
|
|---|
| 2044 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 2045 |
|
|---|
| 2046 | inline void Q3TextFormatCollection::setDefaultFormat(Q3TextFormat *f)
|
|---|
| 2047 | {
|
|---|
| 2048 | defFormat = f;
|
|---|
| 2049 | }
|
|---|
| 2050 |
|
|---|
| 2051 | inline Q3TextFormat *Q3TextFormatCollection::defaultFormat() const
|
|---|
| 2052 | {
|
|---|
| 2053 | return defFormat;
|
|---|
| 2054 | }
|
|---|
| 2055 |
|
|---|
| 2056 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|---|
| 2057 |
|
|---|
| 2058 | inline Q3TextFormat *Q3TextStringChar::format() const
|
|---|
| 2059 | {
|
|---|
| 2060 | return (type == Regular) ? p.format : p.custom->format;
|
|---|
| 2061 | }
|
|---|
| 2062 |
|
|---|
| 2063 |
|
|---|
| 2064 | #ifndef QT_NO_TEXTCUSTOMITEM
|
|---|
| 2065 | inline Q3TextCustomItem *Q3TextStringChar::customItem() const
|
|---|
| 2066 | {
|
|---|
| 2067 | return isCustom() ? p.custom->custom : 0;
|
|---|
| 2068 | }
|
|---|
| 2069 | #endif
|
|---|
| 2070 |
|
|---|
| 2071 | inline int Q3TextStringChar::height() const
|
|---|
| 2072 | {
|
|---|
| 2073 | #ifndef QT_NO_TEXTCUSTOMITEM
|
|---|
| 2074 | return !isCustom() ? format()->height() : (customItem()->placement() == Q3TextCustomItem::PlaceInline ? customItem()->height : 0);
|
|---|
| 2075 | #else
|
|---|
| 2076 | return format()->height();
|
|---|
| 2077 | #endif
|
|---|
| 2078 | }
|
|---|
| 2079 |
|
|---|
| 2080 | inline int Q3TextStringChar::ascent() const
|
|---|
| 2081 | {
|
|---|
| 2082 | #ifndef QT_NO_TEXTCUSTOMITEM
|
|---|
| 2083 | return !isCustom() ? format()->ascent() : (customItem()->placement() == Q3TextCustomItem::PlaceInline ? customItem()->ascent() : 0);
|
|---|
| 2084 | #else
|
|---|
| 2085 | return format()->ascent();
|
|---|
| 2086 | #endif
|
|---|
| 2087 | }
|
|---|
| 2088 |
|
|---|
| 2089 | inline int Q3TextStringChar::descent() const
|
|---|
| 2090 | {
|
|---|
| 2091 | #ifndef QT_NO_TEXTCUSTOMITEM
|
|---|
| 2092 | return !isCustom() ? format()->descent() : 0;
|
|---|
| 2093 | #else
|
|---|
| 2094 | return format()->descent();
|
|---|
| 2095 | #endif
|
|---|
| 2096 | }
|
|---|
| 2097 |
|
|---|
| 2098 | #endif // QT_NO_RICHTEXT
|
|---|
| 2099 |
|
|---|
| 2100 | QT_END_NAMESPACE
|
|---|
| 2101 |
|
|---|
| 2102 | #endif // Q3RICHTEXT_P_H
|
|---|