Browse Source

Move text element

Kandrashin Denis 13 years ago
parent
commit
44029049f3
3 changed files with 41 additions and 2 deletions
  1. 25 0
      source/fb2html.cpp
  2. 11 0
      source/fb2html.h
  3. 5 2
      source/fb2tree.cpp

+ 25 - 0
source/fb2html.cpp

@@ -174,6 +174,31 @@ void Fb2SubtitleCmd::undo()
     m_page.update();
     m_page.update();
 }
 }
 
 
+//---------------------------------------------------------------------------
+//  Fb2MoveUpCmd
+//---------------------------------------------------------------------------
+
+Fb2MoveUpCmd::Fb2MoveUpCmd(Fb2TextPage &page, const Fb2TextElement &element, Fb2UndoCommand *parent)
+    : Fb2UndoCommand(parent)
+    , m_page(page)
+    , m_element(element)
+{
+}
+
+void Fb2MoveUpCmd::redo()
+{
+    Fb2TextElement subling = m_element.previousSibling();
+    subling.prependOutside(m_element.takeFromDocument());
+    m_page.update();
+}
+
+void Fb2MoveUpCmd::undo()
+{
+    Fb2TextElement subling = m_element.nextSibling();
+    subling.appendOutside(m_element.takeFromDocument());
+    m_page.update();
+}
+
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 //  Fb2DeleteCmd
 //  Fb2DeleteCmd
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------

+ 11 - 0
source/fb2html.h

@@ -96,6 +96,17 @@ private:
     QString m_position;
     QString m_position;
 };
 };
 
 
+class Fb2MoveUpCmd : public Fb2UndoCommand
+{
+public:
+    explicit Fb2MoveUpCmd(Fb2TextPage &page, const Fb2TextElement &element, Fb2UndoCommand *parent = 0);
+    virtual void undo();
+    virtual void redo();
+private:
+    Fb2TextPage & m_page;
+    Fb2TextElement m_element;
+};
+
 class Fb2DeleteCmd : public Fb2UndoCommand
 class Fb2DeleteCmd : public Fb2UndoCommand
 {
 {
 public:
 public:

+ 5 - 2
source/fb2tree.cpp

@@ -281,9 +281,12 @@ QModelIndex Fb2TreeModel::move(const QModelIndex &index, int dx, int dy)
             beginMoveRows(parent, from, from, parent, to);
             beginMoveRows(parent, from, from, parent, to);
             brother = owner->takeAt(from);
             brother = owner->takeAt(from);
             owner->insert(brother, to);
             owner->insert(brother, to);
-            QWebElement element = child->element().takeFromDocument();
-            brother->element().appendOutside(element);
             endMoveRows();
             endMoveRows();
+
+            Fb2TextPage & page = *m_view.page();
+            page.undoStack()->beginMacro("Move element");
+            page.undoStack()->push(new Fb2MoveUpCmd(page, brother->element()));
+            page.undoStack()->endMacro();
         } break;
         } break;
     }
     }
     return result;
     return result;