lib Library API Documentation

kotextobject.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001-2005 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef kotextobject_h
00021 #define kotextobject_h
00022 
00023 #include <korichtext.h>
00024 #include "koChangeCaseDia.h"
00025 #include "kostyle.h"
00026 #include "kotextdocument.h"
00027 #include <koffice_export.h>
00028 
00029 class KoSavingContext;
00030 class KCommand;
00031 class KoTextFormat;
00032 class QProgressDialog;
00033 class KoLinkVariable;
00034 class KoVariable;
00035 
00036 //#define TIMING_FORMAT
00037 //#include <qdatetime.h>
00038 
00048 class KOTEXT_EXPORT KoTextFormatInterface
00049 {
00050 public:
00051     KoTextFormatInterface() {}
00052     virtual ~KoTextFormatInterface() {}
00053 
00055     virtual KoTextFormat * currentFormat() const = 0;
00056 
00057     virtual bool rtl() const = 0;
00058 
00064     virtual KCommand *setFormatCommand( const KoTextFormat *format, int flags, bool zoomFont = false ) = 0;
00065 
00067     virtual const KoParagLayout * currentParagLayoutFormat() const = 0;
00068 
00073     virtual KCommand *setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex=-1) = 0;
00074 
00075     virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type)=0;
00076 
00077     KoTextDocCommand *deleteTextCommand( KoTextDocument *textdoc, int id, int index, const QMemArray<KoTextStringChar> & str, const CustomItemsMap & customItemsMap, const QValueList<KoParagLayout> & oldParagLayouts );
00078 
00079     void setParagLayoutFormat( KoParagLayout *newLayout,int flags, int marginIndex=-1);
00080     void setFormat( KoTextFormat * newFormat, int flags, bool zoomFont = false );
00081 
00082     // Warning: use the methods that return a command! The others just leak the commands away
00083     //void setBold(bool on);
00084     KCommand *setBoldCommand(bool on);
00085     //void setItalic(bool on);
00086     KCommand *setItalicCommand(bool on);
00087     //void setUnderline(bool on);
00088     KCommand *setUnderlineCommand(bool on);
00089     //void setStrikeOut(bool on);
00090     KCommand *setDoubleUnderlineCommand( bool on );
00091     KCommand *setUnderlineColorCommand( const QColor &color );
00092     KCommand *setStrikeOutCommand(bool on);
00093     //void setTextColor(const QColor &color);
00094     KCommand *setTextColorCommand(const QColor &color);
00095     //void setPointSize( int s );
00096     KCommand *setPointSizeCommand( int s );
00097     //void setFamily(const QString &font);
00098     KCommand *setFamilyCommand(const QString &font);
00099     //void setTextSubScript(bool on);
00100     KCommand *setTextSubScriptCommand(bool on);
00101     //void setTextSuperScript(bool on);
00102     KCommand *setTextSuperScriptCommand(bool on);
00103 
00104     //void setDefaultFormat();
00105     KCommand *setDefaultFormatCommand();
00106 
00107     //void setTextBackgroundColor(const QColor &);
00108     KCommand *setTextBackgroundColorCommand(const QColor &);
00109 
00110     //void setAlign(int align);
00111     KCommand *setAlignCommand(int align);
00112 
00113     //void setMargin(QStyleSheetItem::Margin m, double margin);
00114     KCommand *setMarginCommand(QStyleSheetItem::Margin m, double margin);
00115 
00116     //void setTabList(const KoTabulatorList & tabList );
00117     KCommand *setTabListCommand(const KoTabulatorList & tabList );
00118 
00119     //void setCounter(const KoParagCounter & counter );
00120     KCommand *setCounterCommand(const KoParagCounter & counter );
00121 
00122     KCommand *setLanguageCommand(const QString &);
00123 
00124     KCommand *setShadowTextCommand( double shadowDistanceX, double shadowDistanceY, const QColor& shadowColor );
00125 
00126     KCommand *setHyphenationCommand( bool _b );
00127 
00128 
00129     KCommand *setFontAttributeCommand( KoTextFormat::AttributeStyle _att);
00130 
00131     KCommand *setRelativeTextSizeCommand( double _size );
00132 
00133     KCommand *setOffsetFromBaseLineCommand( int _offset );
00134 
00135     KCommand *setWordByWordCommand( bool _b );
00136 
00137 
00138     QColor textColor() const;
00139     QFont textFont() const;
00140     QString textFontFamily()const;
00141     QString language() const;
00142     QColor textBackgroundColor()const;
00143     QColor textUnderlineColor()const;
00144 
00145     KoTextFormat::UnderlineType underlineType()const;
00146     KoTextFormat::StrikeOutType strikeOutType()const;
00147     KoTextFormat::UnderlineStyle underlineStyle()const;
00148     KoTextFormat::StrikeOutStyle strikeOutStyle()const;
00149 
00150 
00151 
00152     bool textUnderline()const;
00153     bool textDoubleUnderline()const;
00154 
00155     bool textBold()const;
00156     bool textStrikeOut()const;
00157     bool textItalic() const;
00158     bool textSubScript() const;
00159     bool textSuperScript() const;
00160     double shadowDistanceX() const;
00161     double shadowDistanceY() const;
00162     QColor shadowColor() const;
00163     KoTextFormat::AttributeStyle fontAttribute() const;
00164     double relativeTextSize() const;
00165     int offsetFromBaseLine()const;
00166     bool wordByWord()const;
00167     bool hyphenation()const;
00168 };
00169 
00176 class KOTEXT_EXPORT KoTextObject : public QObject, public KoTextFormatInterface
00177 {
00178     Q_OBJECT
00179 public:
00190     KoTextObject( KoZoomHandler *zh, const QFont& defaultFont, const QString &defaultLanguage,
00191                   bool defaultHyphenation, KoParagStyle* defaultStyle, int tabStopWidth = -1,
00192                   QObject* parent = 0, const char *name = 0 );
00193 
00200     KoTextObject( KoTextDocument *textdoc, KoParagStyle* defaultStyle,
00201                   QObject* parent = 0, const char *name = 0 );
00202 
00203     virtual ~KoTextObject();
00204 
00205 
00206     static const char * acceptSelectionMimeType();
00209     static QCString providesOasis( QMimeSource* mime );
00210 
00211     void setNeedSpellCheck(bool b);
00212     bool needSpellCheck() const { return m_needsSpellCheck;}
00213     void setProtectContent(bool b) { m_protectContent = b; }
00214     bool protectContent() const{ return m_protectContent;}
00218     KoTextDocument *textDocument() const { return textdoc; }
00219 
00220     void setAvailableHeight( int avail ) { m_availableHeight = avail; }
00221     int availableHeight() const;
00222 
00223     void undo();
00224     void redo();
00226     void clearUndoRedoInfo();
00227 
00229     bool hasSelection() const { return textdoc->hasSelection( KoTextDocument::Standard, true ); }
00231     QString selectedText( int selectionId = KoTextDocument::Standard ) const {
00232         return textdoc->selectedText( selectionId );
00233     }
00235     bool selectionHasCustomItems( int selectionId = KoTextDocument::Standard ) const;
00236 
00248     void insert( KoTextCursor * cursor, KoTextFormat * currentFormat, const QString &text,
00249                  bool checkNewLine, bool removeSelected, const QString & commandName,
00250                  CustomItemsMap customItemsMap = CustomItemsMap(),
00251                  int selectionId = KoTextDocument::Standard,
00252                  bool repaint = true );
00259     void removeSelectedText( KoTextCursor * cursor, int selectionId = KoTextDocument::Standard,
00260                              const QString & cmdName = QString::null, bool createUndoRedo=true  );
00261 
00262     KCommand * replaceSelectionCommand( KoTextCursor * cursor, const QString & replacement,
00263                                         int selectionId, const QString & cmdName, bool repaint = true,
00264                                         bool checkNewLine = true );
00265     KCommand * removeSelectedTextCommand( KoTextCursor * cursor, int selectionId, bool repaint = true );
00266     KCommand* insertParagraphCommand( KoTextCursor * cursor );
00267 
00268     void pasteText( KoTextCursor * cursor, const QString & text, KoTextFormat * currentFormat, bool removeSelected );
00269     void selectAll( bool select );
00270 
00274     void highlightPortion( KoTextParag * parag, int index, int length, bool repaint );
00275     void removeHighlight( bool repaint );
00276 
00278     KCommand *setFormatCommand( const KoTextFormat *format, int flags, bool zoomFont = false );
00279 
00282     KCommand *setFormatCommand( KoTextCursor * cursor, KoTextFormat ** currentFormat, const KoTextFormat *format, int flags, bool zoomFont = false, int selectionId = KoTextDocument::Standard );
00283 
00285     enum SelectionIds {
00286         HighlightSelection = 2 // used to highlight during search/replace
00287     };
00288 
00289     enum KeyboardAction { // keep in sync with QTextEdit
00290     ActionBackspace,
00291     ActionDelete,
00292     ActionReturn,
00293     ActionKill
00294     };
00297     void doKeyboardAction( KoTextCursor * cursor, KoTextFormat * & currentFormat, KeyboardAction action );
00298 
00299     // -- Paragraph settings --
00300     KCommand * setCounterCommand( KoTextCursor * cursor, const KoParagCounter & counter, int selectionId = KoTextDocument::Standard );
00301     KCommand * setAlignCommand( KoTextCursor * cursor, int align , int selectionId = KoTextDocument::Standard);
00302     KCommand * setLineSpacingCommand( KoTextCursor * cursor, double spacing, KoParagLayout::SpacingType _type,int selectionId = KoTextDocument::Standard );
00303     KCommand * setBordersCommand( KoTextCursor * cursor, const KoBorder& leftBorder, const KoBorder& rightBorder, const KoBorder& topBorder, const KoBorder& bottomBorder, int selectionId = KoTextDocument::Standard );
00304     KCommand * setMarginCommand( KoTextCursor * cursor, QStyleSheetItem::Margin m, double margin, int selectionId = KoTextDocument::Standard);
00305     KCommand* setTabListCommand( KoTextCursor * cursor,const KoTabulatorList & tabList , int selectionId = KoTextDocument::Standard );
00306 
00307     KCommand * setParagDirectionCommand( KoTextCursor * cursor, QChar::Direction d, int selectionId = KoTextDocument::Standard );
00308 
00319     void applyStyle( KoTextCursor * cursor, const KoParagStyle * style,
00320                      int selectionId = KoTextDocument::Standard,
00321                      int paragLayoutFlags = KoParagLayout::All, int formatFlags = KoTextFormat::Format,
00322                      bool createUndoRedo = true, bool interactive = true );
00323 
00329     KCommand* applyStyleCommand( KoTextCursor * cursor, const KoParagStyle * style,
00330                      int selectionId = KoTextDocument::Standard,
00331                      int paragLayoutFlags = KoParagLayout::All, int formatFlags = KoTextFormat::Format,
00332                      bool createUndoRedo = true, bool interactive = true );
00333 
00334 
00340     void applyStyleChange( KoStyleChangeDefMap changed );
00343     void setFormat( KoTextCursor * cursor, KoTextFormat ** currentFormat, KoTextFormat *format, int flags, bool zoomFont = false );
00344 
00345 
00351     virtual KoTextFormat * currentFormat() const;
00352 
00356     virtual const KoParagLayout * currentParagLayoutFormat() const;
00357 
00358     virtual bool rtl() const;
00359 
00363     virtual KCommand *setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex=-1);
00364 
00365     // common for setParagLayoutFormatCommand above and KoTextView::setParagLayoutFormatCommand
00366     KCommand *setParagLayoutCommand( KoTextCursor * cursor, const KoParagLayout& paragLayout,
00367                                      int selectionId, int paragLayoutFlags,
00368                                      int marginIndex, bool createUndoRedo );
00372     virtual void setFormat( KoTextFormat * newFormat, int flags, bool zoomFont = false );
00373 
00375     int docFontSize( KoTextFormat * format ) const;
00377     int zoomedFontSize( int docFontSize ) const;
00378 
00380     void setViewArea( QWidget* w, int maxY );
00382     void ensureFormatted( KoTextParag * parag, bool emitAfterFormatting = true );
00383     void setLastFormattedParag( KoTextParag *parag );
00384 
00385     static QChar customItemChar() { return QChar( s_customItemChar ); }
00386 
00387     // Qt should really have support for public signals
00388     void emitHideCursor() { emit hideCursor(); }
00389     void emitShowCursor() { emit showCursor(); }
00390     void emitEnsureCursorVisible() { emit ensureCursorVisible(); }
00391     void emitUpdateUI( bool updateFormat, bool force = false ) { emit updateUI( updateFormat, force ); }
00392 
00393     void typingStarted();
00394     void typingDone();
00395 
00402     void abortFormatting();
00403 
00404     void selectionChangedNotify( bool enableActions = true );
00405 
00406     void emitNewCommand(KCommand *cmd);
00407 
00408     virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type);
00409 
00410     KCommand *changeCaseOfText(KoTextCursor *cursor, KoChangeCaseDia::TypeOfCase _type);
00411     QString textChangedCase(const QString& _text, KoChangeCaseDia::TypeOfCase _type);
00412     KCommand *changeCaseOfTextParag(int cursorPosStart, int cursorPosEnd,KoChangeCaseDia::TypeOfCase _type,KoTextCursor *cursor, KoTextParag *parag);
00413 
00414     void loadOasisContent( const QDomElement &bodyElem, KoOasisContext& context, KoStyleCollection * styleColl );
00415     void saveOasisContent( KoXmlWriter& writer, KoSavingContext& context ) const;
00416 
00417     // Similar to KoTextDocument::loadOasisText but there's no newline inserted before the first paragraph
00418     // or after the last one - so it's possible to paste just a few chars.
00419     // It also handles m_lastFormatted
00420     KoTextCursor pasteOasisText( const QDomElement &bodyElem, KoOasisContext& context,
00421                                  KoTextCursor& cursor, KoStyleCollection * styleColl );
00422 
00423 #ifndef NDEBUG
00424     void printRTDebug(int);
00425 #endif
00426 
00427     bool statistics( QProgressDialog *progress, ulong & charsWithSpace, ulong & charsWithoutSpace, ulong & words, ulong & sentences, ulong & syllables, ulong & lines, bool selected );
00428     int numberOfparagraphLineSelected( KoTextParag *parag);
00429 
00433     KoVariable* variableAtPoint( const QPoint& iPoint ) const;
00434 
00440     KoVariable* variableAtPosition( KoTextParag* parag, int index ) const;
00441 
00442     enum ParagModifyType { AddChar = 0, RemoveChar = 1, ChangeFormat = 2 };
00443 
00444 signals:
00447     void availableHeightNeeded();
00448 
00452     void afterFormatting( int bottom, KoTextParag* m_lastFormatted, bool* abort );
00453 
00458     void chapterParagraphFormatted( KoTextParag* parag );
00459 
00462     void formattingFirstParag();
00463 
00468     void newCommand( KCommand *cmd );
00469 
00471     void repaintChanged( KoTextObject * );
00472 
00473     void hideCursor();
00474     void showCursor();
00476     void setCursor( KoTextCursor * cursor );
00479     void updateUI( bool updateFormat, bool force = false );
00481     void showCurrentFormat();
00483     void ensureCursorVisible();
00485     void selectionChanged( bool hasSelection );
00486 
00487     void showFormatObject(const KoTextFormat &);
00488 
00489     // Keeping track of text modifications - not emitted during loading/closing.
00490     void paragraphCreated( KoTextParag* parag );
00491     void paragraphModified( KoTextParag* parag, int /*ParagModifyType*/, int pos, int length );
00492     void paragraphDeleted( KoTextParag* parag );
00493 
00494 public slots:
00495     // The default arguments are those used by the formatTimer.
00496     // The return value is used by ensureFormatted
00497     bool formatMore( int count = 10, bool emitAfterFormatting = true );
00498 
00499     void emitRepaintChanged() { emit repaintChanged( this ); }
00500 
00501 public: // made public for KWTextFrameSet...
00502 
00506     void storeParagUndoRedoInfo( KoTextCursor * cursor, int selectionId = KoTextDocument::Standard );
00508     void copyCharFormatting( KoTextParag *parag, int position, int index /*in text*/, bool moveCustomItems );
00509     void readFormats( KoTextCursor &c1, KoTextCursor &c2, bool copyParagLayouts = false, bool moveCustomItems = false );
00510 
00520     struct KOTEXT_EXPORT UndoRedoInfo { // borrowed from QTextEdit
00521         enum Type { Invalid, Insert, Delete, Return, RemoveSelected };
00522         UndoRedoInfo( KoTextObject* textobj );
00523         ~UndoRedoInfo() {}
00524         void clear();
00525         bool valid() const;
00526 
00527         KoTextString text; // storage for formatted text
00528         int id; // id of first parag
00529         int eid; // id of last parag
00530         int index; // index (for insertion/deletion)
00531         Type type; // type of command
00532         KoTextObject* textobj; // parent
00533         CustomItemsMap customItemsMap; // character position -> qtextcustomitem
00534         QValueList<KoParagLayout> oldParagLayouts;
00535         KoParagLayout newParagLayout;
00536         KoTextCursor *cursor; // basically a "mark" of the view that started this undo/redo info
00537         // If the view changes, the next call to checkUndoRedoInfo will terminate the previous view's edition
00538         KMacroCommand *placeHolderCmd;
00539     };
00546     void newPlaceHolderCommand( const QString & name );
00547     void checkUndoRedoInfo( KoTextCursor * cursor, UndoRedoInfo::Type t );
00548 
00550     UndoRedoInfo & undoRedoInfoStruct() { return undoRedoInfo; }
00551 
00552     void setVisible(bool vis) { m_visible=vis; }
00553     bool isVisible() const { return m_visible; }
00554 
00555 private slots:
00556     void doChangeInterval();
00561     void slotAfterUndoRedo();
00562     void slotParagraphModified(KoTextParag *, int, int , int);
00563     void slotParagraphCreated(KoTextParag *);
00564     void slotParagraphDeleted(KoTextParag *);
00565 private:
00566     void init();
00567 
00568 private:
00569     class KoTextObjectPrivate;
00570     KoTextObjectPrivate* d;
00572     KoTextDocument *textdoc;
00573 
00576     KoParagStyle* m_defaultStyle;
00577 
00578     bool m_visible;
00579 
00581     UndoRedoInfo undoRedoInfo;
00582 
00586     KoTextParag *m_lastFormatted;
00588     QTimer *formatTimer, *changeIntervalTimer;
00589     int interval;
00590 
00592     int m_availableHeight;
00594     QMap<QWidget *, int> m_mapViewAreas;
00595 
00596     //QPtrDict<int> m_origFontSizes; // Format -> doc font size.
00597 
00598     bool m_highlightSelectionAdded;
00599 
00600 #ifdef TIMING_FORMAT
00601     QTime m_time;
00602 #endif
00603 
00604     static const char s_customItemChar;
00605     bool m_needsSpellCheck;
00606     bool m_protectContent;
00607 };
00608 
00609 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:10 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003