File indexing completed on 2024-05-12 16:36:42

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  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (  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 GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef KPRANIMATIONDIRECTOR_H
0022 #define KPRANIMATIONDIRECTOR_H
0023 
0024 #include <QList>
0025 #include <QObject>
0026 #include <QPair>
0027 #include <QTimeLine>
0028 #include <QTransform>
0029 #include <QTimer>
0030 
0031 #include <KoZoomHandler.h>
0032 #include "KPrShapeAnimations.h"
0033 
0034 class QPainter;
0035 class QPaintEvent;
0036 class KoViewConverter;
0037 class KoShape;
0038 class KoPACanvas;
0039 class KoPAPageBase;
0040 class KoPAView;
0041 class KPrPageEffect;
0042 class KPrPageEffectRunner;
0043 class KPrPage;
0044 class KPrShapeAnimation;
0045 
0046 
0047 class KPrAnimationDirector : public QObject
0048 {
0049     Q_OBJECT
0050 public:
0051     enum Navigation
0052     {
0053         FirstPage,
0054         PreviousPage,
0055         PreviousStep,
0056         NextStep,
0057         NextPage,
0058         LastPage
0059     };
0060 
0061     enum State
0062     {
0063         PresentationState,
0064         EntryEffectState,
0065         EntryAnimationState
0066     };
0067 
0068     KPrAnimationDirector( KoPAView * view, KoPACanvas * canvas, const QList<KoPAPageBase*> & pages, KoPAPageBase* currentPage );
0069     ~KPrAnimationDirector() override;
0070 
0071     void paint(QPainter& painter, const QRectF &paintRect);
0072     void paintEvent( QPaintEvent* event );
0073 
0074     KoViewConverter * viewConverter();
0075 
0076     /**
0077      * get the number of pages
0078      */
0079     int numPages() const;
0080 
0081     /**
0082      * get the current page number
0083      */
0084     int currentPage() const;
0085 
0086     /**
0087      * get the number of steps in this page
0088      */
0089     int numStepsInPage() const;
0090 
0091     /**
0092      * get the current step
0093      */
0094     int currentStep() const;
0095 
0096     /**
0097      * do the next step in the presentation
0098      *
0099      * @return true if slideshow is finished and should be exited, false otherwise
0100      */
0101     bool navigate( Navigation navigation );
0102 
0103     /**
0104      * do the navigation to the page specified
0105      */
0106     void navigateToPage( int index );
0107 
0108     void deactivate();
0109 
0110     KoPAPageBase *page(int index) const;
0111 
0112 protected:
0113     // set the page to be shon and update the UI
0114     void updateActivePage( KoPAPageBase * page );
0115 
0116     /**
0117      * change the page
0118      *
0119      * @return true if slideshow is finished and should be exited, false otherwise
0120      */
0121     bool changePage( Navigation navigation );
0122 
0123     /**
0124      * Update to the next step
0125      *
0126      * @return true if slideshow is finished and should be exited, false otherwise
0127      */
0128     bool nextStep();
0129 
0130     /**
0131      * Update to the previous step
0132      */
0133     void previousStep();
0134 
0135     // paint the given step to the painter
0136     void paintStep( QPainter & painter );
0137 
0138     /**
0139      * Finish the running shape animations
0140      */
0141     void finishAnimations();
0142 
0143     /**
0144      * Start the timeline
0145      */
0146     void startTimeLine( int duration );
0147 
0148     // helper method for freeing the resources of the animations
0149     void clearAnimations();
0150     // check if there is a set animation in m_animations
0151     bool hasAnimation() const;
0152     bool animationRunning() const;
0153     bool moreAnimationSteps() const;
0154 
0155     bool hasPageEffect() const;
0156     bool pageEffectRunning() const;
0157 
0158     bool hasAutoSlideTransition() const;
0159     void startAutoSlideTransition();
0160 
0161     void updatePageAnimation();
0162     void updateStepAnimation();
0163 
0164 protected Q_SLOTS:
0165     // update the zoom value
0166     void updateZoom( const QSize & size );
0167     // acts on the time line event
0168     void animate();
0169 
0170     void nextPage();
0171     void slotTimelineFinished();
0172 
0173 private:
0174     KoPAView * m_view;
0175     KoPACanvas * m_canvas;
0176     QList<KoPAPageBase*> m_pages;
0177 
0178     KoZoomHandler m_zoomHandler;
0179     QPoint m_offset;
0180     QRect m_pageRect;
0181 
0182     KPrPageEffectRunner * m_pageEffectRunner;
0183     QList<KPrAnimationStep *> m_animations;
0184     QTimeLine m_timeLine;
0185     int m_pageIndex;
0186     int m_stepIndex;
0187     int m_maxShapeDuration;
0188     // true when there is an animation in this step
0189     bool m_hasAnimation;
0190     KPrAnimationCache * m_animationCache;
0191 
0192     State m_state;
0193     QTimer m_autoTransitionTimer;
0194 };
0195 
0196 #endif /* KPRANIMATIONDIRECTOR_H */