00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
#ifndef QRICHTEXT_P_H
00045
#define QRICHTEXT_P_H
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
#ifndef QT_H
00060
#include "qstring.h"
00061
#include "qptrlist.h"
00062
#include "qrect.h"
00063
#include "qfontmetrics.h"
00064
#include "qintdict.h"
00065
#include "qmap.h"
00066
#include "qstringlist.h"
00067
#include "qfont.h"
00068
#include "qcolor.h"
00069
#include "qsize.h"
00070
#include "qvaluelist.h"
00071
#include "qvaluestack.h"
00072
#include "qobject.h"
00073
#include "qdict.h"
00074
#include "qtextstream.h"
00075
#include "qpixmap.h"
00076
#include "qstylesheet.h"
00077
#include "qptrvector.h"
00078
#include "qpainter.h"
00079
#include "qlayout.h"
00080
#include "qobject.h"
00081
#include <limits.h>
00082
#include "qcomplextext_p.h"
00083
#include "qapplication.h"
00084
#endif // QT_H
00085
00086
class KoTextParag;
00087
class KoTextString;
00088
class KoTextCursor;
00089
class KoTextCustomItem;
00090
class KoTextFlow;
00091
class KoTextDocument;
00092
00093
class KoTextFormatterBase;
00094
class KoTextIndent;
00095
class KoTextFormat;
00096
class KoTextFormatCollection;
00097
struct KoBidiContext;
00098
00100
class KCommand;
00101
class QDomElement;
00102
class KoZoomHandler;
00103
class KoTextFormatter;
00104
class KoParagVisitor;
00105
class KoTextDocCommand;
00106
#include <qmemarray.h>
00107
#include "koparaglayout.h"
00108
#include "korichtext.h"
00110
00111
00112
00113
class KoTextStringChar
00114 {
00115
friend class KoTextString;
00116
00117
public:
00118
00119 KoTextStringChar() : lineStart( 0 ), type( Regular ), startOfRun( 0 ) {d.format=0; }
00120 ~KoTextStringChar();
00121
00122
QChar c;
00123
00124
00125 uchar softBreak :1;
00126 uchar whiteSpace :1;
00127 uchar charStop :1;
00128 uchar wordStop :1;
00129
00130
00131
enum Type { Regular, Custom };
00132 uint lineStart : 1;
00133 Type type : 1;
00134 uint startOfRun : 1;
00135 uint rightToLeft : 1;
00136
00137
00138 Q_INT8 pixelxadj;
00139
short int pixelwidth;
00140
short int width;
00141
00142
int x;
00143
int height() const;
00144
int ascent() const;
00145
int descent() const;
00146
bool isCustom()
const {
return type == Custom; }
00147
KoTextFormat *format() const;
00148 KoTextCustomItem *customItem() const;
00149
void setFormat(
KoTextFormat *f );
00150
void setCustomItem( KoTextCustomItem *i );
00151
void loseCustomItem();
00152 struct CustomData
00153 {
00154
KoTextFormat *format;
00155 KoTextCustomItem *custom;
00156 };
00157
00158
union {
00159
KoTextFormat* format;
00160 CustomData* custom;
00161 } d;
00162
00163
private:
00164 KoTextStringChar &operator=(
const KoTextStringChar & ) {
00165
00166
return *
this;
00167 }
00168 KoTextStringChar(
const KoTextStringChar & );
00169
friend class KoComplexText;
00170
friend class KoTextParag;
00171 };
00172
00173
#if defined(Q_TEMPLATEDLL)
00174
00175
template class QMemArray<KoTextStringChar>;
00176
00177
#endif
00178
00179
class KoTextString
00180 {
00181
public:
00182
00183 KoTextString();
00184 KoTextString(
const KoTextString &s );
00185
virtual ~KoTextString();
00186
00187
QString toString() const;
00188 static
QString toString( const
QMemArray<KoTextStringChar> &data );
00189
QString toReverseString() const;
00190
00191 KoTextStringChar &at(
int i ) const;
00192
int length() const;
00193
00194
00195
00196
void insert(
int index, const
QString &s,
KoTextFormat *f );
00197
void insert(
int index, KoTextStringChar *c );
00198
void truncate(
int index );
00199
void remove(
int index,
int len );
00200
void clear();
00201
00202
void setFormat(
int index,
KoTextFormat *f,
bool useCollection );
00203
00204
void setBidi(
bool b ) { bidi = b; }
00205
bool isBidi() const;
00206
bool isRightToLeft() const;
00207
QChar::Direction direction() const;
00208
void setDirection(
QChar::Direction d ) { dir = d; bidiDirty = TRUE; }
00209
00211
void setNeedsSpellCheck(
bool b ) { bNeedsSpellCheck = b; }
00212
bool needsSpellCheck()
const {
return bNeedsSpellCheck; }
00213
00214
QMemArray<KoTextStringChar> subString(
int start = 0,
int len = 0xFFFFFF )
const;
00215
QString mid(
int start = 0,
int len = 0xFFFFFF )
const;
00216
QMemArray<KoTextStringChar> rawData()
const {
return data.copy(); }
00217
00218
void operator=(
const QString &s ) { clear(); insert( 0, s, 0 ); }
00219
void operator+=(
const QString &s );
00220
void prepend(
const QString &s ) { insert( 0, s, 0 ); }
00221
00222
00223
bool validCursorPosition(
int idx );
00224
int nextCursorPosition(
int idx );
00225
int previousCursorPosition(
int idx );
00226
00227
private:
00228
void checkBidi() const;
00229
00230
QMemArray<KoTextStringChar> data;
00231 uint bidiDirty : 1;
00232 uint bidi : 1;
00233 uint rightToLeft : 1;
00234 uint dir : 5;
00235 uint bNeedsSpellCheck : 1;
00236 };
00237
00238 inline
bool KoTextString::isBidi()
const
00239
{
00240
if ( bidiDirty )
00241 checkBidi();
00242
return bidi;
00243 }
00244
00245
inline bool KoTextString::isRightToLeft()
const
00246
{
00247
if ( bidiDirty )
00248 checkBidi();
00249
return rightToLeft;
00250 }
00251
00252
inline QChar::Direction KoTextString::direction()
const
00253
{
00254
return (QChar::Direction) dir;
00255 }
00256
00257
00258
00259
#if defined(Q_TEMPLATEDLL)
00260
00261
template class QValueStack<int>;
00262
template class QValueStack<KoTextParag*>;
00263
template class QValueStack<bool>;
00264
00265
#endif
00266
00267
class KoTextCursor
00268 {
00269
public:
00270 KoTextCursor( KoTextDocument *d );
00271 KoTextCursor();
00272 KoTextCursor(
const KoTextCursor &c );
00273 KoTextCursor &operator=(
const KoTextCursor &c );
00274
virtual ~KoTextCursor() {}
00275
00276
bool operator==(
const KoTextCursor &c )
const;
00277
bool operator!=(
const KoTextCursor &c )
const {
return !(*
this == c); }
00278
00279 KoTextDocument *document()
const {
return doc; }
00280
void setDocument( KoTextDocument *d );
00281
00282 KoTextParag *parag() const;
00283
int index() const;
00284
void setParag( KoTextParag *s,
bool restore = TRUE );
00285
00286
void gotoLeft();
00287
void gotoRight();
00288
void gotoNextLetter();
00289
void gotoPreviousLetter();
00290
void gotoUp();
00291
void gotoDown();
00292
void gotoLineEnd();
00293
void gotoLineStart();
00294
void gotoHome();
00295
void gotoEnd();
00296
void gotoPageUp(
int visibleHeight );
00297
void gotoPageDown(
int visibleHeight );
00298
void gotoNextWord();
00299
void gotoPreviousWord();
00300
void gotoWordLeft();
00301
void gotoWordRight();
00302
00303
void insert( const
QString &s,
bool checkNewLine,
QMemArray<KoTextStringChar> *formatting = 0 );
00304
void splitAndInsertEmptyParag(
bool ind = TRUE,
bool updateIds = TRUE );
00305
bool remove();
00306
bool removePreviousChar();
00307
void killLine();
00308
void indent();
00309
00310
bool atParagStart() const;
00311
bool atParagEnd() const;
00312
00313
void setIndex(
int i,
bool restore = TRUE );
00314
00315
void checkIndex();
00316
00317
int offsetX()
const {
return ox; }
00318
int offsetY()
const {
return oy; }
00319
00320 KoTextParag *topParag()
const {
return parags.isEmpty() ? string : parags.first(); }
00321
int totalOffsetX() const;
00322
int totalOffsetY() const;
00323
00324
bool place( const
QPoint &pos, KoTextParag *s,
bool link = false,
int *customItemIndex = 0 );
00325
void restoreState();
00326
00327
int x() const;
00328
int y() const;
00329
void fixCursorPosition();
00330
int nestedDepth()
const {
return (
int)indices.count(); }
00331
00332
private:
00333
enum Operation { EnterBegin, EnterEnd, Next, Prev, Up, Down };
00334
00335
void push();
00336
void pop();
00337
void processNesting( Operation op );
00338
void invalidateNested();
00339
void gotoIntoNested(
const QPoint &globalPos );
00340
00341 KoTextParag *string;
00342 KoTextDocument *doc;
00343
int idx, tmpIndex;
00344
int ox, oy;
00345
QValueStack<int> indices;
00346
QValueStack<KoTextParag*> parags;
00347
QValueStack<int> xOffsets;
00348
QValueStack<int> yOffsets;
00349
QValueStack<bool> nestedStack;
00350
bool nested;
00351
00352 };
00353
00354
00355
00356
class KoTextDocCommand
00357 {
00358
public:
00359
enum Commands { Invalid, Insert, Delete, Format, Alignment, ParagType };
00360
00361 KoTextDocCommand( KoTextDocument *d ) : doc( d ), cursor( d ) {}
00362
virtual ~KoTextDocCommand() {}
00363
virtual Commands type()
const {
return Invalid; };
00364
00365
virtual KoTextCursor *execute( KoTextCursor *c ) = 0;
00366
virtual KoTextCursor *unexecute( KoTextCursor *c ) = 0;
00367
00368
protected:
00369 KoTextDocument *doc;
00370 KoTextCursor cursor;
00371
00372 };
00373
00374
#if defined(Q_TEMPLATEDLL)
00375
00376
template class QPtrList<KoTextDocCommand>;
00377
00378
#endif
00379
00380
class KoTextDocCommandHistory
00381 {
00382
public:
00383 KoTextDocCommandHistory(
int s ) : current( -1 ), steps( s ) { history.setAutoDelete( TRUE ); }
00384
virtual ~KoTextDocCommandHistory() { clear(); }
00385
00386
void clear() { history.clear(); current = -1; }
00387
00388
void addCommand( KoTextDocCommand *cmd );
00389 KoTextCursor *undo( KoTextCursor *c );
00390 KoTextCursor *redo( KoTextCursor *c );
00391
00392
bool isUndoAvailable();
00393
bool isRedoAvailable();
00394
00395
void setUndoDepth(
int d ) { steps = d; }
00396
int undoDepth()
const {
return steps; }
00397
00398
int historySize()
const {
return history.count(); }
00399
int currentPosition()
const {
return current; }
00400
00401
private:
00402
QPtrList<KoTextDocCommand> history;
00403
int current, steps;
00404
00405 };
00406
00407
00408
00409
class KoTextCustomItem
00410 {
00411
public:
00412 KoTextCustomItem( KoTextDocument *p );
00413
virtual ~KoTextCustomItem();
00414
virtual void draw(
QPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const QColorGroup& cg,
bool selected ) ;
00415
00416
00417
virtual void finalize() {}
00418
00419
void move(
int x,
int y ) { xpos = x; ypos = y; }
00420
int x()
const {
return xpos; }
00421
int y()
const {
return ypos; }
00422
00423
00424
virtual void setFormat(
KoTextFormat * ) { }
00425
00426
00427
00428
enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
00429
virtual Placement placement()
const {
return PlaceInline; }
00430
bool placeInline() {
return placement() == PlaceInline; }
00431
00432
virtual bool ownLine()
const {
return FALSE; }
00433
00434
virtual void resize(
int nwidth ) { width = nwidth; }
00435
virtual void invalidate() {};
00436
00437
virtual bool isNested()
const {
return FALSE; }
00438
virtual int minimumWidth()
const {
return 0; }
00439
virtual int widthHint()
const {
return 0; }
00440
virtual int ascent()
const {
return height; }
00441
00442
virtual QString richText()
const {
return QString::null; }
00443
00444
int width;
00445
int height;
00446
00447
QRect geometry()
const {
return QRect( xpos, ypos, width, height ); }
00448
00449
virtual bool enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
bool atEnd = FALSE );
00450
virtual bool enterAt( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
const QPoint & );
00451
virtual bool next( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00452
virtual bool prev( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00453
virtual bool down( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00454
virtual bool up( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00455
00456
void setParagraph( KoTextParag * p ) { parag = p; }
00457 KoTextParag *paragraph()
const {
return parag; }
00458
00459
virtual void pageBreak(
int , KoTextFlow* ) {}
00460
00461 KoTextDocument *parent;
00462
00463
#include "kotextcustomitem.h"
00464
00465
protected:
00466
int xpos;
00467
int ypos;
00468
private:
00469 KoTextParag *parag;
00470 };
00471
00472
#if defined(Q_TEMPLATEDLL)
00473
00474
template class QMap<QString, QString>;
00475
00476
#endif
00477
00478
#if 0
00479
class KoTextImage :
public KoTextCustomItem
00480 {
00481
public:
00482 KoTextImage( KoTextDocument *p,
const QMap<QString, QString> &attr,
const QString& context,
00483
QMimeSourceFactory &factory );
00484
virtual ~KoTextImage();
00485
00486 Placement placement()
const {
return place; }
00487
00488
int widthHint()
const {
return width; }
00489
int minimumWidth()
const {
return width; }
00490
00491
QString richText() const;
00492
00493
void draw(
QPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch, const
QColorGroup& cg,
bool selected );
00494
00495 private:
00496
QRegion* reg;
00497
QPixmap pm;
00498 Placement place;
00499
int tmpwidth, tmpheight;
00500
QMap<
QString, QString> attributes;
00501 QString imgId;
00502
00503 };
00504 #endif
00505
00506 class KoTextHorizontalLine : public KoTextCustomItem
00507 {
00508
public:
00509 KoTextHorizontalLine( KoTextDocument *p,
const QMap<QString, QString> &attr,
const QString& context,
00510
QMimeSourceFactory &factory );
00511
virtual ~KoTextHorizontalLine();
00512
00513
00514
void draw(
QPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const QColorGroup& cg,
bool selected );
00515 QString richText() const;
00516
00517
bool ownLine()
const {
return TRUE; }
00518
00519
private:
00520
int tmpheight;
00521
QColor color;
00522
00523 };
00524
00525
#if defined(Q_TEMPLATEDLL)
00526
00527
template class QPtrList<KoTextCustomItem>;
00528
00529
#endif
00530
00531
class KoTextFlow
00532 {
00533
friend class KoTextDocument;
00534
friend class KoTextTableCell;
00535
00536
public:
00537 KoTextFlow();
00538
virtual ~KoTextFlow();
00539
00540
virtual void setWidth(
int width );
00541
int width()
const {
return w; }
00542
00543
00544
00545
00553
virtual void adjustMargins(
int yp,
int h,
int reqMinWidth,
int& leftMargin,
int& rightMargin,
int& pageWidth, KoTextParag* parag );
00554
00555
virtual void registerFloatingItem( KoTextCustomItem* item );
00556
virtual void unregisterFloatingItem( KoTextCustomItem* item );
00557
00558
00560
virtual int availableHeight() const;
00561 virtual
void drawFloatingItems(
QPainter* p,
int cx,
int cy,
int cw,
int ch, const
QColorGroup& cg,
bool selected );
00562
00563 virtual
int adjustFlow(
int y,
int w,
int h );
00564
00565 virtual
bool isEmpty();
00566
00567
void clear();
00568
00569 private:
00570
int w;
00571
00572
00573
QPtrList<KoTextCustomItem> leftItems;
00574
QPtrList<KoTextCustomItem> rightItems;
00575
00576 };
00577
00578 #ifdef QTEXTTABLE_AVAILABLE
00579 class KoTextTable;
00580
00581 class KoTextTableCell : public
QLayoutItem
00582 {
00583
friend class KoTextTable;
00584
00585
public:
00586 KoTextTableCell( KoTextTable* table,
00587
int row,
int column,
00588
const QMap<QString, QString> &attr,
00589
const QStyleSheetItem* style,
00590
const KoTextFormat& fmt,
const QString& context,
00591
QMimeSourceFactory &factory,
QStyleSheet *sheet,
const QString& doc );
00592 KoTextTableCell( KoTextTable* table,
int row,
int column );
00593
virtual ~KoTextTableCell();
00594
00595
QSize sizeHint() const ;
00596
QSize minimumSize() const ;
00597
QSize maximumSize() const ;
00598
QSizePolicy::ExpandData expanding() const;
00599
bool isEmpty() const;
00600
void setGeometry( const
QRect& ) ;
00601 QRect geometry() const;
00602
00603
bool hasHeightForWidth() const;
00604
int heightForWidth(
int ) const;
00605
00606
void setPainter(
QPainter*,
bool );
00607
00608
int row()
const {
return row_; }
00609
int column()
const {
return col_; }
00610
int rowspan()
const {
return rowspan_; }
00611
int colspan()
const {
return colspan_; }
00612
int stretch()
const {
return stretch_; }
00613
00614 KoTextDocument* richText() const {
return richtext; }
00615 KoTextTable* table()
const {
return parent; }
00616
00617
void draw(
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const QColorGroup& cg,
bool selected );
00618
00619
QBrush *backGround()
const {
return background; }
00620
virtual void invalidate();
00621
00622
int verticalAlignmentOffset() const;
00623
int horizontalAlignmentOffset() const;
00624
00625 private:
00626
QPainter* painter() const;
00627
QRect geom;
00628 KoTextTable* parent;
00629 KoTextDocument* richtext;
00630
int row_;
00631
int col_;
00632
int rowspan_;
00633
int colspan_;
00634
int stretch_;
00635
int maxw;
00636
int minw;
00637
bool hasFixedWidth;
00638
QBrush *background;
00639
int cached_width;
00640
int cached_sizehint;
00641
QMap<
QString, QString> attributes;
00642
int align;
00643 };
00644
00645 #if defined(Q_TEMPLATEDLL)
00646
00647 template class
QPtrList<KoTextTableCell>;
00648 template class
QMap<KoTextCursor*,
int>;
00649
00650 #endif
00651
00652 class KoTextTable: public KoTextCustomItem
00653 {
00654
friend class KoTextTableCell;
00655
00656
public:
00657 KoTextTable( KoTextDocument *p,
const QMap<QString, QString> &attr );
00658
virtual ~KoTextTable();
00659
00660
void setPainter(
QPainter *p,
bool adjust );
00661
void pageBreak(
int y, KoTextFlow* flow );
00662
void draw(
QPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
00663
const QColorGroup& cg,
bool selected );
00664
00665
bool noErase()
const {
return TRUE; }
00666
bool ownLine()
const {
return TRUE; }
00667 Placement placement()
const {
return place; }
00668
bool isNested()
const {
return TRUE; }
00669
void resize(
int nwidth );
00670
virtual void invalidate();
00672
00673
virtual bool enter( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
bool atEnd = FALSE );
00674
virtual bool enterAt( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
const QPoint &pos );
00675
virtual bool next( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00676
virtual bool prev( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00677
virtual bool down( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00678
virtual bool up( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00679
00680 QString richText() const;
00681
00682
int minimumWidth()
const {
return layout ? layout->minimumSize().width() : 0; }
00683
int widthHint()
const {
return ( layout ? layout->sizeHint().width() : 0 ) + 2 * outerborder; }
00684
00685
QPtrList<KoTextTableCell> tableCells()
const {
return cells; }
00686
00687
QRect geometry()
const {
return layout ? layout->geometry() :
QRect(); }
00688
bool isStretching()
const {
return stretch; }
00689
00690
private:
00691
void format(
int &w );
00692
void addCell( KoTextTableCell* cell );
00693
00694
private:
00695
QGridLayout* layout;
00696
QPtrList<KoTextTableCell> cells;
00697
QPainter* painter;
00698
int cachewidth;
00699
int fixwidth;
00700
int cellpadding;
00701
int cellspacing;
00702
int border;
00703
int outerborder;
00704
int stretch;
00705
int innerborder;
00706
int us_cp, us_ib, us_b, us_ob, us_cs;
00707
QMap<QString, QString> attributes;
00708
QMap<KoTextCursor*, int> currCell;
00709 Placement place;
00710
void adjustCells(
int y ,
int shift );
00711
int pageBreakFor;
00712 };
00713
#endif // QTEXTTABLE_AVAILABLE
00714
00715
00716
00717
class KoTextTableCell;
00718
00719
struct KoTextDocumentSelection
00720 {
00721 KoTextCursor startCursor, endCursor;
00722
bool swapped;
00723 };
00724
00725
00726
00727
00728
class KoTextDocDeleteCommand :
public KoTextDocCommand
00729 {
00730
public:
00731 KoTextDocDeleteCommand( KoTextDocument *d,
int i,
int idx,
const QMemArray<KoTextStringChar> &str );
00732
00733
virtual ~KoTextDocDeleteCommand();
00734
00735 Commands type()
const {
return Delete; }
00736 KoTextCursor *execute( KoTextCursor *c );
00737 KoTextCursor *unexecute( KoTextCursor *c );
00738
00739
protected:
00740
int id, index;
00741 KoTextParag *parag;
00742
QMemArray<KoTextStringChar> text;
00743
00744 };
00745
00746
#if 0
00747
class KoTextDocInsertCommand :
public KoTextDocDeleteCommand
00748 {
00749
public:
00750 KoTextDocInsertCommand( KoTextDocument *d,
int i,
int idx,
const QMemArray<KoTextStringChar> &str )
00751 : KoTextDocDeleteCommand( d, i, idx, str ) {}
00752 KoTextDocInsertCommand( KoTextParag *p,
int idx,
const QMemArray<KoTextStringChar> &str )
00753 : KoTextDocDeleteCommand( p, idx, str ) {}
00754
virtual ~KoTextDocInsertCommand() {}
00755
00756 Commands type()
const {
return Insert; }
00757 KoTextCursor *execute( KoTextCursor *c ) {
return KoTextDocDeleteCommand::unexecute( c ); }
00758 KoTextCursor *unexecute( KoTextCursor *c ) {
return KoTextDocDeleteCommand::execute( c ); }
00759
00760 };
00761
#endif
00762
00763
class KoTextDocFormatCommand :
public KoTextDocCommand
00764 {
00765
public:
00766 KoTextDocFormatCommand( KoTextDocument *d,
int sid,
int sidx,
int eid,
int eidx,
const QMemArray<KoTextStringChar> &old,
const KoTextFormat *f,
int fl );
00767
virtual ~KoTextDocFormatCommand();
00768
00769 Commands type()
const {
return Format; }
00770 KoTextCursor *execute( KoTextCursor *c );
00771 KoTextCursor *unexecute( KoTextCursor *c );
00772
00773
protected:
00774
int startId, startIndex, endId, endIndex;
00775
KoTextFormat *format;
00776
QMemArray<KoTextStringChar> oldFormats;
00777
int flags;
00778
00779 };
00780
00781
class KoTextAlignmentCommand :
public KoTextDocCommand
00782 {
00783
public:
00784 KoTextAlignmentCommand( KoTextDocument *d,
int fParag,
int lParag,
int na,
const QMemArray<int> &oa );
00785
virtual ~KoTextAlignmentCommand() {}
00786
00787 Commands type()
const {
return Alignment; }
00788 KoTextCursor *execute( KoTextCursor *c );
00789 KoTextCursor *unexecute( KoTextCursor *c );
00790
00791
private:
00792
int firstParag, lastParag;
00793
int newAlign;
00794
QMemArray<int> oldAligns;
00795
00796 };
00797
00798
00799
00800
struct KoTextParagSelection
00801 {
00802
int start, end;
00803 };
00804
00805
struct KoTextParagLineStart
00806 {
00807 KoTextParagLineStart() : y( 0 ), baseLine( 0 ), h( 0 ), lineSpacing( 0 ), hyphenated( false )
00808 #ifndef QT_NO_COMPLEXTEXT
00809 , bidicontext( 0 )
00810 #endif
00811 { }
00812 KoTextParagLineStart( ushort y_, ushort bl, ushort h_ ) : y( y_ ), baseLine( bl ), h( h_ ),
00813 lineSpacing( 0 ), hyphenated( false ),
00814 w( 0 )
00815 #ifndef QT_NO_COMPLEXTEXT
00816 , bidicontext( 0 )
00817 #endif
00818 { }
00819
#ifndef QT_NO_COMPLEXTEXT
00820
KoTextParagLineStart( KoBidiContext *c, KoBidiStatus s ) : y(0), baseLine(0), h(0),
00821 lineSpacing( 0 ), hyphenated( false ),
00822 status( s ), bidicontext( c ) {
if ( bidicontext ) bidicontext->ref(); }
00823
#endif
00824
00825
virtual ~KoTextParagLineStart()
00826 {
00827
#ifndef QT_NO_COMPLEXTEXT
00828
if ( bidicontext && bidicontext->deref() )
00829
delete bidicontext;
00830
#endif
00831
}
00832
00833
#ifndef QT_NO_COMPLEXTEXT
00834
void setContext( KoBidiContext *c ) {
00835
if ( c == bidicontext )
00836
return;
00837
if ( bidicontext && bidicontext->deref() )
00838
delete bidicontext;
00839 bidicontext = c;
00840
if ( bidicontext )
00841 bidicontext->ref();
00842 }
00843 KoBidiContext *context()
const {
return bidicontext; }
00844
#endif
00845
00846
public:
00847 ushort y, baseLine, h;
00848
short lineSpacing;
00849
bool hyphenated;
00850
#ifndef QT_NO_COMPLEXTEXT
00851
KoBidiStatus status;
00852
#endif
00853
int w;
00854
00855
private:
00856
#ifndef QT_NO_COMPLEXTEXT
00857
KoBidiContext *bidicontext;
00858
#endif
00859
};
00860
00861
#if defined(Q_TEMPLATEDLL)
00862
00863
template class QMap<int, KoTextParagSelection>;
00864
template class QMap<int, KoTextParagLineStart*>;
00865
00866
#endif
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
class KoTextParag
00877 {
00878
friend class KoTextDocument;
00879
friend class KoTextCursor;
00880
00881
public:
00882 KoTextParag( KoTextDocument *d, KoTextParag *pr = 0, KoTextParag *nx = 0,
bool updateIds = TRUE );
00883
virtual ~KoTextParag();
00884
00885 KoTextString *string() const;
00886 KoTextStringChar *at(
int i ) const;
00887
int leftGap() const;
00888
int length() const;
00889
00890
void setFormat(
KoTextFormat *fm );
00891
KoTextFormat *paragFormat() const;
00892
00893 KoTextDocument *document() const;
00894
00895
QRect rect() const;
00896
void setRect( const
QRect& rect ) { r = rect; }
00897
void setHeight(
int h ) { r.setHeight( h ); }
00898
void setWidth(
int w ) { r.setWidth( w ); }
00899
void show();
00900
void hide();
00901
bool isVisible()
const {
return visible; }
00902
00903
00904
00905
00906 KoTextParag *prev() const;
00907 KoTextParag *next() const;
00908
void setPrev( KoTextParag *s );
00909
void setNext( KoTextParag *s );
00910
00911
void insert(
int index, const QString &s );
00912
void append( const QString &s,
bool reallyAtEnd = FALSE );
00913
void truncate(
int index );
00914
void remove(
int index,
int len );
00915
00916
void invalidate(
int chr );
00917
00918
void move(
int &dy );
00919
void format(
int start = -1,
bool doMove = TRUE );
00920
00921
bool isValid() const;
00922
bool hasChanged() const;
00923
void setChanged(
bool b,
bool recursive = FALSE );
00924
short int lineChanged();
00925
void setLineChanged(
short int line );
00926
00927
int lineHeightOfChar(
int i,
int *bl = 0,
int *y = 0 ) const;
00928 KoTextStringChar *lineStartOfChar(
int i,
int *index = 0,
int *line = 0 ) const;
00929
int lines() const;
00930 KoTextStringChar *lineStartOfLine(
int line,
int *index = 0 ) const;
00931
int lineY(
int l ) const;
00932
int lineBaseLine(
int l ) const;
00933
int lineHeight(
int l ) const;
00934
void lineInfo(
int l,
int &y,
int &h,
int &bl ) const;
00935
00936
void setSelection(
int id,
int start,
int end );
00937
void removeSelection(
int id );
00938
int selectionStart(
int id ) const;
00939
int selectionEnd(
int id ) const;
00940
bool hasSelection(
int id ) const;
00941
bool hasAnySelection() const;
00942
bool fullSelected(
int id ) const;
00943
00944
00945
00946
00947
void setParagId(
int i );
00948
int paragId() const;
00949
00950
00951
00952
00953
void indent(
int *oldIndent = 0,
int *newIndent = 0 );
00954
00955
00956
00957
00958
QMap<
int, KoTextParagLineStart*> &lineStartList();
00959
00960
void setFormat(
int index,
int len, const
KoTextFormat *f,
bool useCollection = TRUE,
int flags = -1 );
00961
00962
void setAlignment( uint a );
00963
void setAlignmentDirect( uint a ) { align = a; }
00964 uint alignment() const;
00965
00966 virtual
void paint(
QPainter &painter, const
QColorGroup &cg, KoTextCursor *cursor,
bool drawSelections,
00967
int clipx,
int clipy,
int clipw,
int cliph );
00968
00969
00970
int topMargin() const;
00971
int bottomMargin() const;
00972
int leftMargin() const;
00973
int firstLineMargin() const;
00974
int rightMargin() const;
00975
int lineSpacing(
int line ) const;
00976
00977
int numberOfSubParagraph() const;
00978
void registerFloatingItem( KoTextCustomItem *i );
00979
void unregisterFloatingItem( KoTextCustomItem *i );
00980
00981
void setFullWidth(
bool b ) { fullWidth = b; }
00982
bool isFullWidth()
const {
return fullWidth; }
00983
00984
#ifdef QTEXTTABLE_AVAILABLE
00985
KoTextTableCell *tableCell()
const {
return tc; }
00986
void setTableCell( KoTextTableCell *c ) { tc = c; }
00987
#endif
00988
00989
00990
00991
int customItems() const;
00992
00993
QBrush *background() const;
00994
00995
void setDocumentRect( const
QRect &r );
00996
int documentWidth() const;
00997
00998
int documentX() const;
00999
int documentY() const;
01000 KoTextFormatCollection *formatCollection() const;
01001
01002 KoTextFormatterBase *formatter() const;
01003
01004
int widthUsed() const;
01005
01006
int nextTabDefault(
int i,
int x );
01007
int nextTab(
int i,
int x );
01008
int *tabArray() const;
01009
void setTabArray(
int *a );
01010
void setTabStops(
int tw );
01011
01012
01013
01014
01015
void setNewLinesAllowed(
bool b );
01016
bool isNewLinesAllowed() const;
01017
01018 QString richText() const;
01019
01020
01021
01022
01023
01024
01025 virtual
void join( KoTextParag *s );
01026 virtual
void copyParagData( KoTextParag *parag );
01027
01028
void setBreakable(
bool b ) { breakable = b; }
01029
bool isBreakable()
const {
return breakable; }
01030
01031
01032
01033
01034
01035
01036
01037
void setMovedDown(
bool b ) { movedDown = b; }
01038
bool wasMovedDown()
const {
return movedDown; }
01039
01040
void setDirection( QChar::Direction d );
01041 QChar::Direction direction() const;
01042
01043
01044
void insertLineStart(
int index, KoTextParagLineStart *ls );
01045
01046 protected:
01047
void drawLabel(
QPainter* p,
int x,
int y,
int w,
int h,
int base, const
QColorGroup& cg );
01048
void drawCursorDefault(
QPainter &painter, KoTextCursor *cursor,
int curx,
int cury,
int curh, const
QColorGroup &cg );
01049
void drawCursor(
QPainter &painter, KoTextCursor *cursor,
int curx,
int cury,
int curh, const
QColorGroup &cg );
01050
01051 #include "kotextparag.h"
01052
01053 private:
01054
QMap<
int, KoTextParagSelection> &selections() const;
01055
QPtrVector<
QStyleSheetItem> &styleSheetItemsVec() const;
01056
QPtrList<KoTextCustomItem> &floatingItems() const;
01057
01058
QMap<
int, KoTextParagLineStart*> lineStarts;
01059
int invalid;
01060
QRect r;
01061 KoTextParag *p, *n;
01062 KoTextDocument *doc;
01063 uint changed : 1;
01064
01065
01066
01067 uint fullWidth : 1;
01068 uint newLinesAllowed : 1;
01069
01070 uint visible : 1;
01071 uint breakable : 1;
01072
01073 uint movedDown : 1;
01074 uint align : 4;
01075
short int m_lineChanged;
01076
int id;
01077
int m_wused;
01078 KoTextString *str;
01079
QMap<
int, KoTextParagSelection> *mSelections;
01080
QPtrList<KoTextCustomItem> *mFloatingItems;
01081
01082
KoTextFormat *defFormat;
01083
01084
int *tArray;
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097 };
01098
01099
01100
01101 class KoTextFormatterBase
01102 {
01103
public:
01104 KoTextFormatterBase();
01105
virtual ~KoTextFormatterBase() {}
01106
virtual bool format( KoTextDocument *doc, KoTextParag *parag,
int start,
const QMap<int, KoTextParagLineStart*> &oldLineStarts,
int& y,
int& widthUsed ) = 0;
01107
virtual int formatVertically( KoTextDocument* doc, KoTextParag* parag );
01108
01109
01110
virtual void postFormat( KoTextParag* parag ) = 0;
01111
01112
bool isWrapEnabled( KoTextParag *p )
const {
if ( !wrapEnabled )
return FALSE;
if ( p && !p->isBreakable() )
return FALSE;
return TRUE;}
01113
int wrapAtColumn()
const {
return wrapColumn;}
01114
virtual void setWrapEnabled(
bool b ) { wrapEnabled = b; }
01115
virtual void setWrapAtColumn(
int c ) { wrapColumn = c; }
01116
virtual void setAllowBreakInWords(
bool b ) { biw = b; }
01117
bool allowBreakInWords()
const {
return biw; }
01118
01119
01120
void setViewFormattingChars(
bool b ) { m_bViewFormattingChars = b; }
01121
bool viewFormattingChars()
const {
return m_bViewFormattingChars; }
01122
01123
bool isBreakable( KoTextString *string,
int pos )
const;
01124
bool isStretchable( KoTextString *string,
int pos )
const;
01125
01126
protected:
01127
01128
01129
01130
01131
#ifndef QT_NO_COMPLEXTEXT
01132
virtual KoTextParagLineStart *bidiReorderLine( KoTextParag *parag, KoTextString *string, KoTextParagLineStart *line, KoTextStringChar *start,
01133 KoTextStringChar *last,
int align,
int space );
01134
#endif
01135
01136
private:
01137
int wrapColumn;
01138
bool wrapEnabled;
01139
bool m_bViewFormattingChars;
01140
bool biw;
01141
bool unused;
01142
01143
#ifdef HAVE_THAI_BREAKS
01144
static QCString *thaiCache;
01145
static KoTextString *cachedString;
01146
static ThBreakIterator *thaiIt;
01147
#endif
01148
};
01149
01150
01151
01152
01153
class KoTextIndent
01154 {
01155
public:
01156 KoTextIndent();
01157
virtual ~KoTextIndent() {}
01158
01159
virtual void indent( KoTextDocument *doc, KoTextParag *parag,
int *oldIndent = 0,
int *newIndent = 0 ) = 0;
01160
01161 };
01162
01163
01164
01165
#if 0
01166
class KoTextPreProcessor
01167 {
01168
public:
01169
enum Ids {
01170 Standard = 0
01171 };
01172
01173 KoTextPreProcessor() {}
01174
virtual ~KoTextPreProcessor() {}
01175
01176
virtual void process( KoTextDocument *doc, KoTextParag *,
int,
bool = TRUE ) = 0;
01177
virtual KoTextFormat *format(
int id ) = 0;
01178
01179 };
01180
#endif
01181
01182
01183
01184
01185
01186
inline int KoTextString::length()
const
01187
{
01188
return data.size();
01189 }
01190
01191
inline void KoTextString::operator+=(
const QString &s )
01192 {
01193 insert( length(), s, 0 );
01194 }
01195
01196
inline int KoTextParag::length()
const
01197
{
01198
return str->length();
01199 }
01200
01201
inline QRect KoTextParag::rect()
const
01202
{
01203
return r;
01204 }
01205
01206
inline KoTextParag *KoTextCursor::parag()
const
01207
{
01208
return string;
01209 }
01210
01211
inline int KoTextCursor::index()
const
01212
{
01213
return idx;
01214 }
01215
01216
inline void KoTextCursor::setParag( KoTextParag *s,
bool restore )
01217 {
01218
if ( restore )
01219 restoreState();
01220 idx = 0;
01221 string = s;
01222 tmpIndex = -1;
01223 }
01224
01225
inline void KoTextCursor::checkIndex()
01226 {
01227
if ( idx >= string->length() )
01228 idx = string->length() - 1;
01229 }
01230
01231
01232
01233
inline KoTextStringChar &KoTextString::at(
int i )
const
01234
{
01235
return data[ i ];
01236 }
01237
01238
inline QString KoTextString::toString()
const
01239
{
01240
return toString( data );
01241 }
01242
01243
01244
01245
inline KoTextStringChar *KoTextParag::at(
int i )
const
01246
{
01247
return &str->at( i );
01248 }
01249
01250
inline bool KoTextParag::isValid()
const
01251
{
01252
return invalid == -1;
01253 }
01254
01255
inline bool KoTextParag::hasChanged()
const
01256
{
01257
return changed;
01258 }
01259
01260
inline short int KoTextParag::lineChanged()
01261 {
01262
return m_lineChanged;
01263 }
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
inline void KoTextParag::append(
const QString &s,
bool reallyAtEnd )
01279 {
01280
if ( reallyAtEnd )
01281 insert( str->length(), s );
01282
else
01283 insert( QMAX( str->length() - 1, 0 ), s );
01284 }
01285
01286
inline KoTextParag *KoTextParag::prev()
const
01287
{
01288
return p;
01289 }
01290
01291
inline KoTextParag *KoTextParag::next()
const
01292
{
01293
return n;
01294 }
01295
01296
inline bool KoTextParag::hasAnySelection()
const
01297
{
01298
return mSelections ? !selections().isEmpty() : FALSE;
01299 }
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
inline void KoTextParag::setParagId(
int i )
01314 {
01315
id = i;
01316 }
01317
01318
inline int KoTextParag::paragId()
const
01319
{
01320
01321
01322
return id;
01323 }
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
inline QMap<int, KoTextParagLineStart*> &KoTextParag::lineStartList()
01336 {
01337
return lineStarts;
01338 }
01339
01340
inline KoTextString *KoTextParag::string()
const
01341
{
01342
return str;
01343 }
01344
01345
inline KoTextDocument *KoTextParag::document()
const
01346
{
01347
return doc;
01348 }
01349
01350
inline void KoTextParag::setAlignment( uint a )
01351 {
01352
if ( a == align )
01353
return;
01354 align = a;
01355 invalidate( 0 );
01356 }
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
inline KoTextFormat *KoTextParag::paragFormat()
const
01370
{
01371
return defFormat;
01372 }
01373
01374
inline void KoTextParag::registerFloatingItem( KoTextCustomItem *i )
01375 {
01376 floatingItems().append( i );
01377 }
01378
01379
inline void KoTextParag::unregisterFloatingItem( KoTextCustomItem *i )
01380 {
01381 floatingItems().removeRef( i );
01382 }
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
inline int KoTextParag::customItems()
const
01395
{
01396
return mFloatingItems ? mFloatingItems->count() : 0;
01397
01398 }
01399
01400
inline QBrush *KoTextParag::background()
const
01401
{
01402
#ifdef QTEXTTABLE_AVAILABLE
01403
return tc ? tc->backGround() : 0;
01404
#endif
01405
return 0;
01406 }
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
inline void KoTextParag::setNewLinesAllowed(
bool b )
01425 {
01426 newLinesAllowed = b;
01427 }
01428
01429
inline bool KoTextParag::isNewLinesAllowed()
const
01430
{
01431
return newLinesAllowed;
01432 }
01433
01434
01435
01436
inline KoTextFormat *KoTextStringChar::format()
const
01437
{
01438
return (type == Regular) ? d.format : d.custom->format;
01439 }
01440
01441
inline KoTextCustomItem *KoTextStringChar::customItem()
const
01442
{
01443
return isCustom() ? d.custom->custom : 0;
01444 }
01445
01446
#endif