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 "kostyle.h"
00026
#include "kotextdocument.h"
00027
class KCommand;
00028
class KoTextFormat;
00029
00030
00031
00041 class KoTextFormatInterface
00042 {
00043
public:
00044
KoTextFormatInterface() {}
00045
00047
virtual KoTextFormat *
currentFormat()
const = 0;
00048
00049
virtual bool rtl()
const = 0;
00050
00056
virtual KCommand *
setFormatCommand(
const KoTextFormat *format,
int flags,
bool zoomFont =
false ) = 0;
00057
00059
virtual const KoParagLayout *
currentParagLayoutFormat()
const = 0;
00060
00065
virtual KCommand *
setParagLayoutFormatCommand(
KoParagLayout *newLayout,
int flags,
int marginIndex=-1) = 0;
00066
00067
virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type)=0;
00068
00069 KoTextDocCommand *deleteTextCommand( KoTextDocument *textdoc,
int id,
int index,
const QMemArray<KoTextStringChar> & str,
const CustomItemsMap & customItemsMap,
const QValueList<KoParagLayout> & oldParagLayouts );
00070
00071
void setParagLayoutFormat(
KoParagLayout *newLayout,
int flags,
int marginIndex=-1);
00072
void setFormat(
KoTextFormat * newFormat,
int flags,
bool zoomFont =
false );
00073
00074
00075
00076 KCommand *setBoldCommand(
bool on);
00077
00078 KCommand *setItalicCommand(
bool on);
00079
00080 KCommand *setUnderlineCommand(
bool on);
00081
00082 KCommand *setDoubleUnderlineCommand(
bool on );
00083 KCommand *setUnderlineColorCommand(
const QColor &color );
00084 KCommand *setStrikeOutCommand(
bool on);
00085
00086 KCommand *setTextColorCommand(
const QColor &color);
00087
00088 KCommand *setPointSizeCommand(
int s );
00089
00090 KCommand *setFamilyCommand(
const QString &font);
00091
00092 KCommand *setTextSubScriptCommand(
bool on);
00093
00094 KCommand *setTextSuperScriptCommand(
bool on);
00095
00096
00097 KCommand *setDefaultFormatCommand();
00098
00099
00100 KCommand *setTextBackgroundColorCommand(
const QColor &);
00101
00102
00103 KCommand *setAlignCommand(
int align);
00104
00105
00106 KCommand *setMarginCommand(QStyleSheetItem::Margin m,
double margin);
00107
00108
00109 KCommand *setTabListCommand(
const KoTabulatorList & tabList );
00110
00111
00112 KCommand *setCounterCommand(
const KoParagCounter & counter );
00113
00114 KCommand *setLanguageCommand(
const QString &);
00115
00116 KCommand *setShadowTextCommand(
double shadowDistanceX,
double shadowDistanceY,
const QColor& shadowColor );
00117
00118 KCommand *setHyphenationCommand(
bool _b );
00119
00120
00121 KCommand *setFontAttributeCommand( KoTextFormat::AttributeStyle _att);
00122
00123 KCommand *setRelativeTextSizeCommand(
double _size );
00124
00125 KCommand *setOffsetFromBaseLineCommand(
int _offset );
00126
00127 KCommand *setWordByWordCommand(
bool _b );
00128
00129
00130
QColor textColor()
const;
00131
QFont textFont()
const;
00132
QString textFontFamily()
const;
00133
QString language()
const;
00134
QColor textBackgroundColor()
const;
00135
QColor textUnderlineColor()
const;
00136
00137 KoTextFormat::UnderlineType underlineType()
const;
00138 KoTextFormat::StrikeOutType strikeOutType()
const;
00139 KoTextFormat::UnderlineStyle underlineStyle()
const;
00140 KoTextFormat::StrikeOutStyle strikeOutStyle()
const;
00141
00142
00143
00144
bool textUnderline()
const;
00145
bool textDoubleUnderline()
const;
00146
00147
bool textBold()
const;
00148
bool textStrikeOut()
const;
00149
bool textItalic()
const;
00150
bool textSubScript()
const;
00151
bool textSuperScript()
const;
00152
double shadowDistanceX()
const;
00153
double shadowDistanceY()
const;
00154
QColor shadowColor()
const;
00155 KoTextFormat::AttributeStyle fontAttribute()
const;
00156
double relativeTextSize()
const;
00157
int offsetFromBaseLine()
const;
00158
bool wordByWord()
const;
00159
bool hyphenation()
const;
00160 };
00161
00168 class KoTextObject :
public QObject,
public KoTextFormatInterface
00169 {
00170 Q_OBJECT
00171
public:
00178
KoTextObject(
KoZoomHandler *zh,
const QFont& defaultFont,
const QString &defaultLanguage,
bool hyphen,
double ulw,
KoStyle* defaultStyle,
int _tabStopWidth = -1,
00179
QObject* parent = 0,
const char *name = 0 );
00180
00187
KoTextObject( KoTextDocument *textdoc,
KoStyle* defaultStyle,
00188
QObject* parent = 0,
const char *name = 0 );
00189
00190
virtual ~
KoTextObject();
00191
00192
00193
void setNeedSpellCheck(
bool b);
00194
bool needSpellCheck()
const {
return m_needsSpellCheck;}
00195
void setProtectContent(
bool b) { m_protectContent = b; }
00196
bool protectContent()
const{
return m_protectContent;}
00200 KoTextDocument *
textDocument()
const {
return textdoc; }
00201
00202
void setAvailableHeight(
int avail ) { m_availableHeight = avail; }
00203
int availableHeight() const;
00204
00205
void undo();
00206
void redo();
00208
void clearUndoRedoInfo();
00209
00211 bool hasSelection()
const {
return textdoc->hasSelection( KoTextDocument::Standard,
true ); }
00213 QString selectedText(
int selectionId = KoTextDocument::Standard )
const {
00214
return textdoc->selectedText( selectionId );
00215 }
00217
bool selectionHasCustomItems(
int selectionId = KoTextDocument::Standard )
const;
00218
00230
void insert( KoTextCursor * cursor,
KoTextFormat * currentFormat,
const QString &text,
00231
bool checkNewLine,
bool removeSelected,
const QString & commandName,
00232
CustomItemsMap customItemsMap =
CustomItemsMap(),
00233
int selectionId = KoTextDocument::Standard,
00234
bool repaint =
true );
00241
void removeSelectedText( KoTextCursor * cursor,
int selectionId = KoTextDocument::Standard,
00242
const QString & cmdName = QString::null,
bool createUndoRedo=
true );
00243
00244 KCommand * replaceSelectionCommand( KoTextCursor * cursor,
const QString & replacement,
00245
int selectionId,
const QString & cmdName,
bool repaint =
true );
00246 KCommand * removeSelectedTextCommand( KoTextCursor * cursor,
int selectionId,
bool repaint =
true );
00247 KCommand* insertParagraphCommand( KoTextCursor * cursor );
00248
00249
void pasteText( KoTextCursor * cursor,
const QString & text,
KoTextFormat * currentFormat,
bool removeSelected );
00250
void selectAll(
bool select );
00251
00255
void highlightPortion( KoTextParag * parag,
int index,
int length,
bool repaint );
00256
void removeHighlight(
bool repaint );
00257
00259 KCommand *setFormatCommand(
const KoTextFormat *format,
int flags,
bool zoomFont =
false );
00260
00263 KCommand *setFormatCommand( KoTextCursor * cursor,
KoTextFormat ** currentFormat,
const KoTextFormat *format,
int flags,
bool zoomFont =
false,
int selectionId = KoTextDocument::Standard );
00264
00266 enum SelectionIds {
00267 HighlightSelection = 1
00268 };
00269
00270
enum KeyboardAction {
00271 ActionBackspace,
00272 ActionDelete,
00273 ActionReturn,
00274 ActionKill
00275 };
00278
void doKeyboardAction( KoTextCursor * cursor,
KoTextFormat * & currentFormat, KeyboardAction action );
00279
00280
00281 KCommand * setCounterCommand( KoTextCursor * cursor,
const KoParagCounter & counter,
int selectionId = KoTextDocument::Standard );
00282 KCommand * setAlignCommand( KoTextCursor * cursor,
int align ,
int selectionId = KoTextDocument::Standard);
00283 KCommand * setLineSpacingCommand( KoTextCursor * cursor,
double spacing, KoParagLayout::SpacingType _type,
int selectionId = KoTextDocument::Standard );
00284 KCommand * setBordersCommand( KoTextCursor * cursor,
const KoBorder& leftBorder,
const KoBorder& rightBorder,
const KoBorder& topBorder,
const KoBorder& bottomBorder,
int selectionId = KoTextDocument::Standard );
00285 KCommand * setMarginCommand( KoTextCursor * cursor, QStyleSheetItem::Margin m,
double margin,
int selectionId = KoTextDocument::Standard);
00286 KCommand* setTabListCommand( KoTextCursor * cursor,
const KoTabulatorList & tabList ,
int selectionId = KoTextDocument::Standard );
00287
00288 KCommand * setParagDirectionCommand( KoTextCursor * cursor, QChar::Direction d,
int selectionId = KoTextDocument::Standard );
00289
00300
void applyStyle( KoTextCursor * cursor,
const KoStyle * style,
00301
int selectionId = KoTextDocument::Standard,
00302
int paragLayoutFlags = KoParagLayout::All,
int formatFlags = KoTextFormat::Format,
00303
bool createUndoRedo =
true,
bool interactive =
true );
00304
00310 KCommand*
applyStyleCommand( KoTextCursor * cursor,
const KoStyle * style,
00311
int selectionId = KoTextDocument::Standard,
00312
int paragLayoutFlags = KoParagLayout::All,
int formatFlags = KoTextFormat::Format,
00313
bool createUndoRedo =
true,
bool interactive =
true );
00314
00315
00321
void applyStyleChange(
StyleChangeDefMap changed );
00324
void setFormat( KoTextCursor * cursor,
KoTextFormat ** currentFormat,
KoTextFormat *format,
int flags,
bool zoomFont =
false );
00325
00326
00332
virtual KoTextFormat *
currentFormat() const;
00333
00337 virtual const
KoParagLayout * currentParagLayoutFormat() const;
00338
00339 virtual
bool rtl() const;
00340
00344 virtual KCommand *setParagLayoutFormatCommand(
KoParagLayout *newLayout,
int flags,
int marginIndex=-1);
00345
00346
00347 KCommand *setParagLayoutFormatCommand( KoTextCursor* cursor,
int selectionId,
KoParagLayout *newLayout,
int flags,
int marginIndex );
00348
00352 virtual
void setFormat(
KoTextFormat * newFormat,
int flags,
bool zoomFont = false );
00353
00355
int docFontSize(
KoTextFormat * format ) const;
00357
int zoomedFontSize(
int docFontSize ) const;
00358
00360
void setViewArea(
QWidget* w,
int maxY );
00362
void ensureFormatted( KoTextParag * parag,
bool emitAfterFormatting = true );
00363
void setLastFormattedParag( KoTextParag *parag );
00364
00365 static
QChar customItemChar() {
return QChar( s_customItemChar ); }
00366
00367
00368
void emitHideCursor() { emit hideCursor(); }
00369
void emitShowCursor() { emit showCursor(); }
00370
void emitEnsureCursorVisible() { emit
ensureCursorVisible(); }
00371
void emitUpdateUI(
bool updateFormat,
bool force =
false ) { emit
updateUI( updateFormat, force ); }
00372
00373
void typingStarted();
00374
void typingDone();
00375
00382
void abortFormatting();
00383
00384
void selectionChangedNotify(
bool enableActions =
true );
00385
00386
void emitNewCommand(KCommand *cmd);
00387
00388
virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type);
00389
00390 KCommand *changeCaseOfText(KoTextCursor *cursor, KoChangeCaseDia::TypeOfCase _type);
00391
QString textChangedCase(
const QString& _text, KoChangeCaseDia::TypeOfCase _type);
00392 KCommand *changeCaseOfTextParag(
int cursorPosStart,
int cursorPosEnd,KoChangeCaseDia::TypeOfCase _type,KoTextCursor *cursor, KoTextParag *parag);
00393
00394
#ifndef NDEBUG
00395
void printRTDebug(
int);
00396
#endif
00397
00398
enum ParagModifyType { AddChar = 0, RemoveChar = 1, ChangeFormat = 2 };
00399
00400 signals:
00403
void availableHeightNeeded();
00404
00408
void afterFormatting(
int bottom, KoTextParag* m_lastFormatted,
bool* abort );
00409
00414
void chapterParagraphFormatted( KoTextParag* parag );
00415
00418
void formattingFirstParag();
00419
00424
void newCommand( KCommand *cmd );
00425
00427
void repaintChanged(
KoTextObject * );
00428
00429
void hideCursor();
00430
void showCursor();
00432
void setCursor( KoTextCursor * cursor );
00435
void updateUI(
bool updateFormat,
bool force =
false );
00437
void showCurrentFormat();
00439
void ensureCursorVisible();
00441
void selectionChanged(
bool hasSelection );
00442
00443
void showFormatObject(
const KoTextFormat &);
00444
00445
00446
void paragraphCreated( KoTextParag* parag );
00447
void paragraphModified( KoTextParag* parag,
int ,
int pos,
int length );
00448
void paragraphDeleted( KoTextParag* parag );
00449
00450
public slots:
00451
00452
00453
bool formatMore(
int count = 10,
bool emitAfterFormatting =
true );
00454
00455
void emitRepaintChanged() { emit repaintChanged(
this ); }
00456
00457
public:
00458
00462
void storeParagUndoRedoInfo( KoTextCursor * cursor,
int selectionId = KoTextDocument::Standard );
00464
void copyCharFormatting( KoTextParag *parag,
int position,
int index ,
bool moveCustomItems );
00465
void readFormats( KoTextCursor &c1, KoTextCursor &c2,
bool copyParagLayouts =
false,
bool moveCustomItems =
false );
00466
00476 struct UndoRedoInfo {
00477
enum Type { Invalid, Insert, Delete, Return, RemoveSelected };
00478
UndoRedoInfo(
KoTextObject* textobj );
00479 ~
UndoRedoInfo() {}
00480
void clear();
00481
bool valid()
const;
00482
00483 KoTextString text;
00484
int id;
00485
int eid;
00486
int index;
00487 Type type;
00488
KoTextObject* textobj;
00489
CustomItemsMap customItemsMap;
00490
QValueList<KoParagLayout> oldParagLayouts;
00491
KoParagLayout newParagLayout;
00492 KoTextCursor *cursor;
00493
00494 KMacroCommand *placeHolderCmd;
00495 };
00502
void newPlaceHolderCommand(
const QString & name );
00503
void checkUndoRedoInfo( KoTextCursor * cursor, UndoRedoInfo::Type t );
00504
00506 UndoRedoInfo &
undoRedoInfoStruct() {
return undoRedoInfo; }
00507
00508
void setVisible(
bool vis) { m_visible=vis; }
00509
bool isVisible()
const {
return m_visible; }
00510
00511
private slots:
00512
void doChangeInterval();
00517
void slotAfterUndoRedo();
00518
void slotParagraphModified(KoTextParag *,
int,
int ,
int);
00519
void slotParagraphCreated(KoTextParag *);
00520
void slotParagraphDeleted(KoTextParag *);
00521
private:
00522
void init();
00523
00524
private:
00525
class KoTextObjectPrivate;
00526 KoTextObjectPrivate* d;
00528 KoTextDocument *textdoc;
00529
00532
KoStyle* m_defaultStyle;
00533
00534
bool m_visible;
00535
00537 UndoRedoInfo undoRedoInfo;
00538
00542 KoTextParag *m_lastFormatted;
00544
QTimer *formatTimer, *changeIntervalTimer;
00545
int interval;
00546
00548
int m_availableHeight;
00550
QMap<QWidget *, int> m_mapViewAreas;
00551
00552
00553
00554
bool m_highlightSelectionAdded;
00555
00556
#ifdef TIMING_FORMAT
00557
QTime m_time;
00558
#endif
00559
00560
static const char s_customItemChar;
00561
bool m_needsSpellCheck;
00562
bool m_protectContent;
00563 };
00564
00565
#endif