F:/KPlato/koffice/libs/kotext/KoTextParag.h

Aller à la documentation de ce fichier.
00001 #ifndef KOTEXTPARAG_H
00002 #define KOTEXTPARAG_H
00003 
00004 /* This file is part of the KDE project
00005    Copyright (C) 2001-2005 David Faure <faure@kde.org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 
00023 // -*- c++ -*-
00024 
00025 #include "KoParagLayout.h"
00026 
00027 #include "KoTextFormat.h"
00028 #include "KoRichText.h" // for KoTextString
00029 #include "KoTabulator.h"
00030 //Added by qt3to4:
00031 #include <Q3PtrList>
00032 #include <Q3MemArray>
00033 class KoTextFormatterBase;
00034 class KoTextParagLineStart;
00035 class KoTextString;
00036 class KoTextDocument;
00037 class KoParagCounter;
00038 class KoParagStyle;
00039 class KoTextCustomItem;
00040 class KoOasisContext;
00041 class KoSavingContext;
00042 class KoStyleCollection;
00043 
00044 struct KoTextParagSelection
00045 {
00046     int start, end;
00047 };
00048 
00049 #if defined(Q_TEMPLATEDLL)
00050 #ifndef Q_MOC_RUN
00051 template class QMap<int, KoTextParagSelection>;
00052 template class QMap<int, KoTextParagLineStart*>;
00053 #endif
00054 #endif
00055 
00056 class KOTEXT_EXPORT KoTextParag
00057 {
00058     friend class KoTextDocument;
00059     friend class KoTextCursor;
00060 
00061 public:
00062     KoTextParag( KoTextDocument *d, KoTextParag *pr = 0, KoTextParag *nx = 0, bool updateIds = true );
00063     virtual ~KoTextParag();
00064 
00065     KoTextString *string() const;
00066     KoTextStringChar *at( int i ) const;
00067     int leftGap() const;
00068     int length() const;
00069 
00070     // Abstraction over the trailing-space thing, so that it can be removed later
00071     int lastCharPos() const { return str->length()-2; }
00072 
00073     void setFormat( KoTextFormat *fm );
00074     KoTextFormat *paragFormat() const;
00075 
00076     KoTextDocument *document() const;
00077 
00078     QRect rect() const;
00079     void setRect( const QRect& rect ) { r = rect; }
00080     void setHeight( int h ) { r.setHeight( h ); }
00081     void setWidth( int w ) { r.setWidth( w ); }
00082     void show();
00083     void hide();
00084     bool isVisible() const { return visible; }
00085 
00086     KoTextParag *prev() const;
00087     KoTextParag *next() const;
00088     void setPrev( KoTextParag *s );
00089     void setNext( KoTextParag *s );
00090 
00091     void insert( int index, const QString &s );
00092     void append( const QString &s, bool reallyAtEnd = false );
00093     void truncate( int index );
00094     void remove( int index, int len );
00095 
00096     void move( int &dy );
00097     void format( int start = -1, bool doMove = true );
00098 
00100     void invalidate( int chr /*ignored*/ = 0 );
00102     bool isValid() const;
00103 
00105     bool hasChanged() const;
00106     void setChanged( bool b, bool recursive = false );
00107     short int lineChanged(); // first line that has been changed.
00108     void setLineChanged( short int line );
00109 
00110     int lineHeightOfChar( int i, int *bl = 0, int *y = 0 ) const;
00111     KoTextStringChar *lineStartOfChar( int i, int *index = 0, int *line = 0 ) const;
00112     int lines() const;
00113     KoTextStringChar *lineStartOfLine( int line, int *index = 0 ) const;
00114     int lineY( int l ) const;
00115     int lineBaseLine( int l ) const;
00116     int lineHeight( int l ) const;
00117     void lineInfo( int l, int &y, int &h, int &bl ) const;
00118 
00119     void setSelection( int id, int start, int end );
00120     void removeSelection( int id );
00121     int selectionStart( int id ) const;
00122     int selectionEnd( int id ) const;
00123     bool hasSelection( int id ) const;
00124     bool hasAnySelection() const;
00125     bool fullSelected( int id ) const;
00126 
00127     //void setEndState( int s );
00128     //int endState() const;
00129 
00130     void setParagId( int i );
00131     int paragId() const;
00132 
00133     QMap<int, KoTextParagLineStart*> &lineStartList();
00134 
00135     void setFormat( int index, int len, const KoTextFormat *f, bool useCollection = true, int flags = -1 );
00136 
00137     void setAlignment( uint a );
00138     void setAlignmentDirect( uint a ) { align = a; }
00139     uint alignment() const;
00140 
00141     virtual void paint( QPainter &painter, const QColorGroup &cg, KoTextCursor *cursor, bool drawSelections,
00142                        int clipx, int clipy, int clipw, int cliph ); // kotextparag.cc
00143 
00144 
00145     int topMargin() const;
00146     int bottomMargin() const;
00147     int leftMargin() const;
00148     int firstLineMargin() const;
00149     int rightMargin() const;
00150     int lineSpacing( int line ) const;
00151     int calculateLineSpacing( int line, int start, int last ) const;
00152 
00153     void registerFloatingItem( KoTextCustomItem *i );
00154     void unregisterFloatingItem( KoTextCustomItem *i );
00155 
00156     void setFullWidth( bool b ) { fullWidth = b; }
00157     bool isFullWidth() const { return fullWidth; }
00158 
00159     int customItems() const;
00160 
00161     void setDocumentRect( const QRect &r );
00162     int documentWidth() const;
00163     //int documentVisibleWidth() const;
00164     int documentX() const;
00165     int documentY() const;
00166     KoTextFormatCollection *formatCollection() const;
00167     //void setFormatter( KoTextFormatterBase *f );
00168     KoTextFormatterBase *formatter() const;
00169     //int minimumWidth() const;
00170     int widthUsed() const;
00171 
00172     int nextTabDefault( int i, int x );
00173     int nextTab( int i, int x, int availableWidth );
00174     int *tabArray() const;
00175     void setTabArray( int *a );
00176     void setTabStops( int tw );
00177 
00180     void setNewLinesAllowed( bool b );
00182     bool isNewLinesAllowed() const;
00183 
00184     virtual void join( KoTextParag *s );
00185     virtual void copyParagData( KoTextParag *parag );
00186 
00187     //void setBreakable( bool b ) { breakable = b; }
00188     //bool isBreakable() const { return breakable; }
00189 
00190     void setMovedDown( bool b ) { movedDown = b; }
00191     bool wasMovedDown() const { return movedDown; }
00192 
00193     void setDirection( QChar::Direction d );
00194     QChar::Direction direction() const;
00195 
00197     void setPartOfTableOfContents( bool b ) { m_toc = b; }
00198     bool partOfTableOfContents() const { return m_toc; }
00199 
00200     // For KoTextFormatter only
00201     void insertLineStart( int index, KoTextParagLineStart *ls );
00202 
00203 protected:
00204     void drawLabel( QPainter* p, int x, int y, int w, int h, int base, const QColorGroup& cg );
00205     void drawCursorDefault( QPainter &painter, KoTextCursor *cursor, int curx, int cury, int curh, const QColorGroup &cg );
00206     void drawCursor( QPainter &painter, KoTextCursor *cursor, int curx, int cury, int curh, const QColorGroup &cg );
00207 
00213 public:
00214     KoTextDocument * textDocument() const { return document(); }
00215 
00216     KoTextFormat * paragraphFormat() const
00217     { return static_cast<KoTextFormat *>( paragFormat() ); }
00218 
00221     virtual void setParagLayout( const KoParagLayout &layout, int flags = KoParagLayout::All,
00222                                  int marginIndex = -1 );
00223 
00224     const KoParagLayout & paragLayout() { return m_layout; }
00225 
00226     // Margins
00227     double margin( Q3StyleSheetItem::Margin m ) { return m_layout.margins[m]; }
00228     const double * margins() const { return m_layout.margins; }
00229     void setMargin( Q3StyleSheetItem::Margin m, double _i );
00230     void setMargins( const double * _i );
00231 
00233     double kwLineSpacing() const { return m_layout.lineSpacingValue(); }
00234 
00235     void setLineSpacing( double _i );
00236 
00237     KoParagLayout::SpacingType kwLineSpacingType() const { return m_layout.lineSpacingType; }
00238 
00239     void setLineSpacingType( KoParagLayout::SpacingType _type );
00240 
00241 
00243     void setAlign( int align );
00245     int resolveAlignment() const;
00246 
00249     int breakableTopMargin() const;
00250 
00251     // Borders
00252     KoBorder leftBorder() const { return m_layout.leftBorder; }
00253     KoBorder rightBorder() const { return m_layout.rightBorder; }
00254     KoBorder topBorder() const { return m_layout.topBorder; }
00255     KoBorder bottomBorder() const { return m_layout.bottomBorder; }
00256     bool hasBorder() const { return m_layout.hasBorder(); }
00257     bool joinBorder() const { return m_layout.joinBorder; }
00258 
00259     void setLeftBorder( const KoBorder & _brd ) { m_layout.leftBorder = _brd; }
00260     void setRightBorder( const KoBorder & _brd ) { m_layout.rightBorder = _brd; }
00261     void setTopBorder( const KoBorder & _brd );
00262     void setBottomBorder( const KoBorder & _brd );
00263     void setJoinBorder( bool join );
00264 
00265     // Paragraph background
00266     QColor backgroundColor() { return m_layout.backgroundColor; }
00267     void setBackgroundColor( const QColor& color);
00268 
00269     // Counters are used to implement list and heading numbering/bullets.
00270     void setCounter( const KoParagCounter & counter );
00271     void setNoCounter();
00272     void setCounter( const KoParagCounter * pCounter );
00273     KoParagCounter *counter();
00274 
00278     int counterWidth() const;
00279 
00281     KoParagStyle *style() const { return m_layout.style; }
00283     void setStyle( KoParagStyle *style ) { m_layout.style = style; }
00285     void applyStyle( KoParagStyle *style );
00286 
00288     const KoTabulatorList& tabList() const { return m_layout.tabList(); }
00290     void setTabList( const KoTabulatorList &tabList );
00291 
00293     int shadowX( KoTextZoomHandler *zh ) const;
00295     int shadowY( KoTextZoomHandler *zh ) const;
00297     double shadowDistanceY() const;
00298 
00300     void setCustomItem( int index, KoTextCustomItem * custom, KoTextFormat * currentFormat );
00302     void removeCustomItem( int index );
00303 
00306     int findCustomItem( const KoTextCustomItem * custom ) const;
00307 
00309     QMap<int, int>& tabCache() { return m_tabCache; }
00310 
00312     QRect pixelRect( KoTextZoomHandler* zh ) const;
00313 
00317      static void drawFontEffects( QPainter * p, KoTextFormat *format, KoTextZoomHandler *zh, QFont font, const QColor & color, int startX, int baseLine, int bw, int y, int h, QChar firstChar );
00318 
00320     QString toString( int from = 0, int length = 0xffffffff) const;
00321 
00323     void fixParagWidth( bool viewFormattingChars );
00324 
00326     virtual void loadOasis( const QDomElement& e, KoOasisContext& context, KoStyleCollection *styleCollection, uint& pos );
00330     virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context,
00331                             int from, int to, bool saveAnchorsFramesets = false ) const;
00332 
00333     void loadOasisSpan( const QDomElement& parent, KoOasisContext& context, uint& pos );
00334 
00335     void applyListStyle( KoOasisContext& context, int restartNumbering, bool orderedList, bool heading, int level );
00336 
00337 #ifndef NDEBUG
00338     void printRTDebug( int );
00339 #endif
00340 
00341 protected:
00342     void invalidateCounters();
00343     bool lineHyphenated( int l ) const;
00344 
00345     void paintLines( QPainter &painter, const QColorGroup &cg, KoTextCursor *cursor, bool drawSelections,
00346                      int clipx, int clipy, int clipw, int cliph );
00347 
00348     void drawParagString( QPainter &painter, const QString &str, int start, int len, int startX,
00349                           int lastY, int baseLine, int bw, int h, bool drawSelections,
00350                           KoTextFormat *lastFormat, const Q3MemArray<int> &selectionStarts,
00351                           const Q3MemArray<int> &selectionEnds, const QColorGroup &cg, bool rightToLeft, int line );
00352     void drawParagStringInternal( QPainter &painter, const QString &s, int start, int len, int startX,
00353                                   int lastY, int baseLine, int bw, int h, bool drawSelections,
00354                                   KoTextFormat *lastFormat, const Q3MemArray<int> &selectionStarts,
00355                                   const Q3MemArray<int> &selectionEnds, const QColorGroup &cg, bool rightToLeft, int line, KoTextZoomHandler* zh, bool drawingShadow );
00356 
00358     enum { FormattingSpace = 1, FormattingBreak = 2, FormattingEndParag = 4, FormattingTabs = 8,
00359            AllFormattingChars = FormattingSpace | FormattingBreak | FormattingEndParag | FormattingTabs };
00360 
00365     virtual void drawFormattingChars( QPainter &painter, int start, int len,
00366                                       int lastY_pix, int baseLine_pix, int h_pix, // in pixels
00367                                       bool drawSelections,
00368                                       KoTextFormat *format, const Q3MemArray<int> &selectionStarts,
00369                                       const Q3MemArray<int> &selectionEnds, const QColorGroup &cg,
00370                                       bool rightToLeft, int line, KoTextZoomHandler* zh,
00371                                       int whichFormattingChars );
00372 
00373 protected:
00374     KoParagLayout m_layout;
00375     QMap<int, int> m_tabCache;
00376 
00377 private:
00378     KoParagLayout loadParagLayout( KoOasisContext& context, KoStyleCollection *styleCollection, bool findStyle );
00379 
00380 
00381 
00383 private:
00384     QMap<int, KoTextParagSelection> &selections() const;
00385     Q3PtrList<KoTextCustomItem> &floatingItems() const;
00387     int heightForLineSpacing( int startChar, int lastChar ) const;
00388 
00389     QMap<int, KoTextParagLineStart*> lineStarts;
00390     QRect r;
00391     KoTextParag *p, *n;
00392     KoTextDocument *doc;
00393     bool m_invalid : 1;
00394     bool changed : 1;
00395     bool fullWidth : 1;
00396     bool newLinesAllowed : 1;
00397     bool visible : 1;
00398     bool movedDown : 1;
00399     bool m_toc : 1;
00400     uint align : 4;
00401     short int m_lineChanged;
00402     int id;
00403     int m_wused;
00404     KoTextString *str;
00405     QMap<int, KoTextParagSelection> *mSelections;
00406     Q3PtrList<KoTextCustomItem> *mFloatingItems;
00407     KoTextFormat *defFormat; // is this really used?
00408     int *tArray;
00409 
00410     // Those things are used by QRT for the case of a paragraph without document
00411     // We don't use this currently, and it's not worth making EVERY parag bigger
00412     // just for a special case that's rarely used. Better have lightweight KoTextDocument
00413     // replacement (with common base class), if we ever want efficient single-parag docs...
00414     //int tabStopWidth;
00415     //QRect docRect;
00416     //KoTextFormatterBase *pFormatter;
00417     //KoTextDocCommandHistory *commandHistory;
00418 };
00419 
00420 inline int KoTextParag::length() const
00421 {
00422     return str->length();
00423 }
00424 
00425 inline QRect KoTextParag::rect() const
00426 {
00427     return r;
00428 }
00429 
00430 inline KoTextStringChar *KoTextParag::at( int i ) const
00431 {
00432     return &str->at( i );
00433 }
00434 
00435 inline bool KoTextParag::isValid() const
00436 {
00437     return !m_invalid;
00438 }
00439 
00440 inline bool KoTextParag::hasChanged() const
00441 {
00442     return changed;
00443 }
00444 
00445 inline short int KoTextParag::lineChanged()
00446 {
00447     return m_lineChanged;
00448 }
00449 
00450 inline void KoTextParag::append( const QString &s, bool reallyAtEnd )
00451 {
00452     if ( reallyAtEnd )
00453         insert( str->length(), s );
00454     else
00455         insert( qMax( str->length() - 1, 0 ), s );
00456 }
00457 
00458 inline KoTextParag *KoTextParag::prev() const
00459 {
00460     return p;
00461 }
00462 
00463 inline KoTextParag *KoTextParag::next() const
00464 {
00465     return n;
00466 }
00467 
00468 inline bool KoTextParag::hasAnySelection() const
00469 {
00470     return mSelections ? !selections().isEmpty() : false;
00471 }
00472 
00473 /*inline void KoTextParag::setEndState( int s )
00474 {
00475     if ( s == state )
00476         return;
00477     state = s;
00478 }
00479 
00480 inline int KoTextParag::endState() const
00481 {
00482     return state;
00483 }*/
00484 
00485 inline void KoTextParag::setParagId( int i )
00486 {
00487     id = i;
00488 }
00489 
00490 inline int KoTextParag::paragId() const
00491 {
00492     //if ( id == -1 )
00493     //  kWarning() << "invalid parag id!!!!!!!! (" << (void*)this << ")" << endl;
00494     return id;
00495 }
00496 
00497 inline QMap<int, KoTextParagLineStart*> &KoTextParag::lineStartList()
00498 {
00499     return lineStarts;
00500 }
00501 
00502 inline KoTextString *KoTextParag::string() const
00503 {
00504     return str;
00505 }
00506 
00507 inline KoTextDocument *KoTextParag::document() const
00508 {
00509     return doc;
00510 }
00511 
00512 inline void KoTextParag::setAlignment( uint a )
00513 {
00514     if ( a == align )
00515         return;
00516     align = a;
00517     invalidate( 0 );
00518 }
00519 
00520 /*inline void KoTextParag::setListStyle( QStyleSheetItem::ListStyle ls )
00521 {
00522     lstyle = ls;
00523     invalidate( 0 );
00524 }
00525 
00526 inline QStyleSheetItem::ListStyle KoTextParag::listStyle() const
00527 {
00528     return lstyle;
00529 }*/
00530 
00531 inline KoTextFormat *KoTextParag::paragFormat() const
00532 {
00533     return defFormat;
00534 }
00535 
00536 inline void KoTextParag::registerFloatingItem( KoTextCustomItem *i )
00537 {
00538     floatingItems().append( i );
00539 }
00540 
00541 inline void KoTextParag::unregisterFloatingItem( KoTextCustomItem *i )
00542 {
00543     floatingItems().removeRef( i );
00544 }
00545 
00546 /*inline void KoTextParag::addCustomItem()
00547 {
00548     numCustomItems++;
00549 }
00550 
00551 inline void KoTextParag::removeCustomItem()
00552 {
00553     numCustomItems--;
00554 }*/
00555 
00556 inline int KoTextParag::customItems() const
00557 {
00558     return mFloatingItems ? mFloatingItems->count() : 0;
00559     // was numCustomItems, but no need for a separate count
00560 }
00561 
00562 inline void KoTextParag::setNewLinesAllowed( bool b )
00563 {
00564     newLinesAllowed = b;
00565 }
00566 
00567 inline bool KoTextParag::isNewLinesAllowed() const
00568 {
00569     return newLinesAllowed;
00570 }
00571 
00572 #endif

Généré le Wed Nov 22 23:41:10 2006 pour KPlato par  doxygen 1.5.1-p1