[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:30
Message-ID: 1228072050.293115.22072.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 890973 by pstirnweiss:

Trials for undo/redo

 M  +3 -0      CMakeLists.txt  
 M  +25 -22    TextTool.cpp  
 M  +46 -1     TextTool.h  
 A             commands/TextInsertParagraphCommand.cpp   [License: LGPL (v2+)]
 A             commands/TextInsertParagraphCommand.h   [License: LGPL (v2+)]
 A             commands/TextInsertTextCommand.cpp   [License: LGPL (v2+)]
 A             commands/TextInsertTextCommand.h   [License: LGPL (v2+)]


--- trunk/koffice/plugins/textshape/CMakeLists.txt #890972:890973
@@ -48,6 +48,9 @@
     commands/ChangeListLevelCommand.cpp
     commands/ListItemNumberingCommand.cpp
     commands/TextCommandBase.cpp
+    
+    commands/TextInsertTextCommand.cpp
+    commands/TextInsertParagraphCommand.cpp
 )
 
 kde4_add_ui_files(textshape_SRCS
--- trunk/koffice/plugins/textshape/TextTool.cpp #890972:890973
@@ -32,6 +32,9 @@
 #include "commands/ChangeListLevelCommand.h"
 #include "commands/ListItemNumberingCommand.h"
 
+#include "commands/TextInsertTextCommand.h"
+#include "commands/TextInsertParagraphCommand.h"
+
 #include <KoAction.h>
 #include <KoExecutePolicy.h>
 #include <KoCanvasBase.h>
@@ -439,6 +442,12 @@
     qDeleteAll(m_textEditingPlugins);
 }
 
+void TextTool::flagUndoRedo( bool flag )
+{
+	m_allowAddUndoCommand = flag;
+	m_allowActions = flag;
+}
+
 void TextTool::blinkCaret()
 {
     m_caretTimerState = !m_caretTimerState;
@@ -876,38 +885,25 @@
             event->ignore();
             return;
         } else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) \
                {
-            startKeyPressMacro();
+//            startKeyPressMacro();
             if (m_caret.hasSelection())
                 m_selectionHandler.deleteInlineObjects();
-            QTextBlockFormat format = m_caret.blockFormat();
-            m_selectionHandler.nextParagraph();
 
-            QVariant direction = \
                format.property(KoParagraphStyle::TextProgressionDirection);
-            format = m_caret.blockFormat();
-            if (m_textShapeData->pageDirection() != KoText::AutoDirection) { // \
                inherit from shape
-                KoText::Direction dir;
-                switch (m_textShapeData->pageDirection()) {
-                case KoText::RightLeftTopBottom:
-                    dir = KoText::PerhapsRightLeftTopBottom;
-                    break;
-                case KoText::LeftRightTopBottom:
-                default:
-                    dir = KoText::PerhapsLeftRightTopBottom;
-                }
-                format.setProperty(KoParagraphStyle::TextProgressionDirection, dir);
-            } else if (! direction.isNull()) // then we inherit from the previous \
                paragraph.
-                format.setProperty(KoParagraphStyle::TextProgressionDirection, \
                direction);
-            m_caret.setBlockFormat(format);
+//            m_selectionHandler.nextParagraph();
+  m_canvas->addCommand(new TextInsertParagraphCommand(this));
+
+
             updateActions();
             editingPluginEvents();
             ensureCursorVisible();
         } else if (event->key() == Qt::Key_Tab || !(event->text().length() == 1 && \
                !event->text().at(0).isPrint())) { // insert the text
-            startKeyPressMacro();
+//            startKeyPressMacro();
             if (m_caret.hasSelection())
                 m_selectionHandler.deleteInlineObjects();
             m_prevCursorPosition = m_caret.position();
             ensureCursorVisible();
-            m_caret.insertText(event->text());
+    m_canvas->addCommand(new TextInsertTextCommand( this, event->text() ));
+//            m_caret.insertText(event->text());
             if (m_textShapeData->pageDirection() == KoText::AutoDirection)
                 m_updateParagDirection.action->execute(m_prevCursorPosition);
             editingPluginEvents();
@@ -1281,6 +1277,8 @@
 
 void TextTool::addUndoCommand()
 {
+//kDebug()<<"in slot add undoCommand";
+m_commandCounter++;
     if (! m_allowAddUndoCommand) return;
     class UndoTextCommand : public QUndoCommand
     {
@@ -1535,7 +1533,12 @@
         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 #890972:890973
@@ -53,6 +53,33 @@
 {
     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();
 
@@ -97,7 +124,8 @@
     virtual void inputMethodEvent(QInputMethodEvent * event);
 
     bool isBidiDocument() const;
-
+//    KoText::Direction getPageDirection() const;
+    
 public slots:
     /// start the textedit-plugin.
     void startTextEditingPlugin(const QString &pluginId);
@@ -189,6 +217,7 @@
     int pointToPosition(const QPointF & point) const;
     void updateSelectionHandler();
     void updateActions();
+
     void updateStyleManager();
     void setShapeData(KoTextShapeData *data);
     void updateSelectedShape(const QPointF &point);
@@ -198,11 +227,15 @@
     void finishedParagraph();
 
     void startKeyPressMacro();
+    
+    void flagUndoRedo( bool flag );
 
 private:
     friend class UndoTextCommand;
     friend class TextCommandBase;
     friend class ChangeTracker;
+    friend class TextInsertTextCommand;
+    friend class TextInsertParagraphCommand;
     TextShape *m_textShape;
     KoTextShapeData *m_textShapeData;
     QTextCursor m_caret;
@@ -215,6 +248,18 @@
     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;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic