Warning, file /office/calligra/libs/kundo2/kundo2stack.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (c) 2014 Dmitry Kazakov <dimula73@gmail.com>
0003  *  Copyright (c) 2014 Mohit Goyal <mohit.bits2011@gmail.com>
0004  *
0005  *  This library is free software; you can redistribute it and/or modify
0006  *  it under the terms of the GNU Lesser General Public License as published by
0007  *  the Free Software Foundation; either version 2.1 of the License, or
0008  *  (at your option) any later version.
0009  *
0010  *  This library is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  *  GNU Lesser General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU Lesser General Public License
0016  *  along with this program; if not, write to the Free Software
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018  */
0019 /****************************************************************************
0020 **
0021 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
0022 ** All rights reserved.
0023 ** Contact: Nokia Corporation (qt-info@nokia.com)
0024 **
0025 ** This file is part of the QtGui module of the Qt Toolkit.
0026 **
0027 ** $QT_BEGIN_LICENSE:LGPL$
0028 ** No Commercial Usage
0029 ** This file contains pre-release code and may not be distributed.
0030 ** You may use this file in accordance with the terms and conditions
0031 ** contained in the Technology Preview License Agreement accompanying
0032 ** this package.
0033 **
0034 ** GNU Lesser General Public License Usage
0035 ** Alternatively, this file may be used under the terms of the GNU Lesser
0036 ** General Public License version 2.1 as published by the Free Software
0037 ** Foundation and appearing in the file LICENSE.LGPL included in the
0038 ** packaging of this file.  Please review the following information to
0039 ** ensure the GNU Lesser General Public License version 2.1 requirements
0040 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
0041 **
0042 ** In addition, as a special exception, Nokia gives you certain additional
0043 ** rights.  These rights are described in the Nokia Qt LGPL Exception
0044 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
0045 **
0046 ** If you have questions regarding the use of this file, please contact
0047 ** Nokia at qt-info@nokia.com.
0048 **
0049 **
0050 **
0051 **
0052 **
0053 **
0054 **
0055 **
0056 ** $QT_END_LICENSE$
0057 **
0058 ****************************************************************************/
0059 
0060 #ifndef KUNDO2STACK_H
0061 #define KUNDO2STACK_H
0062 
0063 #include <QObject>
0064 #include <QString>
0065 #include <QList>
0066 #include <QAction>
0067 #include <QTime>
0068 #include <QVector>
0069 
0070 
0071 #include "kundo2_export.h"
0072 
0073 class QAction;
0074 class KUndo2CommandPrivate;
0075 class KUndo2Group;
0076 class KActionCollection;
0077 
0078 #ifndef QT_NO_UNDOCOMMAND
0079 
0080 #include "kundo2magicstring.h"
0081 #include "kundo2commandextradata.h"
0082 
0083 
0084 class KUNDO2_EXPORT KUndo2Command
0085 {
0086     KUndo2CommandPrivate *d;
0087     int timedID;
0088 
0089 public:
0090     explicit KUndo2Command(KUndo2Command *parent = 0);
0091     explicit KUndo2Command(const KUndo2MagicString &text, KUndo2Command *parent = 0);
0092     virtual ~KUndo2Command();
0093 
0094     virtual void undo();
0095     virtual void redo();
0096 
0097     QString actionText() const;
0098     KUndo2MagicString text() const;
0099     void setText(const KUndo2MagicString &text);
0100 
0101     virtual int id() const;
0102     virtual int timedId();
0103     virtual void setTimedID(int timedID);
0104     virtual bool mergeWith(const KUndo2Command *other);
0105     virtual bool timedMergeWith(KUndo2Command *other);
0106 
0107     int childCount() const;
0108     const KUndo2Command *child(int index) const;
0109 
0110     bool hasParent();
0111     virtual void setTime();
0112     virtual QTime time();
0113     virtual void setEndTime();
0114     virtual QTime endTime();
0115 
0116     virtual QVector<KUndo2Command*> mergeCommandsVector();
0117     virtual bool isMerged();
0118     virtual void undoMergedCommands();
0119     virtual void redoMergedCommands();
0120 
0121     /**
0122      * \return user-defined object associated with the command
0123      *
0124      * \see setExtraData()
0125      */
0126     KUndo2CommandExtraData* extraData() const;
0127 
0128     /**
0129      * The user can assign an arbitrary object associated with the
0130      * command. The \p data object is owned by the command. If you assign
0131      * the object twice, the first one will be destroyed.
0132      */
0133     void setExtraData(KUndo2CommandExtraData *data);
0134 
0135     /**
0136      * Add the @p command as a child to this command
0137      */
0138     void addCommand(KUndo2Command *command);
0139 
0140 private:
0141     Q_DISABLE_COPY(KUndo2Command)
0142     friend class KUndo2QStack;
0143 
0144 
0145     bool m_hasParent;
0146     int m_timedID;
0147 
0148     QTime m_timeOfCreation;
0149     QTime m_endOfCommand;
0150     QVector<KUndo2Command*> m_mergeCommandsVector;
0151 };
0152 
0153 #endif // QT_NO_UNDOCOMMAND
0154 
0155 #ifndef QT_NO_UNDOSTACK
0156 
0157 class KUNDO2_EXPORT KUndo2QStack : public QObject
0158 {
0159     Q_OBJECT
0160 //    Q_DECLARE_PRIVATE(KUndo2QStack)
0161     Q_PROPERTY(bool active READ isActive WRITE setActive)
0162     Q_PROPERTY(int undoLimit READ undoLimit WRITE setUndoLimit)
0163 
0164 public:
0165     explicit KUndo2QStack(QObject *parent = 0);
0166     ~KUndo2QStack() override;
0167     void clear();
0168 
0169     bool push(KUndo2Command *cmd);
0170 
0171     bool canUndo() const;
0172     bool canRedo() const;
0173     QString undoText() const;
0174     QString redoText() const;
0175 
0176     int count() const;
0177     int index() const;
0178     QString actionText(int idx) const;
0179     QString text(int idx) const;
0180 
0181 #ifndef QT_NO_ACTION
0182     QAction *createUndoAction(QObject *parent) const;
0183     QAction *createRedoAction(QObject *parent) const;
0184 #endif // QT_NO_ACTION
0185 
0186     bool isActive() const;
0187     bool isClean() const;
0188     int cleanIndex() const;
0189 
0190     void beginMacro(const KUndo2MagicString &text);
0191     void endMacro();
0192 
0193     void setUndoLimit(int limit);
0194     int undoLimit() const;
0195 
0196     const KUndo2Command *command(int index) const;
0197 
0198     void setUseCumulativeUndoRedo(bool value);
0199     bool useCumulativeUndoRedo();
0200     void setTimeT1(double value);
0201     double timeT1();
0202     void setTimeT2(double value);
0203     double timeT2();
0204     int strokesN();
0205     void setStrokesN(int value);
0206 
0207 
0208 public Q_SLOTS:
0209     void setClean();
0210     virtual void setIndex(int idx);
0211     virtual void undo();
0212     virtual void redo();
0213     void setActive(bool active = true);
0214 
0215     void purgeRedoState();
0216 
0217 Q_SIGNALS:
0218     void indexChanged(int idx);
0219     void cleanChanged(bool clean);
0220     void canUndoChanged(bool canUndo);
0221     void canRedoChanged(bool canRedo);
0222     void undoTextChanged(const QString &undoActionText);
0223     void redoTextChanged(const QString &redoActionText);
0224 
0225 protected:
0226     virtual void notifySetIndexChangedOneCommand();
0227 
0228 private:
0229     // from QUndoStackPrivate
0230     QList<KUndo2Command*> m_command_list;
0231     QList<KUndo2Command*> m_macro_stack;
0232     int m_index;
0233     int m_clean_index;
0234     KUndo2Group *m_group;
0235     int m_undo_limit;
0236     bool m_useCumulativeUndoRedo;
0237     double m_timeT1;
0238     double m_timeT2;
0239     int m_strokesN;
0240     int m_lastMergedSetCount;
0241     int m_lastMergedIndex;
0242 
0243     // also from QUndoStackPrivate
0244     void setIndex(int idx, bool clean);
0245     bool checkUndoLimit();
0246 
0247     Q_DISABLE_COPY(KUndo2QStack)
0248     friend class KUndo2Group;
0249 };
0250 
0251 class KUNDO2_EXPORT KUndo2Stack : public KUndo2QStack
0252 {
0253 Q_OBJECT
0254 public:
0255     explicit KUndo2Stack(QObject *parent = 0);
0256 
0257     // functions from KUndoStack
0258     QAction* createRedoAction(KActionCollection* actionCollection, const QString& actionName = QString());
0259     QAction* createUndoAction(KActionCollection* actionCollection, const QString& actionName = QString());
0260 };
0261 
0262 #endif // QT_NO_UNDOSTACK
0263 
0264 #endif // KUNDO2STACK_H