Commit 76fc48a7 authored by Alexander Potashev's avatar Alexander Potashev

Add libkundo2 to Calligra

kundo2 is a fork of Qt's Undo Framework (QUndoStack, QUndoView, ...).
It contains two bugfixes the are going to be available only in Qt 4.8:
	https://qt.gitorious.org/qt/qt/merge_requests/1212
	https://qt.gitorious.org/qt/qt/merge_requests/2610

To start using kundo2, one should port Calligra to it. This can be done
by adding target_link_libraries(... kundo2) into CMakeLists.txt files
for all modules from Calligra that use Qt Undo Framework, and by
switching from QUndo**** classes to KUndo2**** classes.
(switching to KUndo2 classes can easily be done by using a script)

After Calligra starts requiring Qt 4.8+, this library can be removed,
because it has no advantages over Qt's Undo Framework 4.8.
parent cb253a73
......@@ -6,6 +6,7 @@ add_subdirectory( kotext )
add_subdirectory( flake )
add_subdirectory( pigment )
add_subdirectory( main )
add_subdirectory( kundo2 )
if (SHOULD_BUILD_SCRIPTING)
add_subdirectory( kokross )
endif (SHOULD_BUILD_SCRIPTING)
......
include_directories( ${QT_INCLUDES} )
set(kundo2_LIB_SRCS
kundo2stack.cpp
kundo2group.cpp
kundo2view.cpp
kundo2model.cpp
)
kde4_add_library(kundo2 SHARED ${kundo2_LIB_SRCS})
target_link_libraries(kundo2 ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS})
set_target_properties(koplugin PROPERTIES
VERSION ${GENERIC_KOFFICE_LIB_VERSION} SOVERSION ${GENERIC_KOFFICE_LIB_SOVERSION}
)
install(TARGETS kundo2 ${INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES
kundo2stack.h
kundo2qstack.h
kundo2group.h
kundo2view.h
kundo2model.h
kundo2command.h
DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
)
/* This file is part of the KDE project
Copyright (C) 2007 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KUNDO2_EXPORT_H
#define KUNDO2_EXPORT_H
/* needed for KDE_EXPORT and KDE_IMPORT macros */
#include <kdemacros.h>
#ifndef KUNDO2_EXPORT
# if defined(KDELIBS_STATIC_LIBS)
/* No export/import for static libraries */
# define KUNDO2_EXPORT
# elif defined(MAKE_KUNDO2_LIB)
/* We are building this library */
# define KUNDO2_EXPORT KDE_EXPORT
# else
/* We are using this library */
# define KUNDO2_EXPORT KDE_IMPORT
# endif
#endif
# ifndef KUNDO2_EXPORT_DEPRECATED
# define KUNDO2_EXPORT_DEPRECATED KDE_DEPRECATED KUNDO2_EXPORT
# endif
#endif
#include <kundo2stack.h>
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef KUNDO2GROUP_H
#define KUNDO2GROUP_H
#include <QtCore/qobject.h>
#include <QtCore/qstring.h>
#include "kundo2_export.h"
class KUndo2GroupPrivate;
class KUndo2QStack;
class QAction;
#ifndef QT_NO_UNDOGROUP
class KUNDO2_EXPORT KUndo2Group : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(KUndo2Group)
public:
explicit KUndo2Group(QObject *parent = 0);
~KUndo2Group();
void addStack(KUndo2QStack *stack);
void removeStack(KUndo2QStack *stack);
QList<KUndo2QStack*> stacks() const;
KUndo2QStack *activeStack() const;
#ifndef QT_NO_ACTION
QAction *createUndoAction(QObject *parent) const;
QAction *createRedoAction(QObject *parent) const;
#endif // QT_NO_ACTION
bool canUndo() const;
bool canRedo() const;
QString undoText() const;
QString redoText() const;
bool isClean() const;
public Q_SLOTS:
void undo();
void redo();
void setActiveStack(KUndo2QStack *stack);
Q_SIGNALS:
void activeStackChanged(KUndo2QStack *stack);
void indexChanged(int idx);
void cleanChanged(bool clean);
void canUndoChanged(bool canUndo);
void canRedoChanged(bool canRedo);
void undoTextChanged(const QString &undoActionText);
void redoTextChanged(const QString &redoActionText);
private:
// from QUndoGroupPrivate
KUndo2QStack *m_active;
QList<KUndo2QStack*> m_stack_list;
Q_DISABLE_COPY(KUndo2Group)
};
#endif // QT_NO_UNDOGROUP
#endif // KUNDO2GROUP_H
/* This file is part of the KDE project
* Copyright (C) 2010 Matus Talcik <matus.talcik@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "kundo2model.h"
KUndo2Model::KUndo2Model(QObject *parent)
: QAbstractItemModel(parent)
{
m_stack = 0;
m_sel_model = new QItemSelectionModel(this, this);
connect(m_sel_model, SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(setStackCurrentIndex(QModelIndex)));
m_emty_label = tr("<empty>");
}
QItemSelectionModel *KUndo2Model::selectionModel() const
{
return m_sel_model;
}
KUndo2QStack *KUndo2Model::stack() const
{
return m_stack;
}
void KUndo2Model::setStack(KUndo2QStack *stack)
{
if (m_stack == stack)
return;
if (m_stack != 0) {
disconnect(m_stack, SIGNAL(cleanChanged(bool)), this, SLOT(stackChanged()));
disconnect(m_stack, SIGNAL(indexChanged(int)), this, SLOT(stackChanged()));
disconnect(m_stack, SIGNAL(destroyed(QObject*)), this, SLOT(stackDestroyed(QObject*)));
disconnect(m_stack, SIGNAL(indexChanged(int)), this, SLOT(addImage(int)));
}
m_stack = stack;
if (m_stack != 0) {
connect(m_stack, SIGNAL(cleanChanged(bool)), this, SLOT(stackChanged()));
connect(m_stack, SIGNAL(indexChanged(int)), this, SLOT(stackChanged()));
connect(m_stack, SIGNAL(destroyed(QObject*)), this, SLOT(stackDestroyed(QObject*)));
connect(m_stack, SIGNAL(indexChanged(int)), this, SLOT(addImage(int)));
}
stackChanged();
}
void KUndo2Model::stackDestroyed(QObject *obj)
{
if (obj != m_stack)
return;
m_stack = 0;
stackChanged();
}
void KUndo2Model::stackChanged()
{
reset();
m_sel_model->setCurrentIndex(selectedIndex(), QItemSelectionModel::ClearAndSelect);
}
void KUndo2Model::setStackCurrentIndex(const QModelIndex &index)
{
if (m_stack == 0)
return;
if (index == selectedIndex())
return;
if (index.column() != 0)
return;
m_stack->setIndex(index.row());
}
QModelIndex KUndo2Model::selectedIndex() const
{
return m_stack == 0 ? QModelIndex() : createIndex(m_stack->index(), 0);
}
QModelIndex KUndo2Model::index(int row, int column, const QModelIndex &parent) const
{
if (m_stack == 0)
return QModelIndex();
if (parent.isValid())
return QModelIndex();
if (column != 0)
return QModelIndex();
if (row < 0 || row > m_stack->count())
return QModelIndex();
return createIndex(row, column);
}
QModelIndex KUndo2Model::parent(const QModelIndex&) const
{
return QModelIndex();
}
int KUndo2Model::rowCount(const QModelIndex &parent) const
{
if (m_stack == 0)
return 0;
if (parent.isValid())
return 0;
return m_stack->count() + 1;
}
int KUndo2Model::columnCount(const QModelIndex&) const
{
return 1;
}
QVariant KUndo2Model::data(const QModelIndex &index, int role) const
{
if (m_stack == 0)
return QVariant();
if (index.column() != 0)
return QVariant();
if (index.row() < 0 || index.row() > m_stack->count())
return QVariant();
if (role == Qt::DisplayRole) {
if (index.row() == 0)
return m_emty_label;
return m_stack->text(index.row() - 1);
} else if (role == Qt::DecorationRole) {
if (index.row() == m_stack->cleanIndex() && !m_clean_icon.isNull())
return m_clean_icon;
}
return QVariant();
}
QString KUndo2Model::emptyLabel() const
{
return m_emty_label;
}
void KUndo2Model::setEmptyLabel(const QString &label)
{
m_emty_label = label;
stackChanged();
}
void KUndo2Model::setCleanIcon(const QIcon &icon)
{
m_clean_icon = icon;
stackChanged();
}
QIcon KUndo2Model::cleanIcon() const
{
return m_clean_icon;
}
/* This file is part of the KDE project
* Copyright (C) 2010 Matus Talcik <matus.talcik@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QAbstractItemModel>
#include "kundo2stack.h"
#include <QItemSelectionModel>
#include <QIcon>
class KUndo2Model : public QAbstractItemModel
{
Q_OBJECT
public:
KUndo2Model(QObject *parent = 0);
KUndo2QStack *stack() const;
virtual QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex &child) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex selectedIndex() const;
QItemSelectionModel *selectionModel() const;
QString emptyLabel() const;
void setEmptyLabel(const QString &label);
void setCleanIcon(const QIcon &icon);
QIcon cleanIcon() const;
public slots:
void setStack(KUndo2QStack *stack);
private slots:
void stackChanged();
void stackDestroyed(QObject *obj);
void setStackCurrentIndex(const QModelIndex &index);
private:
KUndo2QStack *m_stack;
QItemSelectionModel *m_sel_model;
QString m_emty_label;
QIcon m_clean_icon;
};
#include <kundo2stack.h>
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef KUNDO2STACK_H
#define KUNDO2STACK_H
#include <QtCore/qobject.h>
#include <QtCore/qstring.h>
#include <QtCore/qlist.h>
#include <QtGui/qaction.h>
#include "kundo2_export.h"
class QAction;
class KUndo2CommandPrivate;
class KUndo2Group;
class KActionCollection;
#ifndef QT_NO_UNDOCOMMAND
class KUNDO2_EXPORT KUndo2Command
{
KUndo2CommandPrivate *d;
public:
explicit KUndo2Command(KUndo2Command *parent = 0);
explicit KUndo2Command(const QString &text, KUndo2Command *parent = 0);
virtual ~KUndo2Command();
virtual void undo();
virtual void redo();
QString actionText() const;
QString text() const;
void setText(const QString &text);
virtual int id() const;
virtual bool mergeWith(const KUndo2Command *other);
int childCount() const;
const KUndo2Command *child(int index) const;
private:
Q_DISABLE_COPY(KUndo2Command)
friend class KUndo2QStack;
};
#endif // QT_NO_UNDOCOMMAND
#ifndef QT_NO_UNDOSTACK
class KUNDO2_EXPORT KUndo2QStack : public QObject
{
Q_OBJECT
// Q_DECLARE_PRIVATE(KUndo2QStack)
Q_PROPERTY(bool active READ isActive WRITE setActive)
Q_PROPERTY(int undoLimit READ undoLimit WRITE setUndoLimit)
public:
explicit KUndo2QStack(QObject *parent = 0);
~KUndo2QStack();
void clear();
void push(KUndo2Command *cmd);
bool canUndo() const;
bool canRedo() const;
QString undoText() const;
QString redoText() const;
int count() const;
int index() const;
QString actionText(int idx) const;
QString text(int idx) const;
#ifndef QT_NO_ACTION
QAction *createUndoAction(QObject *parent) const;
QAction *createRedoAction(QObject *parent) const;
#endif // QT_NO_ACTION
bool isActive() const;
bool isClean() const;
int cleanIndex() const;
void beginMacro(const QString &text);
void endMacro();
void setUndoLimit(int limit);
int undoLimit() const;
const KUndo2Command *command(int index) const;
// functions from KUndoStack
QAction* createRedoAction(KActionCollection* actionCollection, const QString& actionName = QString());
QAction* createUndoAction(KActionCollection* actionCollection, const QString& actionName = QString());
public Q_SLOTS:
void setClean();
void setIndex(int idx);
void undo();
void redo();
void setActive(bool active = true);
Q_SIGNALS:
void indexChanged(int idx);
void cleanChanged(bool clean);
void canUndoChanged(bool canUndo);
void canRedoChanged(bool canRedo);
void undoTextChanged(const QString &undoActionText);
void redoTextChanged(const QString &redoActionText);
private:
// from QUndoStackPrivate
QList<KUndo2Command*> m_command_list;
QList<KUndo2Command*> m_macro_stack;
int m_index;
int m_clean_index;
KUndo2Group *m_group;
int m_undo_limit;
// also from QUndoStackPrivate
void setIndex(int idx, bool clean);
bool checkUndoLimit();
Q_DISABLE_COPY(KUndo2QStack)
friend class KUndo2Group;
};
// HACK!!! (inheritance in the wrong direction)
// Cross your fingers that nobody feels the difference ;)
class KUNDO2_EXPORT KUndo2Stack : public KUndo2QStack
{
public:
explicit KUndo2Stack(QObject *parent = 0);
};
#endif // QT_NO_UNDOSTACK
#endif // KUNDO2STACK_H
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef KUNDO2STACK_P_H
#define KUNDO2STACK_P_H
#include <QtCore/qlist.h>
#include <QtCore/qstring.h>
#include <QtGui/qaction.h>
#include "kundo2stack.h"
class KUndo2Command;
class KUndo2Group;
//
// W A R N I N G