lib Library API Documentation

kotextdocument.h

00001 // -*- c++ -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2001 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef KOTEXTDOCUMENT_H
00022 #define KOTEXTDOCUMENT_H
00023 
00024 #include "korichtext.h"
00025 
00026 #if defined(Q_TEMPLATEDLL)
00027 // MOC_SKIP_BEGIN
00028 template class Q_EXPORT QMap<int, QColor>;
00029 template class Q_EXPORT QMap<int, bool>;
00030 template class Q_EXPORT QMap<int, KoTextDocumentSelection>;
00031 template class Q_EXPORT QPtrList<KoTextDocument>;
00032 // MOC_SKIP_END
00033 #endif
00034 
00035 class KoZoomHandler;
00036 class KoTextFormatCollection;
00037 class KoParagVisitor;
00038 class KoTextFormatter;
00039 class KoTextParag;
00040 class CustomItemsMap;
00041 
00042 class Q_EXPORT KoTextDocument : public QObject
00043 {
00044     Q_OBJECT
00045 
00046     friend class KoTextCursor;
00047     friend class KoTextParag;
00048 
00049 public:
00050     enum SelectionIds {
00051     Standard = 0,
00052     Temp = 32000 // This selection must not be drawn, it's used e.g. by undo/redo to
00053     // remove multiple lines with removeSelectedText()
00054     };
00055 
00056     //KoTextDocument( KoTextDocument *p );
00057     //KoTextDocument( KoTextDocument *d, KoTextFormatCollection *f );
00058     // see below for constructor
00059     virtual ~KoTextDocument();
00060 
00061     //KoTextDocument *parent() const { return par; }
00062 
00063     void setText( const QString &text, const QString &context );
00064 
00065     QString text() const;
00066     QString text( int parag ) const;
00067     //QString originalText() const;
00068 
00069     int x() const;
00070     int y() const;
00071     int width() const;
00072     //int widthUsed() const;
00073     //int visibleWidth() const;
00074     int height() const;
00075     void setWidth( int w );
00076     //int minimumWidth() const;
00077     //virtual bool setMinimumWidth( int w, KoTextParag *parag );
00078 
00079     void setY( int y );
00080     int leftMargin() const;
00081     void setLeftMargin( int lm );
00082     int rightMargin() const;
00083     void setRightMargin( int rm );
00084 
00085     KoTextParag *firstParag() const;
00086     KoTextParag *lastParag() const;
00087     void setFirstParag( KoTextParag *p );
00088     void setLastParag( KoTextParag *p );
00089 
00090     void invalidate();
00091 
00092     //void setPreProcessor( KoTextPreProcessor *sh );
00093     //KoTextPreProcessor *preProcessor() const;
00094 
00095     void setFormatter( KoTextFormatterBase *f );
00096     KoTextFormatterBase *formatter() const;
00097 
00098     void setIndent( KoTextIndent *i );
00099     KoTextIndent *indent() const;
00100 
00101     QColor selectionColor( int id ) const;
00102     bool invertSelectionText( int id ) const;
00103     void setSelectionColor( int id, const QColor &c );
00104     void setInvertSelectionText( int id, bool b );
00105     bool hasSelection( int id, bool visible = false ) const;
00106     bool isSelectionSwapped( int id ); 
00107     void setSelectionStart( int id, KoTextCursor *cursor );
00108     bool setSelectionEnd( int id, KoTextCursor *cursor );
00109     void selectAll( int id );
00110     bool removeSelection( int id );
00111     void selectionStart( int id, int &paragId, int &index );
00112     KoTextCursor selectionStartCursor( int id );
00113     KoTextCursor selectionEndCursor( int id );
00114     void selectionEnd( int id, int &paragId, int &index );
00115     void setFormat( int id, const KoTextFormat *f, int flags );
00116     KoTextParag *selectionStart( int id );
00117     KoTextParag *selectionEnd( int id );
00118     int numSelections() const { return nSelections; }
00119     void addSelection( int id );
00120 
00121     QString selectedText( int id, bool withCustom = TRUE ) const;
00122     //void copySelectedText( int id );
00123     void removeSelectedText( int id, KoTextCursor *cursor );
00124     void indentSelection( int id );
00125 
00126     KoTextParag *paragAt( int i ) const;
00127 
00128     void addCommand( KoTextDocCommand *cmd );
00129     KoTextCursor *undo( KoTextCursor *c = 0 );
00130     KoTextCursor *redo( KoTextCursor *c  = 0 );
00131     KoTextDocCommandHistory *commands() const { return commandHistory; }
00132 
00133     KoTextFormatCollection *formatCollection() const;
00134 
00135     bool find( const QString &expr, bool cs, bool wo, bool forward, int *parag, int *index, KoTextCursor *cursor );
00136 
00137     //void setTextFormat( Qt::TextFormat f );
00138     //Qt::TextFormat textFormat() const;
00139 
00140     bool inSelection( int selId, const QPoint &pos ) const;
00141 
00142     void setUnderlineLinks( bool b ) { underlLinks = b; }
00143     bool underlineLinks() const { return underlLinks; }
00144 
00145     void setPaper( QBrush *brush ) { if ( backBrush ) delete backBrush; backBrush = brush; }
00146     QBrush *paper() const { return backBrush; }
00147 
00148     //void doLayout( QPainter *p, int w );
00149 #if 0 // see KoTextDocument
00150     void draw( QPainter *p, const QRect& rect, const QColorGroup &cg, const QBrush *paper = 0 );
00151     void drawParag( QPainter *p, KoTextParag *parag, int cx, int cy, int cw, int ch,
00152             QPixmap *&doubleBuffer, const QColorGroup &cg,
00153             bool drawCursor, KoTextCursor *cursor, bool resetChanged = TRUE );
00154     KoTextParag *draw( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg,
00155               bool onlyChanged = FALSE, bool drawCursor = FALSE, KoTextCursor *cursor = 0,
00156               bool resetChanged = TRUE );
00157 #endif
00158 
00159     //void setDefaultFont( const QFont &f );
00160 
00161     void registerCustomItem( KoTextCustomItem *i, KoTextParag *p );
00162     void unregisterCustomItem( KoTextCustomItem *i, KoTextParag *p );
00163     const QPtrList<KoTextCustomItem> & allCustomItems() const { return customItems; }
00164 
00165     void setFlow( KoTextFlow *f );
00166     void takeFlow();
00167     KoTextFlow *flow() const { return flow_; }
00168     bool isPageBreakEnabled() const { return m_pageBreakEnabled; }
00169     void setPageBreakEnabled( bool b ) { m_pageBreakEnabled = b; }
00170 
00171     void setWithoutDoubleBuffer( bool b ) { withoutDoubleBuffer = b; }
00172     bool isWithoutDoubleBuffer() const { return withoutDoubleBuffer; } // added for KWTextDocument
00173 
00174     void setUseFormatCollection( bool b ) { useFC = b; }
00175     bool useFormatCollection() const { return useFC; }
00176 
00177 #ifdef QTEXTTABLE_AVAILABLE
00178     KoTextTableCell *tableCell() const { return tc; }
00179     void setTableCell( KoTextTableCell *c ) { tc = c; }
00180 #endif
00181 
00182     void setPlainText( const QString &text );
00183     //void setRichText( const QString &text, const QString &context );
00184     QString richText( KoTextParag *p = 0 ) const;
00185     QString plainText( KoTextParag *p = 0 ) const;
00186 
00187     //bool focusNextPrevChild( bool next );
00188 
00189     int alignment() const;
00190     void setAlignment( int a );
00191 
00192     int *tabArray() const;
00193     int tabStopWidth() const;
00194     void setTabArray( int *a );
00195     void setTabStops( int tw );
00196 
00197     void setUndoDepth( int d ) { commandHistory->setUndoDepth( d ); }
00198     int undoDepth() const { return commandHistory->undoDepth(); }
00199 
00200     int length() const;
00201     void clear( bool createEmptyParag = FALSE );
00202 
00203     virtual KoTextParag *createParag( KoTextDocument *d, KoTextParag *pr = 0, KoTextParag *nx = 0, bool updateIds = TRUE );
00204     void insertChild( QObject *o ) { QObject::insertChild( o ); }
00205     void removeChild( QObject *o ) { QObject::removeChild( o ); }
00206     //void insertChild( KoTextDocument *d ) { childList.append( d ); }
00207     //void removeChild( KoTextDocument *d ) { childList.removeRef( d ); }
00208     //QPtrList<KoTextDocument> children() const { return childList; }
00209 
00210     void setAddMargins( bool b ) { addMargs = b; }
00211     int addMargins() const { return addMargs; }
00212 
00213     //bool hasFocusParagraph() const;
00214     //QString focusHref() const;
00215 
00216     //void invalidateOriginalText() { oTextValid = FALSE; }
00217     void informParagraphDeleted( KoTextParag* parag );
00218 
00219 signals:
00220     //void minimumWidthChanged( int );
00221 
00223     void paragraphDeleted( KoTextParag* parag );
00224 
00225 private:
00226     void init();
00227     QPixmap *bufferPixmap( const QSize &s );
00228 
00230 
00231 public:
00245     KoTextDocument( KoZoomHandler *zoomHandler,
00246                     KoTextFormatCollection *fc, KoTextFormatter *formatter = 0L,
00247                     bool createInitialParag = true );
00248 
00251     KoZoomHandler * formattingZoomHandler() const { return m_zoomHandler; }
00252 
00260     KoZoomHandler * paintingZoomHandler() const { return m_zoomHandler; }
00261 
00262 
00265     bool visitSelection( int selectionId, KoParagVisitor *visitor, bool forward = true );
00266 
00269     bool visitDocument( KoParagVisitor *visitor, bool forward = true );
00270 
00273     bool visitFromTo( KoTextParag *firstParag, int firstIndex, KoTextParag* lastParag, int lastIndex, KoParagVisitor* visitor, bool forw = true );
00274 
00278     bool isDestroying() const { return m_bDestroying; }
00279 
00283     enum DrawingFlags {
00284         DrawMisspelledLine = 1,
00285         DrawFormattingChars = 2,
00286         DrawSelections = 4,
00287         DontDrawNoteVariable = 8
00288     };
00291     KoTextParag *drawWYSIWYG( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg,
00292                               KoZoomHandler* zoomHandler, bool onlyChanged = FALSE,
00293                               bool drawCursor = FALSE, KoTextCursor *cursor = 0,
00294                               bool resetChanged = TRUE, uint drawingFlags = KoTextDocument::DrawSelections );
00295 
00298     void drawParagWYSIWYG( QPainter *p, KoTextParag *parag, int cx, int cy, int cw, int ch,
00299                            QPixmap *&doubleBuffer, const QColorGroup &cg,
00300                            KoZoomHandler* zoomHandler,
00301                            bool drawCursor, KoTextCursor *cursor,
00302                            bool resetChanged = TRUE,
00303                            uint drawingFlags = KoTextDocument::DrawSelections );
00304 
00306     bool drawFormattingChars() const { return (m_drawingFlags & DrawFormattingChars); }
00308     bool drawingMissingSpellLine() const { return (m_drawingFlags & DrawMisspelledLine); }
00309 
00311     bool dontDrawingNoteVariable() const { return (m_drawingFlags & DontDrawNoteVariable); }
00312 
00313     virtual KoTextDocCommand *deleteTextCommand( KoTextDocument *textdoc, int id, int index, const QMemArray<KoTextStringChar> & str, const CustomItemsMap & customItemsMap, const QValueList<KoParagLayout> & oldParagLayouts );
00314 
00315     void emitNewCommand(KCommand *cmd) {
00316         emit newCommand( cmd );
00317     }
00318     void emitRepaintChanged() {
00319         emit repaintChanged();
00320     }
00321 signals:
00327     void newCommand( KCommand *cmd );
00332     void repaintChanged();
00333 
00334 protected:
00335     void drawWithoutDoubleBuffer( QPainter *p, const QRect &rect, const QColorGroup &cg,
00336                                   KoZoomHandler* zoomHandler, const QBrush *paper = 0 );
00337 
00338 private:
00339     // The zoom handler used when formatting
00340     // (due to the pixelx/pixelww stuff in KoTextFormatter)
00341     KoZoomHandler * m_zoomHandler;
00342     bool m_bDestroying;
00343     uint m_drawingFlags;
00344 
00346 
00347 private:
00348     /*struct Q_EXPORT Focus {
00349     KoTextParag *parag;
00350     int start, len;
00351     QString href;
00352     };*/
00353 
00354     int cx, cy; //, cw, vw;
00355     KoTextParag *fParag, *lParag;
00356     //KoTextPreProcessor *pProcessor;
00357     QMap<int, QColor> selectionColors;
00358     QMap<int, KoTextDocumentSelection> selections;
00359     QMap<int, bool> selectionText;
00360     KoTextDocCommandHistory *commandHistory;
00361     KoTextFormatterBase *pFormatter;
00362     KoTextIndent *indenter;
00363     KoTextFormatCollection *fCollection;
00364     //Qt::TextFormat txtFormat;
00365     //bool preferRichText : 1;
00366     bool m_pageBreakEnabled : 1;
00367     bool useFC : 1;
00368     bool withoutDoubleBuffer : 1;
00369     bool underlLinks : 1;
00370     //bool nextDoubleBuffered : 1;
00371     bool addMargs : 1;
00372     //bool oTextValid : 1;
00373     int nSelections;
00374     KoTextFlow *flow_;
00375     QPtrList<KoTextCustomItem> customItems;
00376     //KoTextDocument *par;
00377 #ifdef QTEXTTABLE_AVAILABLE
00378     KoTextTableCell *tc;
00379 #endif
00380     KoTextCursor *tmpCursor;
00381     QBrush *backBrush;
00382     QPixmap *buf_pixmap;
00383     //Focus focusIndicator;
00384     //int minw;
00385     int leftmargin;
00386     int rightmargin;
00387     //KoTextParag *minwParag;
00388     int align;
00389     int *tArray;
00390     int tStopWidth;
00391     int uDepth; // ?
00392     //QString oText;
00393     //QColor linkColor;
00394 };
00395 
00396 inline int KoTextDocument::x() const
00397 {
00398     return cx;
00399 }
00400 
00401 inline int KoTextDocument::y() const
00402 {
00403     return cy;
00404 }
00405 
00406 inline int KoTextDocument::width() const
00407 {
00408     return flow_->width();
00409     //return QMAX( cw, flow_->width() );
00410 }
00411 
00412 //inline int KoTextDocument::visibleWidth() const
00413 //{
00414 //    return vw;
00415 //}
00416 
00417 inline KoTextParag *KoTextDocument::firstParag() const
00418 {
00419     return fParag;
00420 }
00421 
00422 inline KoTextParag *KoTextDocument::lastParag() const
00423 {
00424     return lParag;
00425 }
00426 
00427 inline void KoTextDocument::setFirstParag( KoTextParag *p )
00428 {
00429     fParag = p;
00430 }
00431 
00432 inline void KoTextDocument::setLastParag( KoTextParag *p )
00433 {
00434     lParag = p;
00435 }
00436 
00437 inline void KoTextDocument::setWidth( int w )
00438 {
00439     //cw = QMAX( w, minw );
00440     flow_->setWidth( w );
00441     //vw = w;
00442 }
00443 
00444 //inline int KoTextDocument::minimumWidth() const
00445 //{
00446 //    return minw;
00447 //}
00448 
00449 inline void KoTextDocument::setY( int y )
00450 {
00451     cy = y;
00452 }
00453 
00454 inline int KoTextDocument::leftMargin() const
00455 {
00456     return leftmargin;
00457 }
00458 
00459 inline void KoTextDocument::setLeftMargin( int lm )
00460 {
00461     leftmargin = lm;
00462 }
00463 
00464 inline int KoTextDocument::rightMargin() const
00465 {
00466     return rightmargin;
00467 }
00468 
00469 inline void KoTextDocument::setRightMargin( int rm )
00470 {
00471     rightmargin = rm;
00472 }
00473 
00474 /*inline KoTextPreProcessor *KoTextDocument::preProcessor() const
00475 {
00476     return pProcessor;
00477 }
00478 
00479 inline void KoTextDocument::setPreProcessor( KoTextPreProcessor * sh )
00480 {
00481     pProcessor = sh;
00482 }*/
00483 
00484 inline void KoTextDocument::setFormatter( KoTextFormatterBase *f )
00485 {
00486     delete pFormatter;
00487     pFormatter = f;
00488 }
00489 
00490 inline KoTextFormatterBase *KoTextDocument::formatter() const
00491 {
00492     return pFormatter;
00493 }
00494 
00495 inline void KoTextDocument::setIndent( KoTextIndent *i )
00496 {
00497     indenter = i;
00498 }
00499 
00500 inline KoTextIndent *KoTextDocument::indent() const
00501 {
00502     return indenter;
00503 }
00504 
00505 inline QColor KoTextDocument::selectionColor( int id ) const
00506 {
00507     return selectionColors[ id ];
00508 }
00509 
00510 inline bool KoTextDocument::invertSelectionText( int id ) const
00511 {
00512     return selectionText[ id ];
00513 }
00514 
00515 inline void KoTextDocument::setSelectionColor( int id, const QColor &c )
00516 {
00517     selectionColors[ id ] = c;
00518 }
00519 
00520 inline void KoTextDocument::setInvertSelectionText( int id, bool b )
00521 {
00522     selectionText[ id ] = b;
00523 }
00524 
00525 inline KoTextFormatCollection *KoTextDocument::formatCollection() const
00526 {
00527     return fCollection;
00528 }
00529 
00530 inline int KoTextDocument::alignment() const
00531 {
00532     return align;
00533 }
00534 
00535 inline void KoTextDocument::setAlignment( int a )
00536 {
00537     align = a;
00538 }
00539 
00540 inline int *KoTextDocument::tabArray() const
00541 {
00542     return tArray;
00543 }
00544 
00545 inline int KoTextDocument::tabStopWidth() const
00546 {
00547     return tStopWidth;
00548 }
00549 
00550 inline void KoTextDocument::setTabArray( int *a )
00551 {
00552     tArray = a;
00553 }
00554 
00555 inline void KoTextDocument::setTabStops( int tw )
00556 {
00557     tStopWidth = tw;
00558 }
00559 
00560 /*inline QString KoTextDocument::originalText() const
00561 {
00562     if ( oTextValid )
00563     return oText;
00564     return text();
00565 }*/
00566 
00567 inline void KoTextDocument::setFlow( KoTextFlow *f )
00568 {
00569     if ( flow_ )
00570     delete flow_;
00571     flow_ = f;
00572 }
00573 
00574 inline void KoTextDocument::takeFlow()
00575 {
00576     flow_ = 0L;
00577 }
00578 
00584 class KoParagVisitor
00585 {
00586 protected:
00588     KoParagVisitor() {}
00589     virtual ~KoParagVisitor() {}
00590 public:
00592     virtual bool visit( KoTextParag *parag, int start, int end ) = 0;
00593 };
00594 
00595 class KCommand;
00596 class QDomElement;
00597 class KMacroCommand;
00598 
00601 class CustomItemsMap : public QMap<int, KoTextCustomItem *>
00602 {
00603 public:
00604 
00606     void insertItems( const KoTextCursor & startCursor, int size );
00607 
00609     void deleteAll( KMacroCommand *macroCmd );
00610 };
00611 
00612 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:27 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003