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

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001-2006 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., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef kotextobject_h
00021 #define kotextobject_h
00022 
00023 #include <KoRichText.h>
00024 #include "KoChangeCaseDia.h"
00025 #include "KoStyleCollection.h"
00026 #include "KoTextDocument.h"
00027 #include <koffice_export.h>
00028 //Added by qt3to4:
00029 #include <QByteArray>
00030 #include <Q3MemArray>
00031 #include <Q3ValueList>
00032 
00033 class KoSavingContext;
00034 class KCommand;
00035 class KoTextFormat;
00036 class QProgressDialog;
00037 class KoLinkVariable;
00038 class KoVariable;
00039 class QMimeData;
00040 
00041 //#define TIMING_FORMAT
00042 //#include <QDateTime>
00043 
00053 class KOTEXT_EXPORT KoTextFormatInterface
00054 {
00055 public:
00056     KoTextFormatInterface() {}
00057     virtual ~KoTextFormatInterface() {}
00058 
00060     virtual KoTextFormat * currentFormat() const = 0;
00061 
00062     virtual bool rtl() const = 0;
00063 
00070     virtual KCommand *setFormatCommand( const KoTextFormat *format, int flags, bool zoomFont = false ) = 0;
00071 
00073     virtual const KoParagLayout * currentParagLayoutFormat() const = 0;
00074 
00080     virtual KCommand *setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex=-1) = 0;
00081 
00082     virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type)=0;
00083 
00084     KoTextDocCommand *deleteTextCommand( KoTextDocument *textdoc, int id, int index, const Q3MemArray<KoTextStringChar> & str, const CustomItemsMap & customItemsMap, const Q3ValueList<KoParagLayout> & oldParagLayouts );
00085 
00086     void setParagLayoutFormat( KoParagLayout *newLayout,int flags, int marginIndex=-1);
00087     void setFormat( KoTextFormat * newFormat, int flags, bool zoomFont = false );
00088 
00089     // Warning: use the methods that return a command! The others just leak the commands away
00090     //void setBold(bool on);
00091     KCommand *setBoldCommand(bool on);
00092     //void setItalic(bool on);
00093     KCommand *setItalicCommand(bool on);
00094     //void setUnderline(bool on);
00095     KCommand *setUnderlineCommand(bool on);
00096     //void setStrikeOut(bool on);
00097     KCommand *setDoubleUnderlineCommand( bool on );
00098     KCommand *setUnderlineColorCommand( const QColor &color );
00099     KCommand *setStrikeOutCommand(bool on);
00100     //void setTextColor(const QColor &color);
00101     KCommand *setTextColorCommand(const QColor &color);
00102     //void setPointSize( int s );
00103     KCommand *setPointSizeCommand( int s );
00104     //void setFamily(const QString &font);
00105     KCommand *setFamilyCommand(const QString &font);
00106     //void setTextSubScript(bool on);
00107     KCommand *setTextSubScriptCommand(bool on);
00108     //void setTextSuperScript(bool on);
00109     KCommand *setTextSuperScriptCommand(bool on);
00110 
00111     //void setDefaultFormat();
00112     KCommand *setDefaultFormatCommand();
00113 
00114     //void setTextBackgroundColor(const QColor &);
00115     KCommand *setTextBackgroundColorCommand(const QColor &);
00116 
00117     //void setAlign(int align);
00118     KCommand *setAlignCommand(int align);
00119 
00120     //void setMargin(QStyleSheetItem::Margin m, double margin);
00121     KCommand *setMarginCommand(Q3StyleSheetItem::Margin m, double margin);
00122 
00123     //void setTabList(const KoTabulatorList & tabList );
00124     KCommand *setTabListCommand(const KoTabulatorList & tabList );
00125 
00126     //void setBackgroundColor(const QColor & color );
00127     KCommand *setBackgroundColorCommand(const QColor & color );
00128 
00129     //void setCounter(const KoParagCounter & counter );
00130     KCommand *setCounterCommand(const KoParagCounter & counter );
00131 
00132     KCommand *setLanguageCommand(const QString &);
00133 
00134     KCommand *setShadowTextCommand( double shadowDistanceX, double shadowDistanceY, const QColor& shadowColor );
00135 
00136     KCommand *setHyphenationCommand( bool _b );
00137 
00138 
00139     KCommand *setFontAttributeCommand( KoTextFormat::AttributeStyle _att);
00140 
00141     KCommand *setRelativeTextSizeCommand( double _size );
00142 
00143     KCommand *setOffsetFromBaseLineCommand( int _offset );
00144 
00145     KCommand *setWordByWordCommand( bool _b );
00146 
00147 
00148     QColor textColor() const;
00149     QFont textFont() const;
00150     QString textFontFamily()const;
00151     QString language() const;
00152     QColor textBackgroundColor()const;
00153     QColor textUnderlineColor()const;
00154 
00155     KoTextFormat::UnderlineType underlineType()const;
00156     KoTextFormat::StrikeOutType strikeOutType()const;
00157     KoTextFormat::UnderlineStyle underlineStyle()const;
00158     KoTextFormat::StrikeOutStyle strikeOutStyle()const;
00159 
00160 
00161 
00162     bool textUnderline()const;
00163     bool textDoubleUnderline()const;
00164 
00165     bool textBold()const;
00166     bool textStrikeOut()const;
00167     bool textItalic() const;
00168     bool textSubScript() const;
00169     bool textSuperScript() const;
00170     double shadowDistanceX() const;
00171     double shadowDistanceY() const;
00172     QColor shadowColor() const;
00173     KoTextFormat::AttributeStyle fontAttribute() const;
00174     double relativeTextSize() const;
00175     int offsetFromBaseLine()const;
00176     bool wordByWord()const;
00177     bool hyphenation()const;
00178 };
00179 
00186 class KOTEXT_EXPORT KoTextObject : public QObject, public KoTextFormatInterface
00187 {
00188     Q_OBJECT
00189 public:
00203     KoTextObject( KoTextZoomHandler *zh, const QFont& defaultFont, const QString &defaultLanguage,
00204                   bool defaultHyphenation, KoParagStyle* defaultStyle, int tabStopWidth = -1,
00205                   QObject* parent = 0, const char *name = 0 );
00206 
00216     KoTextObject( KoTextDocument *textdoc, KoParagStyle* defaultStyle,
00217                   QObject* parent = 0, const char *name = 0 );
00218 
00219     virtual ~KoTextObject();
00220 
00221 
00222     static QString acceptSelectionMimeType();
00225     static QString providesOasis( const QMimeData* mime );
00226 
00227     void setNeedSpellCheck(bool b);
00228     bool needSpellCheck() const { return m_needsSpellCheck;}
00229     void setProtectContent(bool b) { m_protectContent = b; }
00230     bool protectContent() const{ return m_protectContent;}
00234     KoTextDocument *textDocument() const { return textdoc; }
00235 
00236     void setAvailableHeight( int avail ) { m_availableHeight = avail; }
00237     int availableHeight() const;
00238 
00239     void undo();
00240     void redo();
00242     void clearUndoRedoInfo();
00243 
00245     bool hasSelection() const { return textdoc->hasSelection( KoTextDocument::Standard, true ); }
00247     QString selectedText( KoTextDocument::SelectionId selectionId = KoTextDocument::Standard ) const {
00248         return textdoc->selectedText( selectionId );
00249     }
00251     bool selectionHasCustomItems( KoTextDocument::SelectionId selectionId = KoTextDocument::Standard ) const;
00252 
00253     enum InsertFlag {
00254         DefaultInsertFlags = 0,
00255         CheckNewLine = 1, 
00256         OverwriteMode = 2,
00257         DoNotRemoveSelected = 4, 
00258         DoNotRepaint = 8         
00259     };
00260 
00272     void insert( KoTextCursor * cursor, KoTextFormat * currentFormat, const QString &text,
00273                  const QString & commandName,
00274                  KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00275                  int insertFlags = DefaultInsertFlags, // KDE4: TODO use QFlags
00276                  CustomItemsMap customItemsMap = CustomItemsMap() );
00277 
00285     void removeSelectedText( KoTextCursor * cursor, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00286                              const QString & cmdName = QString::null, bool createUndoRedo=true  );
00287 
00288     KCommand * replaceSelectionCommand( KoTextCursor * cursor, const QString & replacement,
00289                                         const QString & cmdName,
00290                                         KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00291                                         int insertFlags = DefaultInsertFlags, // KDE4: TODO use QFlags
00292                                         CustomItemsMap customItemsMap = CustomItemsMap() );
00293     KCommand * removeSelectedTextCommand( KoTextCursor * cursor, KoTextDocument::SelectionId selectionId, bool repaint = true );
00294     KCommand* insertParagraphCommand( KoTextCursor * cursor );
00295 
00308     void pasteText( KoTextCursor * cursor, const QString & text, KoTextFormat * currentFormat,
00309                     bool removeSelected );
00310     void selectAll( bool select );
00311 
00315     void highlightPortion( KoTextParag * parag, int index, int length, bool repaint );
00316     void removeHighlight( bool repaint );
00317 
00319     KCommand *setFormatCommand( const KoTextFormat *format, int flags, bool zoomFont = false );
00320 
00323     KCommand *setFormatCommand( KoTextCursor * cursor, KoTextFormat ** currentFormat, const KoTextFormat *format, int flags, bool zoomFont = false, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00324 
00325     enum KeyboardAction { // keep in sync with QTextEdit
00326         ActionBackspace,
00327         ActionDelete,
00328         ActionReturn,
00329         ActionKill
00330     };
00333     void doKeyboardAction( KoTextCursor * cursor, KoTextFormat * & currentFormat, KeyboardAction action );
00334 
00335     // -- Paragraph settings --
00336     KCommand * setCounterCommand( KoTextCursor * cursor, const KoParagCounter & counter, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00337     KCommand * setAlignCommand( KoTextCursor * cursor, int align , KoTextDocument::SelectionId selectionId = KoTextDocument::Standard);
00338     KCommand * setLineSpacingCommand( KoTextCursor * cursor, double spacing, KoParagLayout::SpacingType _type,KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00339     KCommand * setBordersCommand( KoTextCursor * cursor, const KoBorder& leftBorder, const KoBorder& rightBorder, const KoBorder& topBorder, const KoBorder& bottomBorder, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00340     KCommand * setJoinBordersCommand( KoTextCursor * cursor, bool join, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00341     KCommand * setMarginCommand( KoTextCursor * cursor, Q3StyleSheetItem::Margin m, double margin, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard);
00342     KCommand* setTabListCommand( KoTextCursor * cursor,const KoTabulatorList & tabList , KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00343     KCommand* setBackgroundColorCommand( KoTextCursor * cursor,const QColor & color , KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00344 
00345     KCommand * setParagDirectionCommand( KoTextCursor * cursor, QChar::Direction d, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00346 
00357     void applyStyle( KoTextCursor * cursor, const KoParagStyle * style,
00358                      KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00359                      int paragLayoutFlags = KoParagLayout::All, int formatFlags = KoTextFormat::Format,
00360                      bool createUndoRedo = true, bool interactive = true );
00361 
00367     KCommand* applyStyleCommand( KoTextCursor * cursor, const KoParagStyle * style,
00368                      KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00369                      int paragLayoutFlags = KoParagLayout::All, int formatFlags = KoTextFormat::Format,
00370                      bool createUndoRedo = true, bool interactive = true );
00371 
00372 
00377     void applyStyleChange( KoStyleChangeDefMap changed );
00380     void setFormat( KoTextCursor * cursor, KoTextFormat ** currentFormat, KoTextFormat *format, int flags, bool zoomFont = false );
00381 
00382 
00388     virtual KoTextFormat * currentFormat() const;
00389 
00393     virtual const KoParagLayout * currentParagLayoutFormat() const;
00394 
00395     virtual bool rtl() const;
00396 
00400     virtual KCommand *setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex=-1);
00401 
00402     // common for setParagLayoutFormatCommand above and KoTextView::setParagLayoutFormatCommand
00403     KCommand *setParagLayoutCommand( KoTextCursor * cursor, const KoParagLayout& paragLayout,
00404                                      KoTextDocument::SelectionId selectionId, int paragLayoutFlags,
00405                                      int marginIndex, bool createUndoRedo );
00409     virtual void setFormat( KoTextFormat * newFormat, int flags, bool zoomFont = false );
00410 
00412     int docFontSize( KoTextFormat * format ) const;
00414     int zoomedFontSize( int docFontSize ) const;
00415 
00417     void setViewArea( QWidget* w, int maxY );
00419     void ensureFormatted( KoTextParag * parag, bool emitAfterFormatting = true );
00420     void setLastFormattedParag( KoTextParag *parag );
00421 
00422     static QChar customItemChar() { return QChar( s_customItemChar ); }
00423 
00424     // Qt should really have support for public signals
00425     void emitHideCursor() { emit hideCursor(); }
00426     void emitShowCursor() { emit showCursor(); }
00427     void emitEnsureCursorVisible() { emit ensureCursorVisible(); }
00428     void emitUpdateUI( bool updateFormat, bool force = false ) { emit updateUI( updateFormat, force ); }
00429 
00430     void typingStarted();
00431     void typingDone();
00432 
00439     void abortFormatting();
00440 
00441     void selectionChangedNotify( bool enableActions = true );
00442 
00443     void emitNewCommand(KCommand *cmd);
00444 
00445     virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type);
00446 
00447     KCommand *changeCaseOfText(KoTextCursor *cursor, KoChangeCaseDia::TypeOfCase _type);
00448     QString textChangedCase(const QString& _text, KoChangeCaseDia::TypeOfCase _type);
00449     KCommand *changeCaseOfTextParag(int cursorPosStart, int cursorPosEnd,KoChangeCaseDia::TypeOfCase _type,KoTextCursor *cursor, KoTextParag *parag);
00450 
00451     void loadOasisContent( const QDomElement &bodyElem, KoOasisContext& context, KoStyleCollection * styleColl );
00452     void saveOasisContent( KoXmlWriter& writer, KoSavingContext& context ) const;
00453 
00454     // Similar to KoTextDocument::loadOasisText but there's no newline inserted before the first paragraph
00455     // or after the last one - so it's possible to paste just a few chars.
00456     // It also handles m_lastFormatted
00457     KoTextCursor pasteOasisText( const QDomElement &bodyElem, KoOasisContext& context,
00458                                  KoTextCursor& cursor, KoStyleCollection * styleColl );
00459 
00460 #ifndef NDEBUG
00461     void printRTDebug(int);
00462 #endif
00463 
00464     bool statistics( QProgressDialog *progress, ulong & charsWithSpace, ulong & charsWithoutSpace, ulong & words, ulong & sentences, ulong & syllables, ulong & lines, bool selected );
00465     int numberOfparagraphLineSelected( KoTextParag *parag);
00466 
00470     KoVariable* variableAtPoint( const QPoint& iPoint ) const;
00471 
00477     KoVariable* variableAtPosition( KoTextParag* parag, int index ) const;
00478 
00479     enum ParagModifyType { AddChar = 0, RemoveChar = 1, ChangeFormat = 2 };
00480 
00481 signals:
00484     void availableHeightNeeded();
00485 
00489     void afterFormatting( int bottom, KoTextParag* m_lastFormatted, bool* abort );
00490 
00495     void chapterParagraphFormatted( KoTextParag* parag );
00496 
00499     void formattingFirstParag();
00500 
00505     void newCommand( KCommand *cmd );
00506 
00508     void repaintChanged( KoTextObject * );
00509 
00510     void hideCursor();
00511     void showCursor();
00513     void setCursor( KoTextCursor * cursor );
00516     void updateUI( bool updateFormat, bool force = false );
00518     void showCurrentFormat();
00520     void ensureCursorVisible();
00522     void selectionChanged( bool hasSelection );
00523 
00524     void showFormatObject(const KoTextFormat &);
00525 
00526     // Keeping track of text modifications - not emitted during loading/closing.
00527     void paragraphCreated( KoTextParag* parag );
00528     void paragraphModified( KoTextParag* parag, int /*ParagModifyType*/, int pos, int length );
00529     void paragraphDeleted( KoTextParag* parag );
00530 
00531 public slots:
00532     // The default arguments are those used by the formatTimer.
00533     // The return value is used by ensureFormatted
00534     bool formatMore( int count = 10, bool emitAfterFormatting = true );
00535 
00536     void emitRepaintChanged() { emit repaintChanged( this ); }
00537 
00538 public: // made public for KWTextFrameSet...
00539 
00543     void storeParagUndoRedoInfo( KoTextCursor * cursor, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00545     void copyCharFormatting( KoTextParag *parag, int position, int index /*in text*/, bool moveCustomItems );
00546     void readFormats( KoTextCursor &c1, KoTextCursor &c2, bool copyParagLayouts = false, bool moveCustomItems = false );
00547 
00557     struct KOTEXT_EXPORT UndoRedoInfo { // borrowed from QTextEdit
00558         enum Type { Invalid, Insert, Delete, Return, RemoveSelected };
00559         UndoRedoInfo( KoTextObject* textobj );
00560         ~UndoRedoInfo() {}
00561         void clear();
00562         bool valid() const;
00563 
00564         KoTextString text; // storage for formatted text
00565         int id; // id of first parag
00566         int eid; // id of last parag
00567         int index; // index (for insertion/deletion)
00568         Type type; // type of command
00569         KoTextObject* textobj; // parent
00570         CustomItemsMap customItemsMap; // character position -> qtextcustomitem
00571         Q3ValueList<KoParagLayout> oldParagLayouts;
00572         KoParagLayout newParagLayout;
00573         KoTextCursor *cursor; // basically a "mark" of the view that started this undo/redo info
00574         // If the view changes, the next call to checkUndoRedoInfo will terminate the previous view's edition
00575         KMacroCommand *placeHolderCmd;
00576     };
00583     void newPlaceHolderCommand( const QString & name );
00584     void checkUndoRedoInfo( KoTextCursor * cursor, UndoRedoInfo::Type t );
00585 
00587     UndoRedoInfo & undoRedoInfoStruct() { return undoRedoInfo; }
00588 
00589     void setVisible(bool vis) { m_visible=vis; }
00590     bool isVisible() const { return m_visible; }
00591 
00592 private slots:
00593     void doChangeInterval();
00598     void slotAfterUndoRedo();
00599     void slotParagraphModified(KoTextParag *, int, int , int);
00600     void slotParagraphCreated(KoTextParag *);
00601     void slotParagraphDeleted(KoTextParag *);
00602 private:
00603     void init();
00604 
00605 private:
00606     class KoTextObjectPrivate;
00607     KoTextObjectPrivate* d;
00609     KoTextDocument *textdoc;
00610 
00613     KoParagStyle* m_defaultStyle;
00614 
00615     bool m_visible;
00616 
00618     UndoRedoInfo undoRedoInfo;
00619 
00623     KoTextParag *m_lastFormatted;
00625     QTimer *formatTimer, *startTimer;
00626     int interval;
00627 
00629     int m_availableHeight;
00631     QMap<QWidget *, int> m_mapViewAreas;
00632 
00633     //QPtrDict<int> m_origFontSizes; // Format -> doc font size.
00634 
00635     bool m_highlightSelectionAdded;
00636 
00637 #ifdef TIMING_FORMAT
00638     QTime m_time;
00639 #endif
00640 
00641     static const char s_customItemChar;
00642     bool m_needsSpellCheck;
00643     bool m_protectContent;
00644 };
00645 
00646 #endif

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