QtSpell  0.8.2
Spell checking for Qt text widgets
/usr/src/RPM/BUILD/qtspell-0.8.2/src/UndoRedoStack.hpp
00001 /* QtSpell - Spell checking for Qt text widgets.
00002  * Copyright (c) 2014 Sandro Mani
00003  *
00004  *    This program is free software; you can redistribute it and/or modify
00005  *    it under the terms of the GNU General Public License as published by
00006  *    the Free Software Foundation; either version 2 of the License, or
00007  *    (at your option) any later version.
00008  *
00009  *    This program is distributed in the hope that it will be useful,
00010  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *    GNU General Public License for more details.
00013  *
00014  *    You should have received a copy of the GNU General Public License along
00015  *    with this program; if not, write to the Free Software Foundation, Inc.,
00016  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #ifndef QTSPELL_UNDOREDOSTACK_HPP
00020 #define QTSPELL_UNDOREDOSTACK_HPP
00021 
00022 #include <QObject>
00023 #include <QStack>
00024 
00025 
00026 namespace QtSpell {
00027 
00028 class TextEditProxy;
00029 
00030 class UndoRedoStack : public QObject
00031 {
00032         Q_OBJECT
00033 public:
00034         UndoRedoStack(TextEditProxy* textEdit);
00035         void handleContentsChange(int pos, int removed, int added);
00036         void clear();
00037 
00038 public slots:
00039         void undo();
00040         void redo();
00041 
00042 signals:
00043         void undoAvailable(bool);
00044         void redoAvailable(bool);
00045 
00046 private:
00047         struct Action;
00048         struct UndoableInsert;
00049         struct UndoableDelete;
00050 
00051         bool m_actionInProgress;
00052         TextEditProxy* m_textEdit;
00053         QStack<Action*> m_undoStack;
00054         QStack<Action*> m_redoStack;
00055 
00056         bool insertMergeable(const UndoableInsert* prev, const UndoableInsert* cur) const;
00057         bool deleteMergeable(const UndoableDelete* prev, const UndoableDelete* cur) const;
00058 };
00059 
00060 } // QtSpell
00061 
00062 #endif // QTSPELL_UNDOREDOSTACK_HPP