00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Q3RICHTEXT_P_H
00025 #define Q3RICHTEXT_P_H
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "QtGui/qapplication.h"
00039 #include "QtGui/qcolor.h"
00040 #include "QtCore/qhash.h"
00041 #include "QtGui/qfont.h"
00042 #include "QtGui/qfontmetrics.h"
00043 #include "QtGui/qlayout.h"
00044 #include "QtCore/qmap.h"
00045 #include "QtCore/qvector.h"
00046 #include "QtCore/qstack.h"
00047 #include "QtCore/qlist.h"
00048 #include "QtCore/qobject.h"
00049 #include "QtGui/qpainter.h"
00050 #include "QtGui/qpixmap.h"
00051 #include "QtCore/qrect.h"
00052 #include "QtCore/qsize.h"
00053 #include "QtCore/qstring.h"
00054 #include "QtCore/qstringlist.h"
00055 #include "Qt3Support/q3stylesheet.h"
00056 #include "Qt3Support/q3mimefactory.h"
00057
00058 #ifndef QT_NO_RICHTEXT
00059
00060 class Q3TextDocument;
00061 class Q3TextString;
00062 class Q3TextPreProcessor;
00063 class Q3TextFormat;
00064 class Q3TextCursor;
00065 class Q3TextParagraph;
00066 class Q3TextFormatter;
00067 class Q3TextIndent;
00068 class Q3TextFormatCollection;
00069 class Q3StyleSheetItem;
00070 #ifndef QT_NO_TEXTCUSTOMITEM
00071 class Q3TextCustomItem;
00072 #endif
00073 class Q3TextFlow;
00074 struct QBidiContext;
00075
00076
00077
00078 class Q_COMPAT_EXPORT Q3TextStringChar
00079 {
00080 friend class Q3TextString;
00081
00082 public:
00083
00084 Q3TextStringChar() : nobreak(false), lineStart(0), type(Regular) {p.format=0;}
00085 ~Q3TextStringChar();
00086
00087 struct CustomData
00088 {
00089 Q3TextFormat *format;
00090 #ifndef QT_NO_TEXTCUSTOMITEM
00091 Q3TextCustomItem *custom;
00092 #endif
00093 QString anchorName;
00094 QString anchorHref;
00095 };
00096 enum Type { Regular=0, Custom=1, Anchor=2, CustomAnchor=3 };
00097
00098 QChar c;
00099
00100 uchar softBreak :1;
00101 uchar whiteSpace :1;
00102 uchar charStop :1;
00103 uchar nobreak :1;
00104
00105 uchar lineStart : 1;
00106 uchar type : 2;
00107 uchar bidiLevel :7;
00108 uchar rightToLeft : 1;
00109
00110 int x;
00111 union {
00112 Q3TextFormat* format;
00113 CustomData* custom;
00114 } p;
00115
00116
00117 int height() const;
00118 int ascent() const;
00119 int descent() const;
00120 bool isCustom() const { return (type & Custom) != 0; }
00121 Q3TextFormat *format() const;
00122 #ifndef QT_NO_TEXTCUSTOMITEM
00123 Q3TextCustomItem *customItem() const;
00124 #endif
00125 void setFormat(Q3TextFormat *f);
00126 #ifndef QT_NO_TEXTCUSTOMITEM
00127 void setCustomItem(Q3TextCustomItem *i);
00128 #endif
00129
00130 #ifndef QT_NO_TEXTCUSTOMITEM
00131 void loseCustomItem();
00132 #endif
00133
00134
00135 bool isAnchor() const { return (type & Anchor) != 0; }
00136 bool isLink() const { return isAnchor() && p.custom->anchorHref.count(); }
00137 QString anchorName() const;
00138 QString anchorHref() const;
00139 void setAnchor(const QString& name, const QString& href);
00140
00141 Q3TextStringChar(const Q3TextStringChar &) {
00142 Q_ASSERT(false);
00143 }
00144 private:
00145 Q3TextStringChar &operator=(const Q3TextStringChar &) {
00146
00147 return *this;
00148 }
00149 friend class Q3TextParagraph;
00150 };
00151
00152 Q_DECLARE_TYPEINFO(Q3TextStringChar, Q_PRIMITIVE_TYPE);
00153
00154 class Q_COMPAT_EXPORT Q3TextString
00155 {
00156 public:
00157
00158 Q3TextString();
00159 Q3TextString(const Q3TextString &s);
00160 virtual ~Q3TextString();
00161
00162 static QString toString(const QVector<Q3TextStringChar> &data);
00163 QString toString() const;
00164
00165 inline Q3TextStringChar &at(int i) const {
00166 return const_cast<Q3TextString *>(this)->data[i];
00167 }
00168 inline int length() const { return data.size(); }
00169
00170 int width(int idx) const;
00171
00172 void insert(int index, const QString &s, Q3TextFormat *f);
00173 void insert(int index, const QChar *unicode, int len, Q3TextFormat *f);
00174 void insert(int index, Q3TextStringChar *c, bool doAddRefFormat = false);
00175 void truncate(int index);
00176 void remove(int index, int len);
00177 void clear();
00178
00179 void setFormat(int index, Q3TextFormat *f, bool useCollection);
00180
00181 void setBidi(bool b) { bidi = b; }
00182 bool isBidi() const;
00183 bool isRightToLeft() const;
00184 QChar::Direction direction() const;
00185 void setDirection(QChar::Direction dr) { rightToLeft = (dr == QChar::DirR); bidiDirty = true; }
00186
00187 QVector<Q3TextStringChar> rawData() const { return data; }
00188
00189 void operator=(const QString &s) { clear(); insert(0, s, 0); }
00190 void operator+=(const QString &s) { insert(length(), s, 0); }
00191 void prepend(const QString &s) { insert(0, s, 0); }
00192 int appendParagraphs( Q3TextParagraph *start, Q3TextParagraph *end );
00193
00194
00195 bool validCursorPosition(int idx);
00196 int nextCursorPosition(int idx);
00197 int previousCursorPosition(int idx);
00198
00199 private:
00200 void checkBidi() const;
00201
00202 QVector<Q3TextStringChar> data;
00203 QString stringCache;
00204 uint bidiDirty : 1;
00205 uint bidi : 1;
00206 uint rightToLeft : 1;
00207 };
00208
00209 inline bool Q3TextString::isBidi() const
00210 {
00211 if (bidiDirty)
00212 checkBidi();
00213 return bidi;
00214 }
00215
00216 inline bool Q3TextString::isRightToLeft() const
00217 {
00218 if (bidiDirty)
00219 checkBidi();
00220 return rightToLeft;
00221 }
00222
00223 inline QString Q3TextString::toString() const
00224 {
00225 if (bidiDirty)
00226 checkBidi();
00227 return stringCache;
00228 }
00229
00230 inline QChar::Direction Q3TextString::direction() const
00231 {
00232 return rightToLeft ? QChar::DirR : QChar::DirL;
00233 }
00234
00235 inline int Q3TextString::nextCursorPosition(int next)
00236 {
00237 if (bidiDirty)
00238 checkBidi();
00239
00240 const Q3TextStringChar *c = data.data();
00241 int len = length();
00242
00243 if (next < len - 1) {
00244 next++;
00245 while (next < len - 1 && !c[next].charStop)
00246 next++;
00247 }
00248 return next;
00249 }
00250
00251 inline int Q3TextString::previousCursorPosition(int prev)
00252 {
00253 if (bidiDirty)
00254 checkBidi();
00255
00256 const Q3TextStringChar *c = data.data();
00257
00258 if (prev) {
00259 prev--;
00260 while (prev && !c[prev].charStop)
00261 prev--;
00262 }
00263 return prev;
00264 }
00265
00266 inline bool Q3TextString::validCursorPosition(int idx)
00267 {
00268 if (bidiDirty)
00269 checkBidi();
00270
00271 return (at(idx).charStop);
00272 }
00273
00274
00275
00276 class Q_COMPAT_EXPORT Q3TextCursor
00277 {
00278 public:
00279 Q3TextCursor(Q3TextDocument * = 0);
00280 Q3TextCursor(const Q3TextCursor &c);
00281 Q3TextCursor &operator=(const Q3TextCursor &c);
00282 virtual ~Q3TextCursor();
00283
00284 bool operator==(const Q3TextCursor &c) const;
00285 bool operator!=(const Q3TextCursor &c) const { return !(*this == c); }
00286
00287 inline Q3TextParagraph *paragraph() const { return para; }
00288
00289 Q3TextDocument *document() const;
00290 int index() const;
00291
00292 void gotoPosition(Q3TextParagraph* p, int index = 0);
00293 void setIndex(int index) { gotoPosition(paragraph(), index); }
00294 void setParagraph(Q3TextParagraph*p) { gotoPosition(p, 0); }
00295
00296 void gotoLeft();
00297 void gotoRight();
00298 void gotoNextLetter();
00299 void gotoPreviousLetter();
00300 void gotoUp();
00301 void gotoDown();
00302 void gotoLineEnd();
00303 void gotoLineStart();
00304 void gotoHome();
00305 void gotoEnd();
00306 void gotoPageUp(int visibleHeight);
00307 void gotoPageDown(int visibleHeight);
00308 void gotoNextWord(bool onlySpace = false);
00309 void gotoPreviousWord(bool onlySpace = false);
00310 void gotoWordLeft();
00311 void gotoWordRight();
00312
00313 void insert(const QString &s, bool checkNewLine, QVector<Q3TextStringChar> *formatting = 0);
00314 void splitAndInsertEmptyParagraph(bool ind = true, bool updateIds = true);
00315 bool remove();
00316 bool removePreviousChar();
00317 void indent();
00318
00319 bool atParagStart();
00320 bool atParagEnd();
00321
00322 int x() const;
00323 int y() const;
00324
00325 int globalX() const;
00326 int globalY() const;
00327
00328 Q3TextParagraph *topParagraph() const { return paras.isEmpty() ? para : paras.first(); }
00329 int offsetX() const { return ox; }
00330 int offsetY() const { return oy; }
00331 int totalOffsetX() const;
00332 int totalOffsetY() const;
00333
00334 bool place(const QPoint &pos, Q3TextParagraph *s) { return place(pos, s, false); }
00335 bool place(const QPoint &pos, Q3TextParagraph *s, bool link);
00336 void restoreState();
00337
00338
00339 int nestedDepth() const { return (int)indices.count(); }
00340 void oneUp() { if (!indices.isEmpty()) pop(); }
00341 void setValid(bool b) { valid = b; }
00342 bool isValid() const { return valid; }
00343
00344 void fixCursorPosition();
00345 private:
00346 enum Operation { EnterBegin, EnterEnd, Next, Prev, Up, Down };
00347
00348 void push();
00349 void pop();
00350 bool processNesting(Operation op);
00351 void invalidateNested();
00352 void gotoIntoNested(const QPoint &globalPos);
00353
00354 Q3TextParagraph *para;
00355 int idx, tmpX;
00356 int ox, oy;
00357 QStack<int> indices;
00358 QStack<Q3TextParagraph*> paras;
00359 QStack<int> xOffsets;
00360 QStack<int> yOffsets;
00361 uint valid : 1;
00362
00363 };
00364
00365
00366
00367 class Q_COMPAT_EXPORT Q3TextCommand
00368 {
00369 public:
00370 enum Commands { Invalid, Insert, Delete, Format, Style };
00371
00372 Q3TextCommand(Q3TextDocument *dc) : doc(dc), cursor(dc) {}
00373 virtual ~Q3TextCommand();
00374
00375 virtual Commands type() const;
00376
00377 virtual Q3TextCursor *execute(Q3TextCursor *c) = 0;
00378 virtual Q3TextCursor *unexecute(Q3TextCursor *c) = 0;
00379
00380 protected:
00381 Q3TextDocument *doc;
00382 Q3TextCursor cursor;
00383
00384 };
00385
00386 class Q_COMPAT_EXPORT Q3TextCommandHistory
00387 {
00388 public:
00389 Q3TextCommandHistory(int s) : current(-1), steps(s) { }
00390 virtual ~Q3TextCommandHistory();
00391
00392 void clear();
00393
00394 void addCommand(Q3TextCommand *cmd);
00395 Q3TextCursor *undo(Q3TextCursor *c);
00396 Q3TextCursor *redo(Q3TextCursor *c);
00397
00398 bool isUndoAvailable();
00399 bool isRedoAvailable();
00400
00401 void setUndoDepth(int depth) { steps = depth; }
00402 int undoDepth() const { return steps; }
00403
00404 int historySize() const { return history.count(); }
00405 int currentPosition() const { return current; }
00406
00407 private:
00408 QList<Q3TextCommand *> history;
00409 int current, steps;
00410 };
00411
00412 inline Q3TextCommandHistory::~Q3TextCommandHistory()
00413 {
00414 clear();
00415 }
00416
00417
00418
00419 #ifndef QT_NO_TEXTCUSTOMITEM
00420 class Q_COMPAT_EXPORT Q3TextCustomItem
00421 {
00422 public:
00423 Q3TextCustomItem(Q3TextDocument *p)
00424 : xpos(0), ypos(-1), width(-1), height(0), parent(p)
00425 {}
00426 virtual ~Q3TextCustomItem();
00427 virtual void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
00428 const QPalette &pal, bool selected) = 0;
00429
00430 virtual void adjustToPainter(QPainter*);
00431
00432 enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
00433 virtual Placement placement() const;
00434 bool placeInline() { return placement() == PlaceInline; }
00435
00436 virtual bool ownLine() const;
00437 virtual void resize(int nwidth);
00438 virtual void invalidate();
00439 virtual int ascent() const { return height; }
00440
00441 virtual bool isNested() const;
00442 virtual int minimumWidth() const;
00443
00444 virtual QString richText() const;
00445
00446 int xpos;
00447 int ypos;
00448 int width;
00449 int height;
00450
00451 QRect geometry() const { return QRect(xpos, ypos, width, height); }
00452
00453 virtual bool enter(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy, bool atEnd = false);
00454 virtual bool enterAt(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy, const QPoint &);
00455 virtual bool next(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
00456 virtual bool prev(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
00457 virtual bool down(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
00458 virtual bool up(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
00459
00460 void setParagraph(Q3TextParagraph *p) { parag = p; }
00461 Q3TextParagraph *paragraph() const { return parag; }
00462
00463 Q3TextDocument *parent;
00464 Q3TextParagraph *parag;
00465
00466 virtual void pageBreak(int y, Q3TextFlow* flow);
00467 };
00468 #endif
00469
00470
00471 #ifndef QT_NO_TEXTCUSTOMITEM
00472 class Q_COMPAT_EXPORT Q3TextImage : public Q3TextCustomItem
00473 {
00474 public:
00475 Q3TextImage(Q3TextDocument *p, const QMap<QString, QString> &attr, const QString& context,
00476 Q3MimeSourceFactory &factory);
00477 virtual ~Q3TextImage();
00478
00479 Placement placement() const { return place; }
00480 void adjustToPainter(QPainter*);
00481 int minimumWidth() const { return width; }
00482
00483 QString richText() const;
00484
00485 void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
00486 const QPalette &pal, bool selected);
00487
00488 private:
00489 QRegion* reg;
00490 QPixmap pm;
00491 Placement place;
00492 int tmpwidth, tmpheight;
00493 QMap<QString, QString> attributes;
00494 QString imgId;
00495
00496 };
00497 #endif
00498
00499 #ifndef QT_NO_TEXTCUSTOMITEM
00500 class Q_COMPAT_EXPORT Q3TextHorizontalLine : public Q3TextCustomItem
00501 {
00502 public:
00503 Q3TextHorizontalLine(Q3TextDocument *p, const QMap<QString, QString> &attr, const QString& context,
00504 Q3MimeSourceFactory &factory);
00505 virtual ~Q3TextHorizontalLine();
00506
00507 void adjustToPainter(QPainter*);
00508 void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
00509 const QPalette &pal, bool selected);
00510 QString richText() const;
00511
00512 bool ownLine() const { return true; }
00513
00514 private:
00515 int tmpheight;
00516 QColor color;
00517 bool shade;
00518
00519 };
00520 #endif
00521
00522 class Q_COMPAT_EXPORT Q3TextFlow
00523 {
00524 friend class Q3TextDocument;
00525 #ifndef QT_NO_TEXTCUSTOMITEM
00526 friend class Q3TextTableCell;
00527 #endif
00528
00529 public:
00530 Q3TextFlow();
00531 virtual ~Q3TextFlow();
00532
00533 virtual void setWidth(int width);
00534 int width() const;
00535
00536 virtual void setPageSize(int ps);
00537 int pageSize() const { return pagesize; }
00538
00539 virtual int adjustLMargin(int yp, int h, int margin, int space);
00540 virtual int adjustRMargin(int yp, int h, int margin, int space);
00541
00542 #ifndef QT_NO_TEXTCUSTOMITEM
00543 virtual void registerFloatingItem(Q3TextCustomItem* item);
00544 virtual void unregisterFloatingItem(Q3TextCustomItem* item);
00545 #endif
00546 virtual QRect boundingRect() const;
00547 virtual void drawFloatingItems(QPainter* p, int cx, int cy, int cw, int ch,
00548 const QPalette &pal, bool selected);
00549
00550 virtual int adjustFlow(int y, int w, int h);
00551
00552 virtual bool isEmpty();
00553
00554 void clear();
00555
00556 private:
00557 int w;
00558 int pagesize;
00559
00560 #ifndef QT_NO_TEXTCUSTOMITEM
00561 QList<Q3TextCustomItem *> leftItems;
00562 QList<Q3TextCustomItem *> rightItems;
00563 #endif
00564 };
00565
00566 inline int Q3TextFlow::width() const { return w; }
00567
00568 #ifndef QT_NO_TEXTCUSTOMITEM
00569 class Q3TextTable;
00570
00571 class Q_COMPAT_EXPORT Q3TextTableCell : public QLayoutItem
00572 {
00573 friend class Q3TextTable;
00574
00575 public:
00576 Q3TextTableCell(Q3TextTable* table,
00577 int row, int column,
00578 const QMap<QString, QString> &attr,
00579 const Q3StyleSheetItem* style,
00580 const Q3TextFormat& fmt, const QString& context,
00581 Q3MimeSourceFactory &factory, Q3StyleSheet *sheet, const QString& doc);
00582 virtual ~Q3TextTableCell();
00583
00584 QSize sizeHint() const ;
00585 QSize minimumSize() const ;
00586 QSize maximumSize() const ;
00587 Qt::Orientations expandingDirections() const;
00588 bool isEmpty() const;
00589 void setGeometry(const QRect&) ;
00590 QRect geometry() const;
00591
00592 bool hasHeightForWidth() const;
00593 int heightForWidth(int) const;
00594
00595 void adjustToPainter(QPainter*);
00596
00597 int row() const { return row_; }
00598 int column() const { return col_; }
00599 int rowspan() const { return rowspan_; }
00600 int colspan() const { return colspan_; }
00601 int stretch() const { return stretch_; }
00602
00603 Q3TextDocument* richText() const { return richtext; }
00604 Q3TextTable* table() const { return parent; }
00605
00606 void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
00607 const QPalette &cg, bool selected);
00608
00609 QBrush *backGround() const { return background; }
00610 virtual void invalidate();
00611
00612 int verticalAlignmentOffset() const;
00613 int horizontalAlignmentOffset() const;
00614
00615 private:
00616 QRect geom;
00617 Q3TextTable* parent;
00618 Q3TextDocument* richtext;
00619 int row_;
00620 int col_;
00621 int rowspan_;
00622 int colspan_;
00623 int stretch_;
00624 int maxw;
00625 int minw;
00626 bool hasFixedWidth;
00627 QBrush *background;
00628 int cached_width;
00629 int cached_sizehint;
00630 QMap<QString, QString> attributes;
00631 int align;
00632 };
00633 #endif
00634
00635
00636 #ifndef QT_NO_TEXTCUSTOMITEM
00637 class Q_COMPAT_EXPORT Q3TextTable: public Q3TextCustomItem
00638 {
00639 friend class Q3TextTableCell;
00640
00641 public:
00642 Q3TextTable(Q3TextDocument *p, const QMap<QString, QString> &attr);
00643 virtual ~Q3TextTable();
00644
00645 void adjustToPainter(QPainter *p);
00646 void pageBreak(int y, Q3TextFlow* flow);
00647 void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
00648 const QPalette &pal, bool selected);
00649
00650 bool noErase() const { return true; }
00651 bool ownLine() const { return true; }
00652 Placement placement() const { return place; }
00653 bool isNested() const { return true; }
00654 void resize(int nwidth);
00655 virtual void invalidate();
00656
00657 virtual bool enter(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy, bool atEnd = false);
00658 virtual bool enterAt(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy, const QPoint &pos);
00659 virtual bool next(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
00660 virtual bool prev(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
00661 virtual bool down(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
00662 virtual bool up(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *¶g, int &idx, int &ox, int &oy);
00663
00664 QString richText() const;
00665
00666 int minimumWidth() const;
00667
00668 QList<Q3TextTableCell *> tableCells() const { return cells; }
00669
00670 bool isStretching() const { return stretch; }
00671
00672 private:
00673 void format(int w);
00674 void addCell(Q3TextTableCell* cell);
00675
00676 private:
00677 QGridLayout* layout;
00678 QList<Q3TextTableCell *> cells;
00679 int cachewidth;
00680 int fixwidth;
00681 int cellpadding;
00682 int cellspacing;
00683 int border;
00684 int outerborder;
00685 int stretch;
00686 int innerborder;
00687 int us_cp, us_ib, us_b, us_ob, us_cs;
00688 int us_fixwidth;
00689 QMap<QString, QString> attributes;
00690 QMap<Q3TextCursor*, int> currCell;
00691 Placement place;
00692 void adjustCells(int y , int shift);
00693 int pageBreakFor;
00694 };
00695 #endif
00696
00697
00698 #ifndef QT_NO_TEXTCUSTOMITEM
00699 class Q3TextTableCell;
00700 class Q3TextParagraph;
00701 #endif
00702
00703 struct Q_COMPAT_EXPORT Q3TextDocumentSelection
00704 {
00705 Q3TextCursor startCursor, endCursor;
00706 bool swapped;
00707 Q_DUMMY_COMPARISON_OPERATOR(Q3TextDocumentSelection)
00708 };
00709
00710 class Q_COMPAT_EXPORT Q3TextDocument : public QObject
00711 {
00712 Q_OBJECT
00713
00714 #ifndef QT_NO_TEXTCUSTOMITEM
00715 friend class Q3TextTableCell;
00716 #endif
00717 friend class Q3TextCursor;
00718 friend class Q3TextEdit;
00719 friend class Q3TextParagraph;
00720
00721 public:
00722 enum SelectionIds {
00723 Standard = 0,
00724 Temp = 32000
00725
00726 };
00727
00728 Q3TextDocument(Q3TextDocument *p);
00729 virtual ~Q3TextDocument();
00730
00731 Q3TextDocument *parent() const { return par; }
00732 Q3TextParagraph *parentParagraph() const { return parentPar; }
00733
00734 void setText(const QString &text, const QString &context);
00735 QMap<QString, QString> attributes() const { return attribs; }
00736 void setAttributes(const QMap<QString, QString> &attr) { attribs = attr; }
00737
00738 QString text() const;
00739 QString text(int parag) const;
00740 QString originalText() const;
00741
00742 int x() const;
00743 int y() const;
00744 int width() const;
00745 int widthUsed() const;
00746 int visibleWidth() const;
00747 int height() const;
00748 void setWidth(int w);
00749 int minimumWidth() const;
00750 bool setMinimumWidth(int needed, int used = -1, Q3TextParagraph *parag = 0);
00751
00752 void setY(int y);
00753 int leftMargin() const;
00754 void setLeftMargin(int lm);
00755 int rightMargin() const;
00756 void setRightMargin(int rm);
00757
00758 Q3TextParagraph *firstParagraph() const;
00759 Q3TextParagraph *lastParagraph() const;
00760 void setFirstParagraph(Q3TextParagraph *p);
00761 void setLastParagraph(Q3TextParagraph *p);
00762
00763 void invalidate();
00764
00765 void setPreProcessor(Q3TextPreProcessor *sh);
00766 Q3TextPreProcessor *preProcessor() const;
00767
00768 void setFormatter(Q3TextFormatter *f);
00769 Q3TextFormatter *formatter() const;
00770
00771 void setIndent(Q3TextIndent *i);
00772 Q3TextIndent *indent() const;
00773
00774 QColor selectionColor(int id) const;
00775 QColor selectionTextColor(int id) const;
00776 bool hasSelectionTextColor(int id) const;
00777 void setSelectionColor(int id, const QColor &c);
00778 void setSelectionTextColor(int id, const QColor &b);
00779 bool hasSelection(int id, bool visible = false) const;
00780 void setSelectionStart(int id, const Q3TextCursor &cursor);
00781 bool setSelectionEnd(int id, const Q3TextCursor &cursor);
00782 void selectAll(int id);
00783 bool removeSelection(int id);
00784 void selectionStart(int id, int ¶gId, int &index);
00785 Q3TextCursor selectionStartCursor(int id);
00786 Q3TextCursor selectionEndCursor(int id);
00787 void selectionEnd(int id, int ¶gId, int &index);
00788 void setFormat(int id, Q3TextFormat *f, int flags);
00789 int numSelections() const { return nSelections; }
00790 void addSelection(int id);
00791
00792 QString selectedText(int id, bool asRichText = false) const;
00793 void removeSelectedText(int id, Q3TextCursor *cursor);
00794 void indentSelection(int id);
00795
00796 Q3TextParagraph *paragAt(int i) const;
00797
00798 void addCommand(Q3TextCommand *cmd);
00799 Q3TextCursor *undo(Q3TextCursor *c = 0);
00800 Q3TextCursor *redo(Q3TextCursor *c = 0);
00801 Q3TextCommandHistory *commands() const { return commandHistory; }
00802
00803 Q3TextFormatCollection *formatCollection() const;
00804
00805 bool find(Q3TextCursor &cursor, const QString &expr, bool cs, bool wo, bool forward);
00806
00807 void setTextFormat(Qt::TextFormat f);
00808 Qt::TextFormat textFormat() const;
00809
00810 bool inSelection(int selId, const QPoint &pos) const;
00811
00812 Q3StyleSheet *styleSheet() const { return sheet_; }
00813 #ifndef QT_NO_MIME
00814 Q3MimeSourceFactory *mimeSourceFactory() const { return factory_; }
00815 #endif
00816 QString context() const { return contxt; }
00817
00818 void setStyleSheet(Q3StyleSheet *s);
00819 void setDefaultFormat(const QFont &font, const QColor &color);
00820 #ifndef QT_NO_MIME
00821 void setMimeSourceFactory(Q3MimeSourceFactory *f) { if (f) factory_ = f; }
00822 #endif
00823 void setContext(const QString &c) { if (!c.isEmpty()) contxt = c; }
00824
00825 void setUnderlineLinks(bool b);
00826 bool underlineLinks() const { return underlLinks; }
00827
00828 void setPaper(QBrush *brush) { if (backBrush) delete backBrush; backBrush = brush; }
00829 QBrush *paper() const { return backBrush; }
00830
00831 void doLayout(QPainter *p, int w);
00832 void draw(QPainter *p, const QRect& rect, const QPalette &pal, const QBrush *paper = 0);
00833
00834 void drawParagraph(QPainter *p, Q3TextParagraph *parag, int cx, int cy, int cw, int ch,
00835 QPixmap *&doubleBuffer, const QPalette &pal,
00836 bool drawCursor, Q3TextCursor *cursor, bool resetChanged = true);
00837 Q3TextParagraph *draw(QPainter *p, int cx, int cy, int cw, int ch, const QPalette &pal,
00838 bool onlyChanged = false, bool drawCursor = false, Q3TextCursor *cursor = 0,
00839 bool resetChanged = true);
00840
00841 #ifndef QT_NO_TEXTCUSTOMITEM
00842 static Q3TextCustomItem* tag(Q3StyleSheet *sheet, const QString& name,
00843 const QMap<QString, QString> &attr,
00844 const QString& context,
00845 const Q3MimeSourceFactory& factory,
00846 bool emptyTag, Q3TextDocument *doc);
00847 #endif
00848
00849 #ifndef QT_NO_TEXTCUSTOMITEM
00850 void registerCustomItem(Q3TextCustomItem *i, Q3TextParagraph *p);
00851 void unregisterCustomItem(Q3TextCustomItem *i, Q3TextParagraph *p);
00852 #endif
00853
00854 void setFlow(Q3TextFlow *f);
00855 void takeFlow();
00856 Q3TextFlow *flow() const { return flow_; }
00857 bool isPageBreakEnabled() const { return pages; }
00858 void setPageBreakEnabled(bool b) { pages = b; }
00859
00860 void setUseFormatCollection(bool b) { useFC = b; }
00861 bool useFormatCollection() const { return useFC; }
00862
00863 #ifndef QT_NO_TEXTCUSTOMITEM
00864 Q3TextTableCell *tableCell() const { return tc; }
00865 void setTableCell(Q3TextTableCell *c) { tc = c; }
00866 #endif
00867
00868 void setPlainText(const QString &text);
00869 void setRichText(const QString &text, const QString &context, const Q3TextFormat *initialFormat = 0);
00870 QString richText() const;
00871 QString plainText() const;
00872
00873 bool focusNextPrevChild(bool next);
00874
00875 int alignment() const;
00876 void setAlignment(int a);
00877
00878 int *tabArray() const;
00879 int tabStopWidth() const;
00880 void setTabArray(int *a);
00881 void setTabStops(int tw);
00882
00883 void setUndoDepth(int depth) { commandHistory->setUndoDepth(depth); }
00884 int undoDepth() const { return commandHistory->undoDepth(); }
00885
00886 int length() const;
00887 void clear(bool createEmptyParag = false);
00888
00889 virtual Q3TextParagraph *createParagraph(Q3TextDocument *, Q3TextParagraph *pr = 0, Q3TextParagraph *nx = 0, bool updateIds = true);
00890 void insertChild(Q3TextDocument *dc) { childList.append(dc); }
00891 void removeChild(Q3TextDocument *dc) { childList.removeAll(dc); }
00892 QList<Q3TextDocument *> children() const { return childList; }
00893
00894 bool hasFocusParagraph() const;
00895 QString focusHref() const;
00896 QString focusName() const;
00897
00898 void invalidateOriginalText() { oTextValid = false; oText = ""; }
00899
00900 Q_SIGNALS:
00901 void minimumWidthChanged(int);
00902
00903 private:
00904 Q_DISABLE_COPY(Q3TextDocument)
00905
00906 void init();
00907 QPixmap *bufferPixmap(const QSize &s);
00908
00909 bool hasPrefix(const QChar* doc, int length, int pos, QChar c);
00910 bool hasPrefix(const QChar* doc, int length, int pos, const QString& s);
00911 #ifndef QT_NO_TEXTCUSTOMITEM
00912 Q3TextCustomItem* parseTable(const QMap<QString, QString> &attr, const Q3TextFormat &fmt,
00913 const QChar* doc, int length, int& pos, Q3TextParagraph *curpar);
00914 #endif
00915 bool eatSpace(const QChar* doc, int length, int& pos, bool includeNbsp = false);
00916 bool eat(const QChar* doc, int length, int& pos, QChar c);
00917 QString parseOpenTag(const QChar* doc, int length, int& pos, QMap<QString, QString> &attr, bool& emptyTag);
00918 QString parseCloseTag(const QChar* doc, int length, int& pos);
00919 QChar parseHTMLSpecialChar(const QChar* doc, int length, int& pos);
00920 QString parseWord(const QChar* doc, int length, int& pos, bool lower = true);
00921 QChar parseChar(const QChar* doc, int length, int& pos, Q3StyleSheetItem::WhiteSpaceMode wsm);
00922 void setRichTextInternal(const QString &text, Q3TextCursor* cursor = 0, const Q3TextFormat *initialFormat = 0);
00923 void setRichTextMarginsInternal(QList< QVector<Q3StyleSheetItem *> *>& styles, Q3TextParagraph* stylesPar);
00924
00925 struct Q_COMPAT_EXPORT Focus {
00926 Q3TextParagraph *parag;
00927 int start, len;
00928 QString href;
00929 QString name;
00930 };
00931
00932 int cx, cy, cw, vw;
00933 Q3TextParagraph *fParag, *lParag;
00934 Q3TextPreProcessor *pProcessor;
00935 struct SelectionColor {
00936 QColor background;
00937 QColor text;
00938 };
00939 QMap<int, SelectionColor> selectionColors;
00940 QMap<int, Q3TextDocumentSelection> selections;
00941 Q3TextCommandHistory *commandHistory;
00942 Q3TextFormatter *pFormatter;
00943 Q3TextIndent *indenter;
00944 Q3TextFormatCollection *fCollection;
00945 Qt::TextFormat txtFormat;
00946 uint preferRichText : 1;
00947 uint pages : 1;
00948 uint useFC : 1;
00949 uint withoutDoubleBuffer : 1;
00950 uint underlLinks : 1;
00951 uint nextDoubleBuffered : 1;
00952 uint oTextValid : 1;
00953 uint mightHaveCustomItems : 1;
00954 int align;
00955 int nSelections;
00956 Q3TextFlow *flow_;
00957 Q3TextDocument *par;
00958 Q3TextParagraph *parentPar;
00959 #ifndef QT_NO_TEXTCUSTOMITEM
00960 Q3TextTableCell *tc;
00961 #endif
00962 QBrush *backBrush;
00963 QPixmap *buf_pixmap;
00964 Focus focusIndicator;
00965 int minw;
00966 int wused;
00967 int leftmargin;
00968 int rightmargin;
00969 Q3TextParagraph *minwParag, *curParag;
00970 Q3StyleSheet* sheet_;
00971 #ifndef QT_NO_MIME
00972 Q3MimeSourceFactory* factory_;
00973 #endif
00974 QString contxt;
00975 QMap<QString, QString> attribs;
00976 int *tArray;
00977 int tStopWidth;
00978 int uDepth;
00979 QString oText;
00980 QList<Q3TextDocument *> childList;
00981 QColor linkColor, bodyText;
00982 double scaleFontsFactor;
00983
00984 short list_tm,list_bm, list_lm, li_tm, li_bm, par_tm, par_bm;
00985 };
00986
00987
00988
00989
00990 class Q_COMPAT_EXPORT Q3TextDeleteCommand : public Q3TextCommand
00991 {
00992 public:
00993 Q3TextDeleteCommand(Q3TextDocument *dc, int i, int idx, const QVector<Q3TextStringChar> &str,
00994 const QByteArray& oldStyle);
00995 Q3TextDeleteCommand(Q3TextParagraph *p, int idx, const QVector<Q3TextStringChar> &str);
00996 virtual ~Q3TextDeleteCommand();
00997
00998 Commands type() const { return Delete; }
00999 Q3TextCursor *execute(Q3TextCursor *c);
01000 Q3TextCursor *unexecute(Q3TextCursor *c);
01001
01002 protected:
01003 int id, index;
01004 Q3TextParagraph *parag;
01005 QVector<Q3TextStringChar> text;
01006 QByteArray styleInformation;
01007
01008 };
01009
01010 class Q_COMPAT_EXPORT Q3TextInsertCommand : public Q3TextDeleteCommand
01011 {
01012 public:
01013 Q3TextInsertCommand(Q3TextDocument *dc, int i, int idx, const QVector<Q3TextStringChar> &str,
01014 const QByteArray& oldStyleInfo)
01015 : Q3TextDeleteCommand(dc, i, idx, str, oldStyleInfo) {}
01016 Q3TextInsertCommand(Q3TextParagraph *p, int idx, const QVector<Q3TextStringChar> &str)
01017 : Q3TextDeleteCommand(p, idx, str) {}
01018 virtual ~Q3TextInsertCommand() {}
01019
01020 Commands type() const { return Insert; }
01021 Q3TextCursor *execute(Q3TextCursor *c) { return Q3TextDeleteCommand::unexecute(c); }
01022 Q3TextCursor *unexecute(Q3TextCursor *c) { return Q3TextDeleteCommand::execute(c); }
01023
01024 };
01025
01026 class Q_COMPAT_EXPORT Q3TextFormatCommand : public Q3TextCommand
01027 {
01028 public:
01029 Q3TextFormatCommand(Q3TextDocument *dc, int sid, int sidx, int eid, int eidx, const QVector<Q3TextStringChar> &old, Q3TextFormat *f, int fl);
01030 virtual ~Q3TextFormatCommand();
01031
01032 Commands type() const { return Format; }
01033 Q3TextCursor *execute(Q3TextCursor *c);
01034 Q3TextCursor *unexecute(Q3TextCursor *c);
01035
01036 protected:
01037 int startId, startIndex, endId, endIndex;
01038 Q3TextFormat *format;
01039 QVector<Q3TextStringChar> oldFormats;
01040 int flags;
01041
01042 };
01043
01044 class Q_COMPAT_EXPORT Q3TextStyleCommand : public Q3TextCommand
01045 {
01046 public:
01047 Q3TextStyleCommand(Q3TextDocument *dc, int fParag, int lParag, const QByteArray& beforeChange );
01048 virtual ~Q3TextStyleCommand() {}
01049
01050 Commands type() const { return Style; }
01051 Q3TextCursor *execute(Q3TextCursor *c);
01052 Q3TextCursor *unexecute(Q3TextCursor *c);
01053
01054 static QByteArray readStyleInformation( Q3TextDocument* dc, int fParag, int lParag);
01055 static void writeStyleInformation( Q3TextDocument* dc, int fParag, const QByteArray& style);
01056
01057 private:
01058 int firstParag, lastParag;
01059 QByteArray before;
01060 QByteArray after;
01061 };
01062
01063
01064
01065 struct Q_COMPAT_EXPORT Q3TextParagraphSelection
01066 {
01067 int start, end;
01068 Q_DUMMY_COMPARISON_OPERATOR(Q3TextParagraphSelection)
01069 };
01070
01071 struct Q_COMPAT_EXPORT QTextLineStart
01072 {
01073 QTextLineStart() : y(0), baseLine(0), h(0)
01074 { }
01075 QTextLineStart(int y_, int bl, int h_) : y(y_), baseLine(bl), h(h_),
01076 w(0)
01077 { }
01078
01079 public:
01080 int y, baseLine, h;
01081 int w;
01082 };
01083
01084 class Q_COMPAT_EXPORT Q3TextParagraphData
01085 {
01086 public:
01087 Q3TextParagraphData() {}
01088 virtual ~Q3TextParagraphData();
01089 virtual void join(Q3TextParagraphData *);
01090 };
01091
01092 class Q3TextParagraphPseudoDocument;
01093
01094 class Q3SyntaxHighlighter;
01095
01096 class Q_COMPAT_EXPORT Q3TextParagraph
01097 {
01098 friend class Q3TextDocument;
01099 friend class Q3TextCursor;
01100 friend class Q3SyntaxHighlighter;
01101
01102 public:
01103 Q3TextParagraph(Q3TextDocument *dc, Q3TextParagraph *pr = 0, Q3TextParagraph *nx = 0, bool updateIds = true);
01104 ~Q3TextParagraph();
01105
01106 Q3TextString *string() const;
01107 Q3TextStringChar *at(int i) const;
01108 int leftGap() const;
01109 int length() const;
01110
01111 void setListStyle(Q3StyleSheetItem::ListStyle ls) { lstyle = ls; changed = true; }
01112 Q3StyleSheetItem::ListStyle listStyle() const { return (Q3StyleSheetItem::ListStyle)lstyle; }
01113 void setListItem(bool li);
01114 bool isListItem() const { return litem; }
01115 void setListValue(int v) { list_val = v; }
01116 int listValue() const { return list_val > 0 ? list_val : -1; }
01117
01118 void setListDepth(int depth);
01119 int listDepth() const { return ldepth; }
01120
01121
01122
01123
01124 inline Q3TextDocument *document() const {
01125 if (hasdoc) return (Q3TextDocument*) docOrPseudo;
01126 return 0;
01127 }
01128 Q3TextParagraphPseudoDocument *pseudoDocument() const;
01129
01130 QRect rect() const;
01131 void setHeight(int h) { r.setHeight(h); }
01132 void show();
01133 void hide();
01134 bool isVisible() const { return visible; }
01135
01136 Q3TextParagraph *prev() const;
01137 Q3TextParagraph *next() const;
01138 void setPrev(Q3TextParagraph *s);
01139 void setNext(Q3TextParagraph *s);
01140
01141 void insert(int index, const QString &s);
01142 void insert(int index, const QChar *unicode, int len);
01143 void append(const QString &s, bool reallyAtEnd = false);
01144 void truncate(int index);
01145 void remove(int index, int len);
01146 void join(Q3TextParagraph *s);
01147
01148 void invalidate(int chr);
01149
01150 void move(int &dy);
01151 void format(int start = -1, bool doMove = true);
01152
01153 bool isValid() const;
01154 bool hasChanged() const;
01155 void setChanged(bool b, bool recursive = false);
01156
01157 int lineHeightOfChar(int i, int *bl = 0, int *y = 0) const;
01158 Q3TextStringChar *lineStartOfChar(int i, int *index = 0, int *line = 0) const;
01159 int lines() const;
01160 Q3TextStringChar *lineStartOfLine(int line, int *index = 0) const;
01161 int lineY(int l) const;
01162 int lineBaseLine(int l) const;
01163 int lineHeight(int l) const;
01164 void lineInfo(int l, int &y, int &h, int &bl) const;
01165
01166 void setSelection(int id, int start, int end);
01167 void removeSelection(int id);
01168 int selectionStart(int id) const;
01169 int selectionEnd(int id) const;
01170 bool hasSelection(int id) const;
01171 bool hasAnySelection() const;
01172 bool fullSelected(int id) const;
01173
01174 void setEndState(int s);
01175 int endState() const;
01176
01177 void setParagId(int i);
01178 int paragId() const;
01179
01180 bool firstPreProcess() const;
01181 void setFirstPreProcess(bool b);
01182
01183 void indent(int *oldIndent = 0, int *newIndent = 0);
01184
01185 void setExtraData(Q3TextParagraphData *data);
01186 Q3TextParagraphData *extraData() const;
01187
01188 QMap<int, QTextLineStart*> &lineStartList();
01189
01190 void setFormat(int index, int len, Q3TextFormat *f, bool useCollection = true, int flags = -1);
01191
01192 void setAlignment(int a);
01193 int alignment() const;
01194
01195 void paint(QPainter &painter, const QPalette &pal, Q3TextCursor *cursor = 0,
01196 bool drawSelections = false, int clipx = -1, int clipy = -1,
01197 int clipw = -1, int cliph = -1);
01198
01199 int topMargin() const;
01200 int bottomMargin() const;
01201 int leftMargin() const;
01202 int firstLineMargin() const;
01203 int rightMargin() const;
01204 int lineSpacing() const;
01205
01206 #ifndef QT_NO_TEXTCUSTOMITEM
01207 void registerFloatingItem(Q3TextCustomItem *i);
01208 void unregisterFloatingItem(Q3TextCustomItem *i);
01209 #endif
01210
01211 void setFullWidth(bool b) { fullWidth = b; }
01212 bool isFullWidth() const { return fullWidth; }
01213
01214 #ifndef QT_NO_TEXTCUSTOMITEM
01215 Q3TextTableCell *tableCell() const;
01216 #endif
01217
01218 QBrush *background() const;
01219
01220 int documentWidth() const;
01221 int documentVisibleWidth() const;
01222 int documentX() const;
01223 int documentY() const;
01224 Q3TextFormatCollection *formatCollection() const;
01225 Q3TextFormatter *formatter() const;
01226
01227 int nextTab(int i, int x);
01228 int *tabArray() const;
01229 void setTabArray(int *a);
01230 void setTabStops(int tw);
01231
01232 void adjustToPainter(QPainter *p);
01233
01234 void setNewLinesAllowed(bool b);
01235 bool isNewLinesAllowed() const;
01236
01237 QString richText() const;
01238
01239 void addCommand(Q3TextCommand *cmd);
01240 Q3TextCursor *undo(Q3TextCursor *c = 0);
01241 Q3TextCursor *redo(Q3TextCursor *c = 0);
01242 Q3TextCommandHistory *commands() const;
01243 void copyParagData(Q3TextParagraph *parag);
01244
01245 void setBreakable(bool b) { breakable = b; }
01246 bool isBreakable() const { return breakable; }
01247
01248 void setBackgroundColor(const QColor &c);
01249 QColor *backgroundColor() const { return bgcol; }
01250 void clearBackgroundColor();
01251
01252 void setMovedDown(bool b) { movedDown = b; }
01253 bool wasMovedDown() const { return movedDown; }
01254
01255 void setDirection(QChar::Direction);
01256 QChar::Direction direction() const;
01257 void setPaintDevice(QPaintDevice *pd) { paintdevice = pd; }
01258
01259 void readStyleInformation(QDataStream& stream);
01260 void writeStyleInformation(QDataStream& stream) const;
01261
01262 protected:
01263 void setColorForSelection(QColor &c, QPainter &p, const QPalette &pal, int selection);
01264 void drawLabel(QPainter* p, int x, int y, int w, int h, int base, const QPalette &pal);
01265 void drawString(QPainter &painter, const QString &str, int start, int len, int xstart,
01266 int y, int baseLine, int w, int h, bool drawSelections, int fullSelectionWidth,
01267 Q3TextStringChar *formatChar, const QPalette &pal,
01268 bool rightToLeft);
01269
01270 private:
01271 QMap<int, Q3TextParagraphSelection> &selections() const;
01272 #ifndef QT_NO_TEXTCUSTOMITEM
01273 QList<Q3TextCustomItem *> &floatingItems() const;
01274 #endif
01275 inline QBrush backgroundBrush(const QPalette &pal) {
01276 if (bgcol)
01277 return *bgcol;
01278 return pal.brush(QPalette::Base);
01279 }
01280 void invalidateStyleCache();
01281
01282 QMap<int, QTextLineStart*> lineStarts;
01283 QRect r;
01284 Q3TextParagraph *p, *n;
01285 void *docOrPseudo;
01286 uint changed : 1;
01287 uint firstFormat : 1;
01288 uint firstPProcess : 1;
01289 uint needPreProcess : 1;
01290 uint fullWidth : 1;
01291 uint lastInFrame : 1;
01292 uint visible : 1;
01293 uint breakable : 1;
01294 uint movedDown : 1;
01295 uint mightHaveCustomItems : 1;
01296 uint hasdoc : 1;
01297 uint litem : 1;
01298 uint rtext : 1;
01299 signed int align : 5;
01300 uint lstyle : 4;
01301 int invalid;
01302 int state, id;
01303 Q3TextString *str;
01304 QMap<int, Q3TextParagraphSelection> *mSelections;
01305 #ifndef QT_NO_TEXTCUSTOMITEM
01306 QList<Q3TextCustomItem *> *mFloatingItems;
01307 #endif
01308 short utm, ubm, ulm, urm, uflm, ulinespacing;
01309 short tabStopWidth, minwidth;
01310 int *tArray;
01311 Q3TextParagraphData *eData;
01312 short list_val;
01313 ushort ldepth;
01314 QColor *bgcol;
01315 QPaintDevice *paintdevice;
01316 };
01317
01318
01319
01320 class Q_COMPAT_EXPORT Q3TextFormatter
01321 {
01322 public:
01323 Q3TextFormatter();
01324 virtual ~Q3TextFormatter();
01325
01326 virtual int format(Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts) = 0;
01327 virtual int formatVertically(Q3TextDocument* doc, Q3TextParagraph* parag);
01328
01329 bool isWrapEnabled(Q3TextParagraph *p) const { if (!wrapEnabled) return false; if (p && !p->isBreakable()) return false; return true;}
01330 int wrapAtColumn() const { return wrapColumn;}
01331 virtual void setWrapEnabled(bool b);
01332 virtual void setWrapAtColumn(int c);
01333 virtual void setAllowBreakInWords(bool b) { biw = b; }
01334 bool allowBreakInWords() const { return biw; }
01335
01336 int minimumWidth() const { return thisminw; }
01337 int widthUsed() const { return thiswused; }
01338
01339 protected:
01340 virtual QTextLineStart *formatLine(Q3TextParagraph *parag, Q3TextString *string, QTextLineStart *line, Q3TextStringChar *start,
01341 Q3TextStringChar *last, int align = Qt::AlignAuto, int space = 0);
01342 #ifndef QT_NO_COMPLEXTEXT
01343 virtual QTextLineStart *bidiReorderLine(Q3TextParagraph *parag, Q3TextString *string, QTextLineStart *line, Q3TextStringChar *start,
01344 Q3TextStringChar *last, int align, int space);
01345 #endif
01346 void insertLineStart(Q3TextParagraph *parag, int index, QTextLineStart *ls);
01347
01348 int thisminw;
01349 int thiswused;
01350
01351 private:
01352 bool wrapEnabled;
01353 int wrapColumn;
01354 bool biw;
01355 };
01356
01357
01358
01359 class Q_COMPAT_EXPORT Q3TextFormatterBreakInWords : public Q3TextFormatter
01360 {
01361 public:
01362 Q3TextFormatterBreakInWords();
01363 virtual ~Q3TextFormatterBreakInWords() {}
01364
01365 int format(Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts);
01366
01367 };
01368
01369
01370
01371 class Q_COMPAT_EXPORT Q3TextFormatterBreakWords : public Q3TextFormatter
01372 {
01373 public:
01374 Q3TextFormatterBreakWords();
01375 virtual ~Q3TextFormatterBreakWords() {}
01376
01377 int format(Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts);
01378
01379 };
01380
01381
01382
01383 class Q_COMPAT_EXPORT Q3TextIndent
01384 {
01385 public:
01386 Q3TextIndent();
01387 virtual ~Q3TextIndent() {}
01388
01389 virtual void indent(Q3TextDocument *doc, Q3TextParagraph *parag, int *oldIndent = 0, int *newIndent = 0) = 0;
01390
01391 };
01392
01393
01394
01395 class Q_COMPAT_EXPORT Q3TextPreProcessor
01396 {
01397 public:
01398 enum Ids {
01399 Standard = 0
01400 };
01401
01402 Q3TextPreProcessor();
01403 virtual ~Q3TextPreProcessor() {}
01404
01405 virtual void process(Q3TextDocument *doc, Q3TextParagraph *, int, bool = true) = 0;
01406 virtual Q3TextFormat *format(int id) = 0;
01407
01408 };
01409
01410
01411
01412 class Q_COMPAT_EXPORT Q3TextFormat
01413 {
01414 friend class Q3TextFormatCollection;
01415 friend class Q3TextDocument;
01416
01417 public:
01418 enum Flags {
01419 NoFlags,
01420 Bold = 1,
01421 Italic = 2,
01422 Underline = 4,
01423 Family = 8,
01424 Size = 16,
01425 Color = 32,
01426 Misspelled = 64,
01427 VAlign = 128,
01428 StrikeOut= 256,
01429 Font = Bold | Italic | Underline | Family | Size | StrikeOut,
01430 Format = Font | Color | Misspelled | VAlign
01431 };
01432
01433 enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript };
01434
01435 Q3TextFormat();
01436 virtual ~Q3TextFormat();
01437
01438 Q3TextFormat(const Q3StyleSheetItem *s);
01439 Q3TextFormat(const QFont &f, const QColor &c, Q3TextFormatCollection *parent = 0);
01440 Q3TextFormat(const Q3TextFormat &fm);
01441 Q3TextFormat makeTextFormat(const Q3StyleSheetItem *style, const QMap<QString,QString>& attr, double scaleFontsFactor) const;
01442 Q3TextFormat& operator=(const Q3TextFormat &fm);
01443 QColor color() const;
01444 QFont font() const;
01445 QFontMetrics fontMetrics() const { return fm; }
01446 bool isMisspelled() const;
01447 VerticalAlignment vAlign() const;
01448 int minLeftBearing() const;
01449 int minRightBearing() const;
01450 int width(const QChar &c) const;
01451 int width(const QString &str, int pos) const;
01452 int height() const;
01453 int ascent() const;
01454 int descent() const;
01455 int leading() const;
01456 bool useLinkColor() const;
01457
01458 void setBold(bool b);
01459 void setItalic(bool b);
01460 void setUnderline(bool b);
01461 void setStrikeOut(bool b);
01462 void setFamily(const QString &f);
01463 void setPointSize(int s);
01464 void setFont(const QFont &f);
01465 void setColor(const QColor &c);
01466 void setMisspelled(bool b);
01467 void setVAlign(VerticalAlignment a);
01468
01469 bool operator==(const Q3TextFormat &f) const;
01470 Q3TextFormatCollection *parent() const;
01471 const QString &key() const;
01472
01473 static QString getKey(const QFont &f, const QColor &c, bool misspelled, VerticalAlignment vAlign);
01474
01475 void addRef();
01476 void removeRef();
01477
01478 QString makeFormatChangeTags(Q3TextFormat* defaultFormat, Q3TextFormat *f, const QString& oldAnchorHref, const QString& anchorHref) const;
01479 QString makeFormatEndTags(Q3TextFormat* defaultFormat, const QString& anchorHref) const;
01480
01481 static void setPainter(QPainter *p);
01482 static QPainter* painter();
01483
01484 bool fontSizesInPixels() { return usePixelSizes; }
01485
01486 protected:
01487 virtual void generateKey();
01488
01489 private:
01490 void update();
01491 static void applyFont(const QFont &f);
01492
01493 private:
01494 QFont fn;
01495 QColor col;
01496 QFontMetrics fm;
01497 uint missp : 1;
01498 uint linkColor : 1;
01499 uint usePixelSizes : 1;
01500 int leftBearing, rightBearing;
01501 VerticalAlignment ha;
01502 uchar widths[256];
01503 int hei, asc, dsc;
01504 Q3TextFormatCollection *collection;
01505 int ref;
01506 QString k;
01507 int logicalFontSize;
01508 int stdSize;
01509 static QPainter *pntr;
01510 static QFontMetrics *pntr_fm;
01511 static int pntr_asc;
01512 static int pntr_hei;
01513 static int pntr_ldg;
01514 static int pntr_dsc;
01515
01516 };
01517
01518
01519
01520 class Q_COMPAT_EXPORT Q3TextFormatCollection
01521 {
01522 friend class Q3TextDocument;
01523 friend class Q3TextFormat;
01524
01525 public:
01526 Q3TextFormatCollection();
01527 virtual ~Q3TextFormatCollection();
01528
01529 void setDefaultFormat(Q3TextFormat *f);
01530 Q3TextFormat *defaultFormat() const;
01531 virtual Q3TextFormat *format(Q3TextFormat *f);
01532 virtual Q3TextFormat *format(Q3TextFormat *of, Q3TextFormat *nf, int flags);
01533 virtual Q3TextFormat *format(const QFont &f, const QColor &c);
01534 virtual void remove(Q3TextFormat *f);
01535 virtual Q3TextFormat *createFormat(const Q3TextFormat &f) { return new Q3TextFormat(f); }
01536 virtual Q3TextFormat *createFormat(const QFont &f, const QColor &c) { return new Q3TextFormat(f, c, this); }
01537
01538 void updateDefaultFormat(const QFont &font, const QColor &c, Q3StyleSheet *sheet);
01539
01540 QPaintDevice *paintDevice() const { return paintdevice; }
01541 void setPaintDevice(QPaintDevice *);
01542
01543 private:
01544 void updateKeys();
01545
01546 private:
01547 Q3TextFormat *defFormat, *lastFormat, *cachedFormat;
01548 QHash<QString, Q3TextFormat *> cKey;
01549 Q3TextFormat *cres;
01550 QFont cfont;
01551 QColor ccol;
01552 QString kof, knf;
01553 int cflags;
01554
01555 QPaintDevice *paintdevice;
01556 };
01557
01558 class Q_COMPAT_EXPORT Q3TextParagraphPseudoDocument
01559 {
01560 public:
01561 Q3TextParagraphPseudoDocument();
01562 ~Q3TextParagraphPseudoDocument();
01563 QRect docRect;
01564 Q3TextFormatter *pFormatter;
01565 Q3TextCommandHistory *commandHistory;
01566 int minw;
01567 int wused;
01568 Q3TextFormatCollection collection;
01569 };
01570
01571
01572
01573 inline int Q3TextParagraph::length() const
01574 {
01575 return str->length();
01576 }
01577
01578 inline QRect Q3TextParagraph::rect() const
01579 {
01580 return r;
01581 }
01582
01583 inline int Q3TextCursor::index() const
01584 {
01585 return idx;
01586 }
01587
01588
01589
01590 inline int Q3TextDocument::x() const
01591 {
01592 return cx;
01593 }
01594
01595 inline int Q3TextDocument::y() const
01596 {
01597 return cy;
01598 }
01599
01600 inline int Q3TextDocument::width() const
01601 {
01602 return qMax(cw, flow_->width());
01603 }
01604
01605 inline int Q3TextDocument::visibleWidth() const
01606 {
01607 return vw;
01608 }
01609
01610 inline Q3TextParagraph *Q3TextDocument::firstParagraph() const
01611 {
01612 return fParag;
01613 }
01614
01615 inline Q3TextParagraph *Q3TextDocument::lastParagraph() const
01616 {
01617 return lParag;
01618 }
01619
01620 inline void Q3TextDocument::setFirstParagraph(Q3TextParagraph *p)
01621 {
01622 fParag = p;
01623 }
01624
01625 inline void Q3TextDocument::setLastParagraph(Q3TextParagraph *p)
01626 {
01627 lParag = p;
01628 }
01629
01630 inline void Q3TextDocument::setWidth(int w)
01631 {
01632 cw = qMax(w, minw);
01633 flow_->setWidth(cw);
01634 vw = w;
01635 }
01636
01637 inline int Q3TextDocument::minimumWidth() const
01638 {
01639 return minw;
01640 }
01641
01642 inline void Q3TextDocument::setY(int y)
01643 {
01644 cy = y;
01645 }
01646
01647 inline int Q3TextDocument::leftMargin() const
01648 {
01649 return leftmargin;
01650 }
01651
01652 inline void Q3TextDocument::setLeftMargin(int lm)
01653 {
01654 leftmargin = lm;
01655 }
01656
01657 inline int Q3TextDocument::rightMargin() const
01658 {
01659 return rightmargin;
01660 }
01661
01662 inline void Q3TextDocument::setRightMargin(int rm)
01663 {
01664 rightmargin = rm;
01665 }
01666
01667 inline Q3TextPreProcessor *Q3TextDocument::preProcessor() const
01668 {
01669 return pProcessor;
01670 }
01671
01672 inline void Q3TextDocument::setPreProcessor(Q3TextPreProcessor * sh)
01673 {
01674 pProcessor = sh;
01675 }
01676
01677 inline void Q3TextDocument::setFormatter(Q3TextFormatter *f)
01678 {
01679 delete pFormatter;
01680 pFormatter = f;
01681 }
01682
01683 inline Q3TextFormatter *Q3TextDocument::formatter() const
01684 {
01685 return pFormatter;
01686 }
01687
01688 inline void Q3TextDocument::setIndent(Q3TextIndent *i)
01689 {
01690 indenter = i;
01691 }
01692
01693 inline Q3TextIndent *Q3TextDocument::indent() const
01694 {
01695 return indenter;
01696 }
01697
01698 inline QColor Q3TextDocument::selectionColor(int id) const
01699 {
01700 const Q3TextDocument *p = this;
01701 while (p->par)
01702 p = p->par;
01703 return p->selectionColors[id].background;
01704 }
01705
01706 inline QColor Q3TextDocument::selectionTextColor(int id) const
01707 {
01708 const Q3TextDocument *p = this;
01709 while (p->par)
01710 p = p->par;
01711 return p->selectionColors[id].text;
01712 }
01713
01714 inline bool Q3TextDocument::hasSelectionTextColor(int id) const
01715 {
01716 const Q3TextDocument *p = this;
01717 while (p->par)
01718 p = p->par;
01719 return p->selectionColors.contains(id);
01720 }
01721
01722 inline void Q3TextDocument::setSelectionColor(int id, const QColor &c)
01723 {
01724 Q3TextDocument *p = this;
01725 while (p->par)
01726 p = p->par;
01727 p->selectionColors[id].background = c;
01728 }
01729
01730 inline void Q3TextDocument::setSelectionTextColor(int id, const QColor &c)
01731 {
01732 Q3TextDocument *p = this;
01733 while (p->par)
01734 p = p->par;
01735 p->selectionColors[id].text = c;
01736 }
01737
01738 inline Q3TextFormatCollection *Q3TextDocument::formatCollection() const
01739 {
01740 return fCollection;
01741 }
01742
01743 inline int Q3TextDocument::alignment() const
01744 {
01745 return align;
01746 }
01747
01748 inline void Q3TextDocument::setAlignment(int a)
01749 {
01750 align = a;
01751 }
01752
01753 inline int *Q3TextDocument::tabArray() const
01754 {
01755 return tArray;
01756 }
01757
01758 inline int Q3TextDocument::tabStopWidth() const
01759 {
01760 return tStopWidth;
01761 }
01762
01763 inline void Q3TextDocument::setTabArray(int *a)
01764 {
01765 tArray = a;
01766 }
01767
01768 inline void Q3TextDocument::setTabStops(int tw)
01769 {
01770 tStopWidth = tw;
01771 }
01772
01773 inline QString Q3TextDocument::originalText() const
01774 {
01775 if (oTextValid)
01776 return oText;
01777 return text();
01778 }
01779
01780 inline void Q3TextDocument::setFlow(Q3TextFlow *f)
01781 {
01782 if (flow_)
01783 delete flow_;
01784 flow_ = f;
01785 }
01786
01787 inline void Q3TextDocument::takeFlow()
01788 {
01789 flow_ = 0;
01790 }
01791
01792
01793
01794 inline QColor Q3TextFormat::color() const
01795 {
01796 return col;
01797 }
01798
01799 inline QFont Q3TextFormat::font() const
01800 {
01801 return fn;
01802 }
01803
01804 inline bool Q3TextFormat::isMisspelled() const
01805 {
01806 return missp;
01807 }
01808
01809 inline Q3TextFormat::VerticalAlignment Q3TextFormat::vAlign() const
01810 {
01811 return ha;
01812 }
01813
01814 inline bool Q3TextFormat::operator==(const Q3TextFormat &f) const
01815 {
01816 return k == f.k;
01817 }
01818
01819 inline Q3TextFormatCollection *Q3TextFormat::parent() const
01820 {
01821 return collection;
01822 }
01823
01824 inline void Q3TextFormat::addRef()
01825 {
01826 ref++;
01827 }
01828
01829 inline void Q3TextFormat::removeRef()
01830 {
01831 ref--;
01832 if (!collection)
01833 return;
01834 if (this == collection->defFormat)
01835 return;
01836 if (ref == 0)
01837 collection->remove(this);
01838 }
01839
01840 inline const QString &Q3TextFormat::key() const
01841 {
01842 return k;
01843 }
01844
01845 inline bool Q3TextFormat::useLinkColor() const
01846 {
01847 return linkColor;
01848 }
01849
01850 inline Q3TextStringChar *Q3TextParagraph::at(int i) const
01851 {
01852 return &str->at(i);
01853 }
01854
01855 inline bool Q3TextParagraph::isValid() const
01856 {
01857 return invalid == -1;
01858 }
01859
01860 inline bool Q3TextParagraph::hasChanged() const
01861 {
01862 return changed;
01863 }
01864
01865 inline void Q3TextParagraph::setBackgroundColor(const QColor & c)
01866 {
01867 delete bgcol;
01868 bgcol = new QColor(c);
01869 setChanged(true);
01870 }
01871
01872 inline void Q3TextParagraph::clearBackgroundColor()
01873 {
01874 delete bgcol; bgcol = 0; setChanged(true);
01875 }
01876
01877 inline void Q3TextParagraph::append(const QString &s, bool reallyAtEnd)
01878 {
01879 if (reallyAtEnd) {
01880 insert(str->length(), s);
01881 } else {
01882 int str_end = str->length() - 1;
01883 insert(str_end > 0 ? str_end : 0, s);
01884 }
01885 }
01886
01887 inline Q3TextParagraph *Q3TextParagraph::prev() const
01888 {
01889 return p;
01890 }
01891
01892 inline Q3TextParagraph *Q3TextParagraph::next() const
01893 {
01894 return n;
01895 }
01896
01897 inline bool Q3TextParagraph::hasAnySelection() const
01898 {
01899 return mSelections ? !selections().isEmpty() : false;
01900 }
01901
01902 inline void Q3TextParagraph::setEndState(int s)
01903 {
01904 if (s == state)
01905 return;
01906 state = s;
01907 }
01908
01909 inline int Q3TextParagraph::endState() const
01910 {
01911 return state;
01912 }
01913
01914 inline void Q3TextParagraph::setParagId(int i)
01915 {
01916 id = i;
01917 }
01918
01919 inline int Q3TextParagraph::paragId() const
01920 {
01921 if (id == -1)
01922 qWarning("invalid parag id!!!!!!!! (%p)", (void*)this);
01923 return id;
01924 }
01925
01926 inline bool Q3TextParagraph::firstPreProcess() const
01927 {
01928 return firstPProcess;
01929 }
01930
01931 inline void Q3TextParagraph::setFirstPreProcess(bool b)
01932 {
01933 firstPProcess = b;
01934 }
01935
01936 inline QMap<int, QTextLineStart*> &Q3TextParagraph::lineStartList()
01937 {
01938 return lineStarts;
01939 }
01940
01941 inline Q3TextString *Q3TextParagraph::string() const
01942 {
01943 return str;
01944 }
01945
01946 inline Q3TextParagraphPseudoDocument *Q3TextParagraph::pseudoDocument() const
01947 {
01948 if (hasdoc)
01949 return 0;
01950 return (Q3TextParagraphPseudoDocument*) docOrPseudo;
01951 }
01952
01953
01954 #ifndef QT_NO_TEXTCUSTOMITEM
01955 inline Q3TextTableCell *Q3TextParagraph::tableCell() const
01956 {
01957 return hasdoc ? document()->tableCell () : 0;
01958 }
01959 #endif
01960
01961 inline Q3TextCommandHistory *Q3TextParagraph::commands() const
01962 {
01963 return hasdoc ? document()->commands() : pseudoDocument()->commandHistory;
01964 }
01965
01966
01967 inline int Q3TextParagraph::alignment() const
01968 {
01969 return align;
01970 }
01971
01972 #ifndef QT_NO_TEXTCUSTOMITEM
01973 inline void Q3TextParagraph::registerFloatingItem(Q3TextCustomItem *i)
01974 {
01975 floatingItems().append(i);
01976 }
01977
01978 inline void Q3TextParagraph::unregisterFloatingItem(Q3TextCustomItem *i)
01979 {
01980 floatingItems().removeAll(i);
01981 }
01982 #endif
01983
01984 inline QBrush *Q3TextParagraph::background() const
01985 {
01986 #ifndef QT_NO_TEXTCUSTOMITEM
01987 return tableCell() ? tableCell()->backGround() : 0;
01988 #else
01989 return 0;
01990 #endif
01991 }
01992
01993 inline int Q3TextParagraph::documentWidth() const
01994 {
01995 return hasdoc ? document()->width() : pseudoDocument()->docRect.width();
01996 }
01997
01998 inline int Q3TextParagraph::documentVisibleWidth() const
01999 {
02000 return hasdoc ? document()->visibleWidth() : pseudoDocument()->docRect.width();
02001 }
02002
02003 inline int Q3TextParagraph::documentX() const
02004 {
02005 return hasdoc ? document()->x() : pseudoDocument()->docRect.x();
02006 }
02007
02008 inline int Q3TextParagraph::documentY() const
02009 {
02010 return hasdoc ? document()->y() : pseudoDocument()->docRect.y();
02011 }
02012
02013 inline void Q3TextParagraph::setExtraData(Q3TextParagraphData *data)
02014 {
02015 eData = data;
02016 }
02017
02018 inline Q3TextParagraphData *Q3TextParagraph::extraData() const
02019 {
02020 return eData;
02021 }
02022
02023
02024
02025 inline void Q3TextFormatCollection::setDefaultFormat(Q3TextFormat *f)
02026 {
02027 defFormat = f;
02028 }
02029
02030 inline Q3TextFormat *Q3TextFormatCollection::defaultFormat() const
02031 {
02032 return defFormat;
02033 }
02034
02035
02036
02037 inline Q3TextFormat *Q3TextStringChar::format() const
02038 {
02039 return (type == Regular) ? p.format : p.custom->format;
02040 }
02041
02042
02043 #ifndef QT_NO_TEXTCUSTOMITEM
02044 inline Q3TextCustomItem *Q3TextStringChar::customItem() const
02045 {
02046 return isCustom() ? p.custom->custom : 0;
02047 }
02048 #endif
02049
02050 inline int Q3TextStringChar::height() const
02051 {
02052 #ifndef QT_NO_TEXTCUSTOMITEM
02053 return !isCustom() ? format()->height() : (customItem()->placement() == Q3TextCustomItem::PlaceInline ? customItem()->height : 0);
02054 #else
02055 return format()->height();
02056 #endif
02057 }
02058
02059 inline int Q3TextStringChar::ascent() const
02060 {
02061 #ifndef QT_NO_TEXTCUSTOMITEM
02062 return !isCustom() ? format()->ascent() : (customItem()->placement() == Q3TextCustomItem::PlaceInline ? customItem()->ascent() : 0);
02063 #else
02064 return format()->ascent();
02065 #endif
02066 }
02067
02068 inline int Q3TextStringChar::descent() const
02069 {
02070 #ifndef QT_NO_TEXTCUSTOMITEM
02071 return !isCustom() ? format()->descent() : 0;
02072 #else
02073 return format()->descent();
02074 #endif
02075 }
02076
02077 #endif // QT_NO_RICHTEXT
02078
02079 #endif // Q3RICHTEXT_P_H