00001 #ifndef KOTEXTPARAG_H
00002 #define KOTEXTPARAG_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "koparaglayout.h"
00026
00027 #include "kotextformat.h"
00028 #include "korichtext.h"
00029 class KoTextFormatterBase;
00030 class KoTextParagLineStart;
00031 class KoTextString;
00032 class KoTextDocument;
00033 class KoParagCounter;
00034 class KoParagStyle;
00035 class KoTextCustomItem;
00036 class KoOasisContext;
00037 class KoSavingContext;
00038 class KoStyleCollection;
00039
00040 struct KoTextParagSelection
00041 {
00042 int start, end;
00043 };
00044
00045 #if defined(Q_TEMPLATEDLL)
00046
00047 template class QMap<int, KoTextParagSelection>;
00048 template class QMap<int, KoTextParagLineStart*>;
00049
00050 #endif
00051
00052 class KOTEXT_EXPORT KoTextParag
00053 {
00054 friend class KoTextDocument;
00055 friend class KoTextCursor;
00056
00057 public:
00058 KoTextParag( KoTextDocument *d, KoTextParag *pr = 0, KoTextParag *nx = 0, bool updateIds = TRUE );
00059 virtual ~KoTextParag();
00060
00061 KoTextString *string() const;
00062 KoTextStringChar *at( int i ) const;
00063 int leftGap() const;
00064 int length() const;
00065
00066
00067 int lastCharPos() const { return str->length()-2; }
00068
00069 void setFormat( KoTextFormat *fm );
00070 KoTextFormat *paragFormat() const;
00071
00072 KoTextDocument *document() const;
00073
00074 QRect rect() const;
00075 void setRect( const QRect& rect ) { r = rect; }
00076 void setHeight( int h ) { r.setHeight( h ); }
00077 void setWidth( int w ) { r.setWidth( w ); }
00078 void show();
00079 void hide();
00080 bool isVisible() const { return visible; }
00081
00082 KoTextParag *prev() const;
00083 KoTextParag *next() const;
00084 void setPrev( KoTextParag *s );
00085 void setNext( KoTextParag *s );
00086
00087 void insert( int index, const QString &s );
00088 void append( const QString &s, bool reallyAtEnd = FALSE );
00089 void truncate( int index );
00090 void remove( int index, int len );
00091
00092 void invalidate( int chr );
00093
00094 void move( int &dy );
00095 void format( int start = -1, bool doMove = TRUE );
00096
00097 bool isValid() const;
00098 bool hasChanged() const;
00099 void setChanged( bool b, bool recursive = FALSE );
00100 short int lineChanged();
00101 void setLineChanged( short int line );
00102
00103 int lineHeightOfChar( int i, int *bl = 0, int *y = 0 ) const;
00104 KoTextStringChar *lineStartOfChar( int i, int *index = 0, int *line = 0 ) const;
00105 int lines() const;
00106 KoTextStringChar *lineStartOfLine( int line, int *index = 0 ) const;
00107 int lineY( int l ) const;
00108 int lineBaseLine( int l ) const;
00109 int lineHeight( int l ) const;
00110 void lineInfo( int l, int &y, int &h, int &bl ) const;
00111
00112 void setSelection( int id, int start, int end );
00113 void removeSelection( int id );
00114 int selectionStart( int id ) const;
00115 int selectionEnd( int id ) const;
00116 bool hasSelection( int id ) const;
00117 bool hasAnySelection() const;
00118 bool fullSelected( int id ) const;
00119
00120
00121
00122
00123 void setParagId( int i );
00124 int paragId() const;
00125
00126 QMap<int, KoTextParagLineStart*> &lineStartList();
00127
00128 void setFormat( int index, int len, const KoTextFormat *f, bool useCollection = TRUE, int flags = -1 );
00129
00130 void setAlignment( uint a );
00131 void setAlignmentDirect( uint a ) { align = a; }
00132 uint alignment() const;
00133
00134 virtual void paint( QPainter &painter, const QColorGroup &cg, KoTextCursor *cursor, bool drawSelections,
00135 int clipx, int clipy, int clipw, int cliph );
00136
00137
00138 int topMargin() const;
00139 int bottomMargin() const;
00140 int leftMargin() const;
00141 int firstLineMargin() const;
00142 int rightMargin() const;
00143 int lineSpacing( int line ) const;
00144
00145 int numberOfSubParagraph() const;
00146 void registerFloatingItem( KoTextCustomItem *i );
00147 void unregisterFloatingItem( KoTextCustomItem *i );
00148
00149 void setFullWidth( bool b ) { fullWidth = b; }
00150 bool isFullWidth() const { return fullWidth; }
00151
00152 int customItems() const;
00153
00154 QBrush *background() const;
00155
00156 void setDocumentRect( const QRect &r );
00157 int documentWidth() const;
00158
00159 int documentX() const;
00160 int documentY() const;
00161 KoTextFormatCollection *formatCollection() const;
00162
00163 KoTextFormatterBase *formatter() const;
00164
00165 int widthUsed() const;
00166
00167 int nextTabDefault( int i, int x );
00168 int nextTab( int i, int x );
00169 int *tabArray() const;
00170 void setTabArray( int *a );
00171 void setTabStops( int tw );
00172
00173 void setNewLinesAllowed( bool b );
00174 bool isNewLinesAllowed() const;
00175
00176 virtual void join( KoTextParag *s );
00177 virtual void copyParagData( KoTextParag *parag );
00178
00179
00180
00181
00182 void setMovedDown( bool b ) { movedDown = b; }
00183 bool wasMovedDown() const { return movedDown; }
00184
00185 void setDirection( QChar::Direction d );
00186 QChar::Direction direction() const;
00187
00188
00189 void insertLineStart( int index, KoTextParagLineStart *ls );
00190
00191 protected:
00192 void drawLabel( QPainter* p, int x, int y, int w, int h, int base, const QColorGroup& cg );
00193 void drawCursorDefault( QPainter &painter, KoTextCursor *cursor, int curx, int cury, int curh, const QColorGroup &cg );
00194 void drawCursor( QPainter &painter, KoTextCursor *cursor, int curx, int cury, int curh, const QColorGroup &cg );
00195
00201 public:
00202 KoTextDocument * textDocument() const { return document(); }
00203
00204 KoTextFormat * paragraphFormat() const
00205 { return static_cast<KoTextFormat *>( paragFormat() ); }
00206
00209 virtual void setParagLayout( const KoParagLayout &layout, int flags = KoParagLayout::All, int marginIndex = -1 );
00210
00211 const KoParagLayout & paragLayout() { return m_layout; }
00212
00213
00214 double margin( QStyleSheetItem::Margin m ) { return m_layout.margins[m]; }
00215 const double * margins() const { return m_layout.margins; }
00216 void setMargin( QStyleSheetItem::Margin m, double _i );
00217 void setMargins( const double * _i );
00218
00220 double kwLineSpacing() const { return m_layout.lineSpacingValue(); }
00221
00222 void setLineSpacing( double _i );
00223
00224 KoParagLayout::SpacingType kwLineSpacingType() const { return m_layout.lineSpacingType; }
00225
00226 void setLineSpacingType( KoParagLayout::SpacingType _type );
00227
00228
00230 void setAlign( int align );
00232 int resolveAlignment() const;
00233
00236 int breakableTopMargin() const;
00237
00238
00239 KoBorder leftBorder() const { return m_layout.leftBorder; }
00240 KoBorder rightBorder() const { return m_layout.rightBorder; }
00241 KoBorder topBorder() const { return m_layout.topBorder; }
00242 KoBorder bottomBorder() const { return m_layout.bottomBorder; }
00243 bool hasBorder() const { return m_layout.hasBorder(); }
00244
00245 void setLeftBorder( const KoBorder & _brd ) { m_layout.leftBorder = _brd; }
00246 void setRightBorder( const KoBorder & _brd ) { m_layout.rightBorder = _brd; }
00247 void setTopBorder( const KoBorder & _brd );
00248 void setBottomBorder( const KoBorder & _brd );
00249
00250
00251 void setCounter( const KoParagCounter & counter );
00252 void setNoCounter();
00253 void setCounter( const KoParagCounter * pCounter )
00254 {
00255 if ( pCounter ) setCounter( *pCounter );
00256 else setNoCounter();
00257 }
00258 KoParagCounter *counter();
00259
00263 int counterWidth() const;
00264
00266 KoParagStyle *style() const { return m_layout.style; }
00268 void setStyle( KoParagStyle *style ) { m_layout.style = style; }
00270 void applyStyle( KoParagStyle *style );
00271
00273 const KoTabulatorList& tabList() const { return m_layout.tabList(); }
00275 void setTabList( const KoTabulatorList &tabList );
00276
00278 int shadowX( KoZoomHandler *zh ) const;
00280 int shadowY( KoZoomHandler *zh ) const;
00282 double shadowDistanceY() const;
00283
00285 void setCustomItem( int index, KoTextCustomItem * custom, KoTextFormat * currentFormat );
00287 void removeCustomItem( int index );
00288
00291 int findCustomItem( const KoTextCustomItem * custom ) const;
00292
00294 QMap<int, int>& tabCache() { return m_tabCache; }
00295
00297 QRect pixelRect( KoZoomHandler* zh ) const;
00298
00302 static void drawFontEffects( QPainter * p, KoTextFormat *format, KoZoomHandler *zh, QFont font, const QColor & color, int startX, int baseLine, int bw, int y, int h, QChar firstChar );
00303
00305 QString toString( int from = 0, int length = 0xffffffff) const;
00306
00308 void fixParagWidth( bool viewFormattingChars );
00309
00311 virtual void loadOasis( const QDomElement& e, KoOasisContext& context, KoStyleCollection *styleCollection, uint& pos );
00315 virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context,
00316 int from, int to, bool saveAnchorsFramesets = false ) const;
00317
00318 void loadOasisSpan( const QDomElement& parent, KoOasisContext& context, uint& pos );
00319
00320 void applyListStyle( KoOasisContext& context, int restartNumbering, bool orderedList, bool heading, int level );
00321
00322 #ifndef NDEBUG
00323 void printRTDebug( int );
00324 #endif
00325
00326 protected:
00327 void invalidateCounters();
00328 bool lineHyphenated( int l ) const;
00329
00330 void paintLines( QPainter &painter, const QColorGroup &cg, KoTextCursor *cursor, bool drawSelections,
00331 int clipx, int clipy, int clipw, int cliph );
00332
00333 void drawParagString( QPainter &painter, const QString &str, int start, int len, int startX,
00334 int lastY, int baseLine, int bw, int h, bool drawSelections,
00335 KoTextFormat *lastFormat, const QMemArray<int> &selectionStarts,
00336 const QMemArray<int> &selectionEnds, const QColorGroup &cg, bool rightToLeft, int line );
00337 void drawParagStringInternal( QPainter &painter, const QString &s, int start, int len, int startX,
00338 int lastY, int baseLine, int bw, int h, bool drawSelections,
00339 KoTextFormat *lastFormat, const QMemArray<int> &selectionStarts,
00340 const QMemArray<int> &selectionEnds, const QColorGroup &cg, bool rightToLeft, int line, KoZoomHandler* zh, bool drawingShadow );
00341
00343 enum { FormattingSpace = 1, FormattingBreak = 2, FormattingEndParag = 4, FormattingTabs = 8,
00344 AllFormattingChars = FormattingSpace | FormattingBreak | FormattingEndParag | FormattingTabs };
00345
00350 virtual void drawFormattingChars( QPainter &painter, int start, int len,
00351 int lastY_pix, int baseLine_pix, int h_pix,
00352 bool drawSelections,
00353 KoTextFormat *format, const QMemArray<int> &selectionStarts,
00354 const QMemArray<int> &selectionEnds, const QColorGroup &cg,
00355 bool rightToLeft, int line, KoZoomHandler* zh,
00356 int whichFormattingChars );
00357
00358 protected:
00359 KoParagLayout m_layout;
00360 QMap<int, int> m_tabCache;
00361
00362 private:
00363 KoParagLayout loadParagLayout( KoOasisContext& context, KoStyleCollection *styleCollection, bool findStyle );
00364
00365
00367 private:
00368 QMap<int, KoTextParagSelection> &selections() const;
00369 QPtrVector<QStyleSheetItem> &styleSheetItemsVec() const;
00370 QPtrList<KoTextCustomItem> &floatingItems() const;
00371
00372 QMap<int, KoTextParagLineStart*> lineStarts;
00373 int invalid;
00374 QRect r;
00375 KoTextParag *p, *n;
00376 KoTextDocument *doc;
00377 uint changed : 1;
00378 uint fullWidth : 1;
00379 uint newLinesAllowed : 1;
00380 uint visible : 1;
00381
00382 uint movedDown : 1;
00383 uint align : 4;
00384 short int m_lineChanged;
00385 int id;
00386 int m_wused;
00387 KoTextString *str;
00388 QMap<int, KoTextParagSelection> *mSelections;
00389 QPtrList<KoTextCustomItem> *mFloatingItems;
00390 KoTextFormat *defFormat;
00391 int *tArray;
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 };
00402
00403 inline int KoTextParag::length() const
00404 {
00405 return str->length();
00406 }
00407
00408 inline QRect KoTextParag::rect() const
00409 {
00410 return r;
00411 }
00412
00413 inline KoTextStringChar *KoTextParag::at( int i ) const
00414 {
00415 return &str->at( i );
00416 }
00417
00418 inline bool KoTextParag::isValid() const
00419 {
00420 return invalid == -1;
00421 }
00422
00423 inline bool KoTextParag::hasChanged() const
00424 {
00425 return changed;
00426 }
00427
00428 inline short int KoTextParag::lineChanged()
00429 {
00430 return m_lineChanged;
00431 }
00432
00433 inline void KoTextParag::append( const QString &s, bool reallyAtEnd )
00434 {
00435 if ( reallyAtEnd )
00436 insert( str->length(), s );
00437 else
00438 insert( QMAX( str->length() - 1, 0 ), s );
00439 }
00440
00441 inline KoTextParag *KoTextParag::prev() const
00442 {
00443 return p;
00444 }
00445
00446 inline KoTextParag *KoTextParag::next() const
00447 {
00448 return n;
00449 }
00450
00451 inline bool KoTextParag::hasAnySelection() const
00452 {
00453 return mSelections ? !selections().isEmpty() : FALSE;
00454 }
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 inline void KoTextParag::setParagId( int i )
00469 {
00470 id = i;
00471 }
00472
00473 inline int KoTextParag::paragId() const
00474 {
00475
00476
00477 return id;
00478 }
00479
00480 inline QMap<int, KoTextParagLineStart*> &KoTextParag::lineStartList()
00481 {
00482 return lineStarts;
00483 }
00484
00485 inline KoTextString *KoTextParag::string() const
00486 {
00487 return str;
00488 }
00489
00490 inline KoTextDocument *KoTextParag::document() const
00491 {
00492 return doc;
00493 }
00494
00495 inline void KoTextParag::setAlignment( uint a )
00496 {
00497 if ( a == align )
00498 return;
00499 align = a;
00500 invalidate( 0 );
00501 }
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514 inline KoTextFormat *KoTextParag::paragFormat() const
00515 {
00516 return defFormat;
00517 }
00518
00519 inline void KoTextParag::registerFloatingItem( KoTextCustomItem *i )
00520 {
00521 floatingItems().append( i );
00522 }
00523
00524 inline void KoTextParag::unregisterFloatingItem( KoTextCustomItem *i )
00525 {
00526 floatingItems().removeRef( i );
00527 }
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539 inline int KoTextParag::customItems() const
00540 {
00541 return mFloatingItems ? mFloatingItems->count() : 0;
00542
00543 }
00544
00545 inline QBrush *KoTextParag::background() const
00546 {
00547 #ifdef QTEXTTABLE_AVAILABLE
00548 return tc ? tc->backGround() : 0;
00549 #endif
00550 return 0;
00551 }
00552
00553 inline void KoTextParag::setNewLinesAllowed( bool b )
00554 {
00555 newLinesAllowed = b;
00556 }
00557
00558 inline bool KoTextParag::isNewLinesAllowed() const
00559 {
00560 return newLinesAllowed;
00561 }
00562
00563 #endif