File indexing completed on 2024-05-12 16:36:47
0001 /* This file is part of the KDE project 0002 * Copyright ( C ) 2007 Thorsten Zachmann <zachmann@kde.org> 0003 * Copyright ( C ) 2010 Benjamin Port <port.benjamin@gmail.com> 0004 * Copyright ( C ) 2012 Paul Mendez <paulestebanms@gmail.com> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or ( at your option ) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #ifndef KPRSHAPEANIMATIONS_H 0023 #define KPRSHAPEANIMATIONS_H 0024 0025 #include <QList> 0026 #include <QAbstractTableModel> 0027 #include "animations/KPrShapeAnimation.h" 0028 #include "animations/KPrAnimationStep.h" 0029 0030 #include "stage_export.h" 0031 0032 class KPrDocument; 0033 0034 /** 0035 * Model for Animations data of each KPrPage 0036 */ 0037 class STAGE_EXPORT KPrShapeAnimations : public QAbstractTableModel 0038 { 0039 Q_OBJECT 0040 public: 0041 0042 /// Time to be updated 0043 enum TimeUpdated { 0044 BeginTime, 0045 DurationTime, 0046 BothTimes 0047 }; 0048 0049 /// column names 0050 enum ColumnNames { 0051 Group, 0052 StepCount, 0053 TriggerEvent, 0054 Name, 0055 ShapeThumbnail, 0056 AnimationIcon, 0057 StartTime, 0058 Duration, 0059 AnimationClass, 0060 NodeType 0061 }; 0062 0063 explicit KPrShapeAnimations(KPrDocument *document, QObject *parent = 0); 0064 ~KPrShapeAnimations() override; 0065 0066 /// Model Methods 0067 Qt::ItemFlags flags(const QModelIndex &index) const override; 0068 QVariant data(const QModelIndex &index, 0069 int role=Qt::DisplayRole) const override; 0070 QVariant headerData(int section, Qt::Orientation orientation, 0071 int role=Qt::DisplayRole) const override; 0072 int rowCount(const QModelIndex &parent=QModelIndex()) const override; 0073 int columnCount(const QModelIndex &parent=QModelIndex()) const override; 0074 bool setHeaderData(int, Qt::Orientation, const QVariant&, 0075 int=Qt::EditRole) override {return false;} 0076 bool setData(const QModelIndex &index, const QVariant &value, 0077 int role=Qt::EditRole) override; 0078 0079 0080 0081 void init(const QList<KPrAnimationStep *> &animations); 0082 /** 0083 * Add animation to the animations 0084 * 0085 * It the animation for this shape/step already exists it is replaced by the given one 0086 * 0087 * @param animation the animation to insert 0088 */ 0089 void add(KPrShapeAnimation *animation); 0090 0091 /** 0092 * Remove animation to the animations 0093 * 0094 * @param animation the animation to remove 0095 */ 0096 void remove(KPrShapeAnimation *animation); 0097 0098 /** 0099 * @brief Insert a new step on the steps list 0100 * 0101 * @param i position in which the step will be inserted 0102 * @param step step to be inserted 0103 */ 0104 void insertStep(const int i, KPrAnimationStep *step); 0105 0106 /** 0107 * @brief Remove a step on the steps list 0108 * 0109 * @param step step to be removed 0110 */ 0111 void removeStep(KPrAnimationStep *step); 0112 0113 /** 0114 * @brief Swap steps in positions i and j 0115 * 0116 * @param i position of the first step 0117 * @param j position of the second step 0118 */ 0119 void swapSteps(int i, int j); 0120 0121 void swapAnimations(KPrShapeAnimation *oldAnimation, KPrShapeAnimation *newAnimation); 0122 0123 /** 0124 * @brief Replace old animation with new animation 0125 * 0126 * @param oldAnimation animation to be replaced 0127 * @param newAnimation 0128 */ 0129 void replaceAnimation(KPrShapeAnimation *oldAnimation, KPrShapeAnimation *newAnimation); 0130 0131 0132 /** 0133 * Get the animations for the given step 0134 * 0135 * @param step the step for which the animations should be returned 0136 * @return A map of the shape -> animation if the animation is 0 the shape 0137 * is not visible 0138 */ 0139 /* QMap<KoShape *, KPrShapeAnimation *> animations( int step ) const; 0140 */ 0141 /** 0142 * Get all steps 0143 */ 0144 QList<KPrAnimationStep *> steps() const; 0145 0146 /// Save a edit command 0147 void endTimeLineEdition(); 0148 0149 /** 0150 * @brief Set animation begin and duration 0151 * 0152 * @param item the animation 0153 * @param begin time in milliseconds 0154 * @param duration time in milliseconds 0155 */ 0156 void setTimeRange(KPrShapeAnimation *item, const int begin, const int duration); 0157 0158 /** 0159 * Get the end time for the given animation 0160 * 0161 * @param index of the animation 0162 * @return the time in milliseconds of the animation end 0163 */ 0164 int animationEnd(const QModelIndex &index) const; 0165 0166 /** 0167 * Get the scale begin time for the given animation 0168 * 0169 * @param index of the animation 0170 * @return the time in milliseconds where the scale begin (relative to the parent onclik animation) 0171 */ 0172 int animationStart(const QModelIndex &index) const; 0173 0174 /** 0175 * @brief Replace animation in the given index 0176 * 0177 * @param index index of the animation 0178 * @param newAnimation animation to be used to replace 0179 */ 0180 QModelIndex replaceAnimation(const QModelIndex &index, KPrShapeAnimation *newAnimation); 0181 0182 /** 0183 * @brief Create command to change trigger event of the animation on index 0184 * 0185 * @param index index of the animation 0186 * @param type new Node Type for the animation 0187 */ 0188 bool setTriggerEvent(const QModelIndex &index, const KPrShapeAnimation::NodeType type); 0189 0190 /** 0191 * @brief Change trigger event of the animation 0192 * 0193 * @param animation 0194 * @param type new Node Type for the animation 0195 */ 0196 bool setNodeType(KPrShapeAnimation *animation, const KPrShapeAnimation::NodeType type); 0197 0198 /** 0199 * @brief Redefine start of the animation if is moved below the minimum limit 0200 * of its animation trigger event scale. 0201 * 0202 * @param mIndex index of the animation 0203 */ 0204 void recalculateStart(const QModelIndex &mIndex); 0205 0206 /** 0207 * @brief Move animation up in the animation list 0208 * Redefine trigger event if it's necessary 0209 * 0210 * @param index of the animation 0211 */ 0212 QModelIndex moveUp(const QModelIndex &index); 0213 0214 /** 0215 * @brief Move animation down in the animation list 0216 * Redefine trigger event if it's necessary 0217 * 0218 * @param index of the animation 0219 */ 0220 QModelIndex moveDown(const QModelIndex &index); 0221 0222 /** 0223 * @brief Move animation from @p oldRow to @p newRow 0224 * Redefine trigger event if it's necessary 0225 * 0226 * @param oldRow the old index of the animation 0227 * @param newRow the new index of the animation 0228 */ 0229 QModelIndex moveAnimation(int oldRow, int newRow); 0230 0231 /** 0232 * @brief remove animation on index 0233 * 0234 * @param index of the animation to be removed 0235 */ 0236 QModelIndex removeAnimationByIndex(const QModelIndex &index); 0237 0238 /** 0239 * @brief Return the shape of the animation on given index 0240 * 0241 * @param index of the animation 0242 */ 0243 KoShape *shapeByIndex(const QModelIndex &index) const; 0244 0245 /// Return the first animation index for the given shape 0246 QModelIndex indexByShape(KoShape* shape) const; 0247 0248 /** 0249 * @brief Set begin time for the animation on index 0250 * 0251 * @param index index of the animation 0252 * @param begin the begin time 0253 */ 0254 void setBeginTime(const QModelIndex &index, const int begin); 0255 0256 /** 0257 * @brief Set duration for the animation on index 0258 * 0259 * @param index index of the animation 0260 * @param duration duration of the animation 0261 */ 0262 void setDuration(const QModelIndex &index, const int duration); 0263 0264 KPrShapeAnimation *animationByRow(int row, int *pGroup = 0, KPrShapeAnimation::NodeType *pNodeType = 0) const; 0265 0266 /** 0267 * @brief add new animation after index 0268 * 0269 * @param newAnimation animation to be inserted 0270 * @param previousAnimation index of the previous animation 0271 */ 0272 void insertNewAnimation(KPrShapeAnimation *newAnimation, const QModelIndex &previousAnimation); 0273 0274 QModelIndex indexByAnimation(KPrShapeAnimation *animation) const; 0275 0276 void resyncStepsWithAnimations(); 0277 0278 KPrShapeAnimation::NodeType triggerEventByIndex(const QModelIndex &index); 0279 0280 public Q_SLOTS: 0281 /// Notify a external edition of begin or end time 0282 void notifyAnimationEdited(); 0283 0284 /// Notify an external edition of an animation 0285 void notifyAnimationChanged(KPrShapeAnimation *animation); 0286 0287 /// Notify if an animation set as OnClick has changed of trigger event 0288 void notifyOnClickEventChanged(); 0289 0290 Q_SIGNALS: 0291 void timeScaleModified(); 0292 void onClickEventChanged(); 0293 0294 private: 0295 0296 void dump() const; 0297 QString getAnimationName(KPrShapeAnimation *animation, bool omitSubType = false) const; 0298 QPixmap getAnimationShapeThumbnail(KPrShapeAnimation *animation) const; 0299 QPixmap getAnimationIcon(KPrShapeAnimation *animation) const; 0300 QImage createThumbnail(KoShape *shape, const QSize &thumbSize) const; 0301 void setTimeRangeIncrementalChange(KPrShapeAnimation *item, const int begin, 0302 const int duration, TimeUpdated updatedTimes); 0303 QList<KPrShapeAnimation *> getWithPreviousSiblings(KPrShapeAnimation *animation) const; 0304 QList<KPrAnimationSubStep *> getSubSteps(int start, int end, KPrAnimationStep *step) const; 0305 bool createTriggerEventEditCmd(KPrShapeAnimation *animation, KPrShapeAnimation::NodeType oldType, 0306 KPrShapeAnimation::NodeType newType); 0307 0308 QList<KPrAnimationStep *> m_shapeAnimations; 0309 KPrShapeAnimation *m_currentEditedAnimation; 0310 bool m_firstEdition; 0311 int m_oldBegin; 0312 int m_oldDuration; 0313 KPrDocument *m_document; 0314 }; 0315 0316 #endif /* KPRSHAPEANIMATIONS_H */