[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/plugins/textshape
From: Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date: 2008-11-30 19:07:39
Message-ID: 1228072059.261184.22154.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 890974 by pstirnweiss:
working version of TextInsert and NewParagraph commands
M +43 -49 TextTool.cpp
M +42 -40 TextTool.h
M +12 -22 commands/TextInsertParagraphCommand.cpp
M +10 -18 commands/TextInsertTextCommand.cpp
M +0 -1 commands/TextInsertTextCommand.h
--- trunk/koffice/plugins/textshape/TextTool.cpp #890973:890974
@@ -121,6 +121,43 @@
return ltr < rtl;
}
+TextTool::UndoTextCommand::UndoTextCommand(QTextDocument *document, TextTool *tool, \
QUndoCommand *parent) + : QUndoCommand(i18n("Text"), parent),
+ m_document(document),
+ m_tool(tool)
+{
+}
+
+void TextTool::UndoTextCommand::undo()
+{
+ if (m_document.isNull())
+ return;
+ if (! m_tool.isNull()) {
+ m_tool->stopMacro();
+ m_tool->m_allowAddUndoCommand = false;
+ if (m_tool->m_changeTracker && \
!m_tool->m_canvas->resourceProvider()->boolResource(KoCanvasResource::DocumentIsLoading))
+ m_tool->m_changeTracker->notifyForUndo();
+ m_document->undo(&m_tool->m_caret);
+ } else
+ m_document->undo();
+ if (! m_tool.isNull())
+ m_tool->m_allowAddUndoCommand = true;
+}
+
+void TextTool::UndoTextCommand::redo()
+{
+ if (m_document.isNull())
+ return;
+
+ if (! m_tool.isNull()) {
+ m_tool->m_allowAddUndoCommand = false;
+ m_document->redo(&m_tool->m_caret);
+ } else
+ m_document->redo();
+ if (! m_tool.isNull())
+ m_tool->m_allowAddUndoCommand = true;
+}
+
TextTool::TextTool(KoCanvasBase *canvas)
: KoTool(canvas),
m_textShape(0),
@@ -1277,56 +1314,18 @@
void TextTool::addUndoCommand()
{
-//kDebug()<<"in slot add undoCommand";
-m_commandCounter++;
if (! m_allowAddUndoCommand) return;
- class UndoTextCommand : public QUndoCommand
- {
- public:
- UndoTextCommand(QTextDocument *document, TextTool *tool, QUndoCommand \
*parent = 0)
- : QUndoCommand(i18n("Text"), parent),
- m_document(document),
- m_tool(tool) {
- }
-
- void undo() {
- if (m_document.isNull())
- return;
- if (! m_tool.isNull()) {
- m_tool->stopMacro();
- m_tool->m_allowAddUndoCommand = false;
- if (m_tool->m_changeTracker && \
!m_tool->m_canvas->resourceProvider()->boolResource(KoCanvasResource::DocumentIsLoading))
- m_tool->m_changeTracker->notifyForUndo();
- m_document->undo(&m_tool->m_caret);
- } else
- m_document->undo();
- if (! m_tool.isNull())
- m_tool->m_allowAddUndoCommand = true;
- }
-
- void redo() {
- if (m_document.isNull())
- return;
-
- if (! m_tool.isNull()) {
- m_tool->m_allowAddUndoCommand = false;
- m_document->redo(&m_tool->m_caret);
- } else
- m_document->redo();
- if (! m_tool.isNull())
- m_tool->m_allowAddUndoCommand = true;
- }
-
- QPointer<QTextDocument> m_document;
- QPointer<TextTool> m_tool;
- };
+
if (m_currentCommand) {
new UndoTextCommand(m_textShapeData->document(), this, m_currentCommand);
if (! m_currentCommandHasChildren)
+ {
m_canvas->addCommand(m_currentCommand);
+ }
m_currentCommandHasChildren = true;
- } else
+ } else {
m_canvas->addCommand(new UndoTextCommand(m_textShapeData->document(), \
this)); + }
}
void TextTool::addCommand(QUndoCommand *command)
@@ -1533,12 +1532,7 @@
return m_canvas->resourceProvider()->boolResource(KoText::BidiDocument);
return false;
}
-/*
-KoText::Direction TextTool::getPageDirection() const
-{
- return m_textShapeData->pageDirection();
-}
-*/
+
void TextTool::updateParagraphDirection(const QVariant &variant)
{
int position = variant.toInt();
--- trunk/koffice/plugins/textshape/TextTool.h #890973:890974
@@ -31,6 +31,9 @@
#include <QTextBlock>
#include <QTimer>
#include <QClipboard>
+#include <QUndoCommand>
+#include <QTextDocument>
+#include <QPointer>
class KAction;
class KoAction;
@@ -42,7 +45,6 @@
class InsertCharacter;
class ChangeTracker;
-class QUndoCommand;
class KFontSizeAction;
class KFontAction;
@@ -54,32 +56,6 @@
Q_OBJECT
public:
- enum EditCommands {
- InsertText=1,
- InsertParag,
- InsertNBrkSpace,
- InsertNBrkHyphen,
- InsertIndex,
- InsertSoftHyphen,
- InsertLineBreak,
- DeleteText,
- FormatBold,
- FormatItalic,
- FormatUnderline,
- FormatStrikeOut,
- FormatAlignLeft,
- FormatAlignRight,
- FormatAlignCenter,
- FormatAlignJustify,
- FormatSuperScript,
- FormatSubScript,
- FormatIndentIncrease,
- FormatIndentDecrease,
- FormatFont,
- FormatParag,
- FormatDefaultFormat
- };
-
explicit TextTool(KoCanvasBase *canvas);
~TextTool();
@@ -124,7 +100,6 @@
virtual void inputMethodEvent(QInputMethodEvent * event);
bool isBidiDocument() const;
-// KoText::Direction getPageDirection() const;
public slots:
/// start the textedit-plugin.
@@ -208,6 +183,45 @@
void blinkCaret();
private:
+
+ class UndoTextCommand : public QUndoCommand
+ {
+ public:
+ UndoTextCommand(QTextDocument *document, TextTool *tool, QUndoCommand \
*parent = 0); +
+ void undo();
+ void redo();
+
+ QPointer<QTextDocument> m_document;
+ QPointer<TextTool> m_tool;
+ };
+
+ enum EditCommands {
+ InsertText=1,
+ InsertParag,
+ InsertNBrkSpace,
+ InsertNBrkHyphen,
+ InsertIndex,
+ InsertSoftHyphen,
+ InsertLineBreak,
+ DeleteText,
+ FormatBold,
+ FormatItalic,
+ FormatUnderline,
+ FormatStrikeOut,
+ FormatAlignLeft,
+ FormatAlignRight,
+ FormatAlignCenter,
+ FormatAlignJustify,
+ FormatSuperScript,
+ FormatSubScript,
+ FormatIndentIncrease,
+ FormatIndentDecrease,
+ FormatFont,
+ FormatParag,
+ FormatDefaultFormat
+ };
+
bool pasteHelper(QClipboard::Mode mode);
void repaintCaret();
void repaintSelection();
@@ -248,18 +262,6 @@
bool m_needSpellChecking;
bool m_processingKeyPress; // all undo commands generated from key-presses \
should be combined. int m_prevCursorPosition; /// used by editingPluginEvents
-/*
- The following two int allow handling a QTextDocument undo behaviour:
- - when typing subsequent letters, the text insert commands are merged within the \
QTextDocument
- - lets say you type koffice : this is one "insert text" command within \
QTextDocument
- - now between the two f, type rocks: the result is kofrocksfice, but this secont \
typing is considered a new "insert text" command within QTextDocument
- - now undo the last typing: the text becomes koffice again
- - put the cursor back at the end of the text. any new text entered will be \
considered by QTextDocument as a new "text insert" command, even if it is joined with \
the previous text.
-
- Same applies for deletion.
-*/
- int m_commandCounter;
- int m_delCounter;
QTimer m_caretTimer;
bool m_caretTimerState;
--- trunk/koffice/plugins/textshape/commands/TextInsertParagraphCommand.cpp \
#890973:890974 @@ -31,15 +31,14 @@
#include <klocalizedstring.h>
TextInsertParagraphCommand::TextInsertParagraphCommand( TextTool *tool, QUndoCommand \
*parent )
- : QUndoCommand( i18n("New paragraph"), parent ),
+ : QUndoCommand( i18n("New paragraph"), parent ),
m_tool(tool)
{
- m_tool->flagUndoRedo( false );
- m_tool->m_caret.beginEditBlock();
-
+ m_tool->m_currentCommand = this;
+ m_tool->m_currentCommandHasChildren = true;
+
QTextBlockFormat format = m_tool->m_caret.blockFormat();
-// KoTextDocumentLayout *lay = dynamic_cast<KoTextDocumentLayout*> \
(m_document->documentLayout()); KoParagraphStyle *nextStyle = 0;
if(KoTextDocument(m_tool->m_textShapeData->document()).styleManager()) {
int id = m_tool->m_caret.blockFormat().intProperty(KoParagraphStyle::StyleId);
@@ -54,18 +53,14 @@
}
QTextList *list = m_tool->m_caret.block().textList();
-kDebug()<<"insert paragraph before insertBlock";
m_tool->m_caret.insertBlock();
-kDebug()<<"insert paragraph after insertBlock";
QTextBlockFormat bf = m_tool->m_caret.blockFormat();
bf.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
bf.clearProperty(KoParagraphStyle::ListStartValue);
bf.clearProperty(KoParagraphStyle::UnnumberedListItem);
bf.clearProperty(KoParagraphStyle::IsListHeader);
-kDebug()<<"insert paragraph before first setBlockFormat";
m_tool->m_caret.setBlockFormat(bf);
-kDebug()<<"insert paragraph after first setBlockFormat";
if (nextStyle) {
QTextBlock block = m_tool->m_caret.block();
nextStyle->applyStyle(block);
@@ -88,13 +83,10 @@
format.setProperty(KoParagraphStyle::TextProgressionDirection, dir);
} else if (! direction.isNull()) // then we inherit from the previous \
paragraph.
format.setProperty(KoParagraphStyle::TextProgressionDirection, \
direction);
-kDebug()<<"insert paragraph before second setBlockFormat";
m_tool->m_caret.setBlockFormat(format);
-kDebug()<<"insert paragraph after second setBlockFormat";
- m_tool->m_caret.endEditBlock();
- m_tool->flagUndoRedo( true );
-
+ m_tool->m_currentCommand=0;
+ m_tool->m_currentCommandHasChildren = false;
}
@@ -106,18 +98,16 @@
/// redo the command
void TextInsertParagraphCommand::redo()
{
- m_tool->flagUndoRedo( false );
- m_document->redo(m_caret);
- m_tool->flagUndoRedo( true );
-// m_tool->updateActions();
+ m_tool->flagUndoRedo( false );
+ QUndoCommand::redo();
+ m_tool->flagUndoRedo( true );
}
/// revert the actions done in redo
void TextInsertParagraphCommand::undo()
{
- m_tool->flagUndoRedo( false );
- m_document->undo(m_caret);
- m_tool->flagUndoRedo( true );
-// m_tool->updateActions();
+ m_tool->flagUndoRedo( false );
+ QUndoCommand::undo();
+ m_tool->flagUndoRedo( true );
}
--- trunk/koffice/plugins/textshape/commands/TextInsertTextCommand.cpp #890973:890974
@@ -24,24 +24,22 @@
#include "kdebug.h"
#include <klocalizedstring.h>
+
TextInsertTextCommand::TextInsertTextCommand( TextTool *tool, QString text, \
QUndoCommand *parent ) : QUndoCommand( i18n("Insert Text"), parent ),
m_text(text),
m_id(TextTool::InsertText),
m_tool(tool)
{
- m_tool->flagUndoRedo( false );
- m_tool->m_commandCounter = 0;
- m_tool->m_caret.beginEditBlock();
+ m_tool->m_currentCommand = this;
+ m_tool->m_currentCommandHasChildren = true;
m_tool->m_caret.insertText( m_text );
- m_tool->m_caret.endEditBlock();
- m_tool->flagUndoRedo( true );
+ m_tool->m_currentCommand = 0;
+ m_tool->m_currentCommandHasChildren = false;
//Save tool text counter, position and char format for comparison in MergeWith()
m_position = m_tool->m_caret.position();
m_charFormat = m_tool->m_caret.charFormat();
- m_commandCounter = m_tool->m_commandCounter;
-// kDebug()<<"textInsert: m_textCounter: "<<m_textCounter;
}
@@ -53,9 +51,7 @@
void TextInsertTextCommand::redo()
{
m_tool->flagUndoRedo( false );
- for (int i=1; i<=m_commandCounter; i++)
- m_tool->m_textShapeData->document()->redo(&(m_tool->m_caret));
-// m_tool->updateActions();
+ QUndoCommand::redo();
m_tool->flagUndoRedo( true );
}
@@ -63,9 +59,7 @@
void TextInsertTextCommand::undo()
{
m_tool->flagUndoRedo( false );
- for (int i=1; i<=m_commandCounter; i++)
- m_tool->m_textShapeData->document()->undo(&(m_tool->m_caret));
-// m_tool->updateActions();
+ QUndoCommand::undo();
m_tool->flagUndoRedo( true );
}
@@ -79,16 +73,14 @@
if (other->id() != m_id){ // make sure other is also an InsertText command
return false;
}
-
+
if ((m_position == (static_cast<const TextInsertTextCommand*>(other)->m_position \
- static_cast<const TextInsertTextCommand*>(other)->m_text.length())) \
&&
(static_cast<const TextInsertTextCommand*>(other)->m_charFormat == \
m_charFormat)) {
m_text += static_cast<const TextInsertTextCommand*>(other)->m_text;
m_position += static_cast<const \
TextInsertTextCommand*>(other)->m_text.length();
- m_commandCounter += static_cast<const \
TextInsertTextCommand*>(other)->m_commandCounter; + for (int i = 1; i <= \
other->childCount(); i++) + new TextTool::UndoTextCommand( \
m_tool->m_textShapeData->document(), m_tool, this); return true;
}
-// m_tool->m_textCounter++;
-// m_textCounter++;
-// kDebug()<<"textInsert: tool textCounter incremented: "<<m_tool->m_textCounter;
return false;
}
--- trunk/koffice/plugins/textshape/commands/TextInsertTextCommand.h #890973:890974
@@ -64,7 +64,6 @@
int m_position;
QTextCharFormat m_charFormat;
int m_id;
- int m_commandCounter; //this counter is incremented in the tool each time a text \
command is not able to merge with the previous text command. This is to avoid the \
merging of this command with subsequent text command, should the non mergeable \
command be undone. (due to QTextDocument undo/redo behaviour)
QPointer<TextTool> m_tool;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic