1 /* This file is part of the KDE project
2    Copyright (C) 2007-2008 Thorsten Zachmann <zachmann@kde.org>
3    Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com>
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14 
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef KPRPAGEEFFECT_H
22 #define KPRPAGEEFFECT_H
23 
24 #include <QPixmap>
25 #include <QTimeLine>
26 
27 #include <KoXmlReaderForward.h>
28 #include "stage_export.h"
29 
30 class QPainter;
31 class QGraphicsScene;
32 class QGraphicsPixmapItem;
33 class QGraphicsView;
34 class KoXmlWriter;
35 class KoGenStyle;
36 class KPrPageEffectStrategy;
37 
38 /**
39  * This is the base class for all page effects.
40  * It uses an internally a QTimeLine for calculating the position. The timeline is
41  * feed by the time of an external timeline.
42  */
43 class STAGE_EXPORT KPrPageEffect
44 {
45 public:
46     /**
47      * Data used by the effect
48      *
49      * The effect itself contains no status about the effect. All data
50      * is kept in this struct. It contains the old and new pixmap, the
51      * widget on which the effect is painted and the time values.
52      */
53     struct Data
54     {
DataData55         Data( const QPixmap &oldPage, const QPixmap &newPage, QWidget *w )
56         : m_oldPage( oldPage )
57         , m_newPage( newPage )
58         , m_widget( w )
59         , m_scene( 0 )
60         , m_graphicsView( 0 )
61         , m_finished( false )
62         , m_currentTime( 0 )
63         , m_lastTime( 0 )
64         {}
65 
66         QPixmap m_oldPage;
67         QPixmap m_newPage;
68         QWidget * m_widget;
69         QTimeLine m_timeLine;
70         QGraphicsScene *m_scene;
71         QGraphicsView *m_graphicsView;
72         QGraphicsPixmapItem *m_oldPageItem;
73         QGraphicsPixmapItem *m_newPageItem;
74         bool m_finished;
75         int m_currentTime;
76         int m_lastTime;
77     };
78 
79     /**
80      * Constructor
81      *
82      * @param duration The duration in milliseconds
83      * @param id The id of the page effect
84      * @param strategy The page effect strategy
85      */
86     KPrPageEffect( int duration, const QString & id, KPrPageEffectStrategy * strategy );
87     virtual ~KPrPageEffect();
88 
89     virtual void setup( const Data &data, QTimeLine &timeLine );
90     virtual bool useGraphicsView();
91     /**
92      * Paint the page effect
93      *
94      * This should repaint the whole widget. Due to clipping only the
95      * relevant parts are repainted.
96      *
97      * @param painter painter used for painting the effect.
98      * @param data The data used for painting the effect.
99      * @return true if the effect is finished, false otherwise
100      *
101      * @see next()
102      */
103     virtual bool paint( QPainter &painter, const Data &data );
104 
105     /**
106      * Trigger the next paint paint event.
107      *
108      * Trigger a repaint of the part of the widget that changed since
109      * the last time to this call. The default implementation repaints
110      * the full widget.
111      *
112      * @param data The data used for the effect.
113      */
114     virtual void next( const Data &data );
115 
116     /**
117      * Finish the page effect.
118      *
119      * Trigger a repaint of the part of the widget that changed since
120      * the last call to next. The default implementation repaints the
121      * full widget.
122      *
123      * @param data The data used for the effect.
124      */
125     virtual void finish( const Data &data );
126 
127     /**
128      * Get the duration of the page effect.
129      *
130      * @return The duration of the page effect.
131      */
132     int duration() const;
133 
134     /**
135      * Get the id of the page effect.
136      *
137      * @return id of the page effect
138      */
139     const QString & id() const;
140 
141     /**
142      * Get the sub type of the page effect.
143      *
144      * @return The sub type of the page effect.
145      */
146     int subType() const;
147 
148     /**
149      * Save the smil attributes of the effect
150      *
151      * @param xmlWriter The xml writer used for saving
152      */
153     void saveOdfSmilAttributes( KoXmlWriter & xmlWriter ) const;
154 
155     /**
156      * Save transition as part of the style
157      */
158     void saveOdfSmilAttributes( KoGenStyle & style ) const;
159 
160     /**
161      * Load effect from odf.
162      *
163      * Only generic data is loaded here. e.g. the duration of the effect
164      * is loaded here
165      */
166     void loadOdf( const KoXmlElement & element );
167 
168 protected:
169     int m_duration;
170     QString m_id;
171     KPrPageEffectStrategy * m_strategy;
172 };
173 
174 #endif // KPRPAGEEFFECT2_H
175 
176