00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00029 class KoSavingContext;
00030 class KCommand;
00031 class KoTextFormat;
00032 class QProgressDialog;
00033 class KoLinkVariable;
00034 class KoVariable;
00035
00036
00037
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
00065 virtual KCommand *setFormatCommand( const KoTextFormat *format, int flags, bool zoomFont = false ) = 0;
00066
00068 virtual const KoParagLayout * currentParagLayoutFormat() const = 0;
00069
00075 virtual KCommand *setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex=-1) = 0;
00076
00077 virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type)=0;
00078
00079 KoTextDocCommand *deleteTextCommand( KoTextDocument *textdoc, int id, int index, const QMemArray<KoTextStringChar> & str, const CustomItemsMap & customItemsMap, const QValueList<KoParagLayout> & oldParagLayouts );
00080
00081 void setParagLayoutFormat( KoParagLayout *newLayout,int flags, int marginIndex=-1);
00082 void setFormat( KoTextFormat * newFormat, int flags, bool zoomFont = false );
00083
00084
00085
00086 KCommand *setBoldCommand(bool on);
00087
00088 KCommand *setItalicCommand(bool on);
00089
00090 KCommand *setUnderlineCommand(bool on);
00091
00092 KCommand *setDoubleUnderlineCommand( bool on );
00093 KCommand *setUnderlineColorCommand( const QColor &color );
00094 KCommand *setStrikeOutCommand(bool on);
00095
00096 KCommand *setTextColorCommand(const QColor &color);
00097
00098 KCommand *setPointSizeCommand( int s );
00099
00100 KCommand *setFamilyCommand(const QString &font);
00101
00102 KCommand *setTextSubScriptCommand(bool on);
00103
00104 KCommand *setTextSuperScriptCommand(bool on);
00105
00106
00107 KCommand *setDefaultFormatCommand();
00108
00109
00110 KCommand *setTextBackgroundColorCommand(const QColor &);
00111
00112
00113 KCommand *setAlignCommand(int align);
00114
00115
00116 KCommand *setMarginCommand(QStyleSheetItem::Margin m, double margin);
00117
00118
00119 KCommand *setTabListCommand(const KoTabulatorList & tabList );
00120
00121
00122 KCommand *setBackgroundColorCommand(const QColor & color );
00123
00124
00125 KCommand *setCounterCommand(const KoParagCounter & counter );
00126
00127 KCommand *setLanguageCommand(const QString &);
00128
00129 KCommand *setShadowTextCommand( double shadowDistanceX, double shadowDistanceY, const QColor& shadowColor );
00130
00131 KCommand *setHyphenationCommand( bool _b );
00132
00133
00134 KCommand *setFontAttributeCommand( KoTextFormat::AttributeStyle _att);
00135
00136 KCommand *setRelativeTextSizeCommand( double _size );
00137
00138 KCommand *setOffsetFromBaseLineCommand( int _offset );
00139
00140 KCommand *setWordByWordCommand( bool _b );
00141
00142
00143 QColor textColor() const;
00144 QFont textFont() const;
00145 QString textFontFamily()const;
00146 QString language() const;
00147 QColor textBackgroundColor()const;
00148 QColor textUnderlineColor()const;
00149
00150 KoTextFormat::UnderlineType underlineType()const;
00151 KoTextFormat::StrikeOutType strikeOutType()const;
00152 KoTextFormat::UnderlineStyle underlineStyle()const;
00153 KoTextFormat::StrikeOutStyle strikeOutStyle()const;
00154
00155
00156
00157 bool textUnderline()const;
00158 bool textDoubleUnderline()const;
00159
00160 bool textBold()const;
00161 bool textStrikeOut()const;
00162 bool textItalic() const;
00163 bool textSubScript() const;
00164 bool textSuperScript() const;
00165 double shadowDistanceX() const;
00166 double shadowDistanceY() const;
00167 QColor shadowColor() const;
00168 KoTextFormat::AttributeStyle fontAttribute() const;
00169 double relativeTextSize() const;
00170 int offsetFromBaseLine()const;
00171 bool wordByWord()const;
00172 bool hyphenation()const;
00173 };
00174
00181 class KOTEXT_EXPORT KoTextObject : public QObject, public KoTextFormatInterface
00182 {
00183 Q_OBJECT
00184 public:
00198 KoTextObject( KoTextZoomHandler *zh, const QFont& defaultFont, const QString &defaultLanguage,
00199 bool defaultHyphenation, KoParagStyle* defaultStyle, int tabStopWidth = -1,
00200 QObject* parent = 0, const char *name = 0 );
00201
00211 KoTextObject( KoTextDocument *textdoc, KoParagStyle* defaultStyle,
00212 QObject* parent = 0, const char *name = 0 );
00213
00214 virtual ~KoTextObject();
00215
00216
00217 static const char * acceptSelectionMimeType();
00220 static QCString providesOasis( QMimeSource* mime );
00221
00222 void setNeedSpellCheck(bool b);
00223 bool needSpellCheck() const { return m_needsSpellCheck;}
00224 void setProtectContent(bool b) { m_protectContent = b; }
00225 bool protectContent() const{ return m_protectContent;}
00229 KoTextDocument *textDocument() const { return textdoc; }
00230
00231 void setAvailableHeight( int avail ) { m_availableHeight = avail; }
00232 int availableHeight() const;
00233
00234 void undo();
00235 void redo();
00237 void clearUndoRedoInfo();
00238
00240 bool hasSelection() const { return textdoc->hasSelection( KoTextDocument::Standard, true ); }
00242 QString selectedText( KoTextDocument::SelectionId selectionId = KoTextDocument::Standard ) const {
00243 return textdoc->selectedText( selectionId );
00244 }
00246 bool selectionHasCustomItems( KoTextDocument::SelectionId selectionId = KoTextDocument::Standard ) const;
00247
00248 enum InsertFlag {
00249 DefaultInsertFlags = 0,
00250 CheckNewLine = 1,
00251 OverwriteMode = 2,
00252 DoNotRemoveSelected = 4,
00253 DoNotRepaint = 8
00254 };
00255
00267 void insert( KoTextCursor * cursor, KoTextFormat * currentFormat, const QString &text,
00268 const QString & commandName,
00269 KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00270 int insertFlags = DefaultInsertFlags,
00271 CustomItemsMap customItemsMap = CustomItemsMap() );
00272
00280 void removeSelectedText( KoTextCursor * cursor, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00281 const QString & cmdName = QString::null, bool createUndoRedo=true );
00282
00283 KCommand * replaceSelectionCommand( KoTextCursor * cursor, const QString & replacement,
00284 const QString & cmdName,
00285 KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00286 int insertFlags = DefaultInsertFlags,
00287 CustomItemsMap customItemsMap = CustomItemsMap() );
00288 KCommand * removeSelectedTextCommand( KoTextCursor * cursor, KoTextDocument::SelectionId selectionId, bool repaint = true );
00289 KCommand* insertParagraphCommand( KoTextCursor * cursor );
00290
00303 void pasteText( KoTextCursor * cursor, const QString & text, KoTextFormat * currentFormat,
00304 bool removeSelected );
00305 void selectAll( bool select );
00306
00310 void highlightPortion( KoTextParag * parag, int index, int length, bool repaint );
00311 void removeHighlight( bool repaint );
00312
00314 KCommand *setFormatCommand( const KoTextFormat *format, int flags, bool zoomFont = false );
00315
00318 KCommand *setFormatCommand( KoTextCursor * cursor, KoTextFormat ** currentFormat, const KoTextFormat *format, int flags, bool zoomFont = false, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00319
00320 enum KeyboardAction {
00321 ActionBackspace,
00322 ActionDelete,
00323 ActionReturn,
00324 ActionKill
00325 };
00328 void doKeyboardAction( KoTextCursor * cursor, KoTextFormat * & currentFormat, KeyboardAction action );
00329
00330
00331 KCommand * setCounterCommand( KoTextCursor * cursor, const KoParagCounter & counter, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00332 KCommand * setAlignCommand( KoTextCursor * cursor, int align , KoTextDocument::SelectionId selectionId = KoTextDocument::Standard);
00333 KCommand * setLineSpacingCommand( KoTextCursor * cursor, double spacing, KoParagLayout::SpacingType _type,KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00334 KCommand * setBordersCommand( KoTextCursor * cursor, const KoBorder& leftBorder, const KoBorder& rightBorder, const KoBorder& topBorder, const KoBorder& bottomBorder, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00335 KCommand * setJoinBordersCommand( KoTextCursor * cursor, bool join, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00336 KCommand * setMarginCommand( KoTextCursor * cursor, QStyleSheetItem::Margin m, double margin, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard);
00337 KCommand* setTabListCommand( KoTextCursor * cursor,const KoTabulatorList & tabList , KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00338 KCommand* setBackgroundColorCommand( KoTextCursor * cursor,const QColor & color , KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00339
00340 KCommand * setParagDirectionCommand( KoTextCursor * cursor, QChar::Direction d, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00341
00352 void applyStyle( KoTextCursor * cursor, const KoParagStyle * style,
00353 KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00354 int paragLayoutFlags = KoParagLayout::All, int formatFlags = KoTextFormat::Format,
00355 bool createUndoRedo = true, bool interactive = true );
00356
00362 KCommand* applyStyleCommand( KoTextCursor * cursor, const KoParagStyle * style,
00363 KoTextDocument::SelectionId selectionId = KoTextDocument::Standard,
00364 int paragLayoutFlags = KoParagLayout::All, int formatFlags = KoTextFormat::Format,
00365 bool createUndoRedo = true, bool interactive = true );
00366
00367
00372 void applyStyleChange( KoStyleChangeDefMap changed );
00375 void setFormat( KoTextCursor * cursor, KoTextFormat ** currentFormat, KoTextFormat *format, int flags, bool zoomFont = false );
00376
00377
00383 virtual KoTextFormat * currentFormat() const;
00384
00388 virtual const KoParagLayout * currentParagLayoutFormat() const;
00389
00390 virtual bool rtl() const;
00391
00395 virtual KCommand *setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex=-1);
00396
00397
00398 KCommand *setParagLayoutCommand( KoTextCursor * cursor, const KoParagLayout& paragLayout,
00399 KoTextDocument::SelectionId selectionId, int paragLayoutFlags,
00400 int marginIndex, bool createUndoRedo );
00404 virtual void setFormat( KoTextFormat * newFormat, int flags, bool zoomFont = false );
00405
00407 int docFontSize( KoTextFormat * format ) const;
00409 int zoomedFontSize( int docFontSize ) const;
00410
00412 void setViewArea( QWidget* w, int maxY );
00414 void ensureFormatted( KoTextParag * parag, bool emitAfterFormatting = true );
00415 void setLastFormattedParag( KoTextParag *parag );
00416
00417 static QChar customItemChar() { return QChar( s_customItemChar ); }
00418
00419
00420 void emitHideCursor() { emit hideCursor(); }
00421 void emitShowCursor() { emit showCursor(); }
00422 void emitEnsureCursorVisible() { emit ensureCursorVisible(); }
00423 void emitUpdateUI( bool updateFormat, bool force = false ) { emit updateUI( updateFormat, force ); }
00424
00425 void typingStarted();
00426 void typingDone();
00427
00434 void abortFormatting();
00435
00436 void selectionChangedNotify( bool enableActions = true );
00437
00438 void emitNewCommand(KCommand *cmd);
00439
00440 virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type);
00441
00442 KCommand *changeCaseOfText(KoTextCursor *cursor, KoChangeCaseDia::TypeOfCase _type);
00443 QString textChangedCase(const QString& _text, KoChangeCaseDia::TypeOfCase _type);
00444 KCommand *changeCaseOfTextParag(int cursorPosStart, int cursorPosEnd,KoChangeCaseDia::TypeOfCase _type,KoTextCursor *cursor, KoTextParag *parag);
00445
00446 void loadOasisContent( const QDomElement &bodyElem, KoOasisContext& context, KoStyleCollection * styleColl );
00447 void saveOasisContent( KoXmlWriter& writer, KoSavingContext& context ) const;
00448
00449
00450
00451
00452 KoTextCursor pasteOasisText( const QDomElement &bodyElem, KoOasisContext& context,
00453 KoTextCursor& cursor, KoStyleCollection * styleColl );
00454
00455 #ifndef NDEBUG
00456 void printRTDebug(int);
00457 #endif
00458
00459 bool statistics( QProgressDialog *progress, ulong & charsWithSpace, ulong & charsWithoutSpace, ulong & words, ulong & sentences, ulong & syllables, ulong & lines, bool selected );
00460 int numberOfparagraphLineSelected( KoTextParag *parag);
00461
00465 KoVariable* variableAtPoint( const QPoint& iPoint ) const;
00466
00472 KoVariable* variableAtPosition( KoTextParag* parag, int index ) const;
00473
00474 enum ParagModifyType { AddChar = 0, RemoveChar = 1, ChangeFormat = 2 };
00475
00476 signals:
00479 void availableHeightNeeded();
00480
00484 void afterFormatting( int bottom, KoTextParag* m_lastFormatted, bool* abort );
00485
00490 void chapterParagraphFormatted( KoTextParag* parag );
00491
00494 void formattingFirstParag();
00495
00500 void newCommand( KCommand *cmd );
00501
00503 void repaintChanged( KoTextObject * );
00504
00505 void hideCursor();
00506 void showCursor();
00508 void setCursor( KoTextCursor * cursor );
00511 void updateUI( bool updateFormat, bool force = false );
00513 void showCurrentFormat();
00515 void ensureCursorVisible();
00517 void selectionChanged( bool hasSelection );
00518
00519 void showFormatObject(const KoTextFormat &);
00520
00521
00522 void paragraphCreated( KoTextParag* parag );
00523 void paragraphModified( KoTextParag* parag, int , int pos, int length );
00524 void paragraphDeleted( KoTextParag* parag );
00525
00526 public slots:
00527
00528
00529 bool formatMore( int count = 10, bool emitAfterFormatting = true );
00530
00531 void emitRepaintChanged() { emit repaintChanged( this ); }
00532
00533 public:
00534
00538 void storeParagUndoRedoInfo( KoTextCursor * cursor, KoTextDocument::SelectionId selectionId = KoTextDocument::Standard );
00540 void copyCharFormatting( KoTextParag *parag, int position, int index , bool moveCustomItems );
00541 void readFormats( KoTextCursor &c1, KoTextCursor &c2, bool copyParagLayouts = false, bool moveCustomItems = false );
00542
00552 struct KOTEXT_EXPORT UndoRedoInfo {
00553 enum Type { Invalid, Insert, Delete, Return, RemoveSelected };
00554 UndoRedoInfo( KoTextObject* textobj );
00555 ~UndoRedoInfo() {}
00556 void clear();
00557 bool valid() const;
00558
00559 KoTextString text;
00560 int id;
00561 int eid;
00562 int index;
00563 Type type;
00564 KoTextObject* textobj;
00565 CustomItemsMap customItemsMap;
00566 QValueList<KoParagLayout> oldParagLayouts;
00567 KoParagLayout newParagLayout;
00568 KoTextCursor *cursor;
00569
00570 KMacroCommand *placeHolderCmd;
00571 };
00578 void newPlaceHolderCommand( const QString & name );
00579 void checkUndoRedoInfo( KoTextCursor * cursor, UndoRedoInfo::Type t );
00580
00582 UndoRedoInfo & undoRedoInfoStruct() { return undoRedoInfo; }
00583
00584 void setVisible(bool vis) { m_visible=vis; }
00585 bool isVisible() const { return m_visible; }
00586
00587 private slots:
00588 void doChangeInterval();
00593 void slotAfterUndoRedo();
00594 void slotParagraphModified(KoTextParag *, int, int , int);
00595 void slotParagraphCreated(KoTextParag *);
00596 void slotParagraphDeleted(KoTextParag *);
00597 private:
00598 void init();
00599
00600 private:
00601 class KoTextObjectPrivate;
00602 KoTextObjectPrivate* d;
00604 KoTextDocument *textdoc;
00605
00608 KoParagStyle* m_defaultStyle;
00609
00610 bool m_visible;
00611
00613 UndoRedoInfo undoRedoInfo;
00614
00618 KoTextParag *m_lastFormatted;
00620 QTimer *formatTimer, *changeIntervalTimer;
00621 int interval;
00622
00624 int m_availableHeight;
00626 QMap<QWidget *, int> m_mapViewAreas;
00627
00628
00629
00630 bool m_highlightSelectionAdded;
00631
00632 #ifdef TIMING_FORMAT
00633 QTime m_time;
00634 #endif
00635
00636 static const char s_customItemChar;
00637 bool m_needsSpellCheck;
00638 bool m_protectContent;
00639 };
00640
00641 #endif