1 /* |
|
2 PictureFlow - animated image show widget |
|
3 http://pictureflow.googlecode.com |
|
4 |
|
5 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 Copyright (C) 2008 Ariya Hidayat (ariya@kde.org) |
|
7 Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) |
|
8 |
|
9 Permission is hereby granted, free of charge, to any person obtaining a copy |
|
10 of this software and associated documentation files (the "Software"), to deal |
|
11 in the Software without restriction, including without limitation the rights |
|
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
13 copies of the Software, and to permit persons to whom the Software is |
|
14 furnished to do so, subject to the following conditions: |
|
15 |
|
16 The above copyright notice and this permission notice shall be included in |
|
17 all copies or substantial portions of the Software. |
|
18 |
|
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
25 THE SOFTWARE. |
|
26 */ |
|
27 |
|
28 #ifndef PICTUREFLOW_H |
|
29 #define PICTUREFLOW_H |
|
30 |
|
31 #include <qwidget.h> |
|
32 #include "FlowInterface.h" |
|
33 |
|
34 namespace WRT { |
|
35 |
|
36 class PictureFlowPrivate; |
|
37 |
|
38 enum ReflectionEffect |
|
39 { |
|
40 NoReflection, |
|
41 PlainReflection, |
|
42 BlurredReflection |
|
43 }; |
|
44 |
|
45 /*! |
|
46 Class PictureFlow implements an image show widget with animation effect |
|
47 like Apple's CoverFlow (in iTunes and iPod). Images are arranged in form |
|
48 of slides, one main slide is shown at the center with few slides on |
|
49 the left and right sides of the center slide. When the next or previous |
|
50 slide is brought to the front, the whole slides flow to the right or |
|
51 the right with smooth animation effect; until the new slide is finally |
|
52 placed at the center. |
|
53 |
|
54 */ |
|
55 class PictureFlow : public FlowInterface |
|
56 { |
|
57 Q_OBJECT |
|
58 |
|
59 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) |
|
60 Q_PROPERTY(QSize slideSize READ slideSize WRITE setSlideSize) |
|
61 Q_PROPERTY(int slideCount READ slideCount) |
|
62 Q_PROPERTY(int centerIndex READ centerIndex WRITE setCenterIndex) |
|
63 |
|
64 public: |
|
65 |
|
66 |
|
67 |
|
68 /*! |
|
69 Creates a new PictureFlow widget. |
|
70 */ |
|
71 PictureFlow(QWidget* parent = 0); |
|
72 |
|
73 /*! |
|
74 Destroys the widget. |
|
75 */ |
|
76 ~PictureFlow(); |
|
77 |
|
78 /*! |
|
79 Returns the background color. |
|
80 */ |
|
81 QColor backgroundColor() const; |
|
82 |
|
83 /*! |
|
84 Sets the background color. By default it is black. |
|
85 */ |
|
86 void setBackgroundColor(const QColor& c); |
|
87 |
|
88 /*! |
|
89 Returns the dimension of each slide (in pixels). |
|
90 */ |
|
91 QSize slideSize() const; |
|
92 |
|
93 /*! |
|
94 Sets the dimension of each slide (in pixels). |
|
95 */ |
|
96 void setSlideSize(QSize size); |
|
97 |
|
98 /*! |
|
99 Returns the total number of slides. |
|
100 */ |
|
101 int slideCount() const; |
|
102 |
|
103 /*! |
|
104 Returns QImage of specified slide. |
|
105 */ |
|
106 QImage slide(int index) const; |
|
107 |
|
108 /*! |
|
109 Returns the index of slide currently shown in the middle of the viewport. |
|
110 */ |
|
111 int centerIndex() const; |
|
112 |
|
113 /*! |
|
114 Return true if slide animation is ongoing |
|
115 */ |
|
116 bool slideAnimationOngoing() const; |
|
117 |
|
118 /*! |
|
119 Returns the effect applied to the reflection. |
|
120 */ |
|
121 ReflectionEffect reflectionEffect() const; |
|
122 |
|
123 /*! |
|
124 Sets the effect applied to the reflection. The default is PlainReflection. |
|
125 */ |
|
126 void setReflectionEffect(ReflectionEffect effect); |
|
127 |
|
128 QRect centralRect() const; |
|
129 |
|
130 void init(); |
|
131 |
|
132 public slots: |
|
133 |
|
134 /*! |
|
135 Adds a new slide. |
|
136 */ |
|
137 void addSlide(const QImage& image); |
|
138 |
|
139 /*! |
|
140 Adds a new slide. |
|
141 */ |
|
142 void addSlide(const QPixmap& pixmap); |
|
143 |
|
144 /*! |
|
145 Sets an image for specified slide. If the slide already exists, |
|
146 it will be replaced. |
|
147 */ |
|
148 void setSlide(int index, const QImage& image); |
|
149 |
|
150 /*! |
|
151 Sets a pixmap for specified slide. If the slide already exists, |
|
152 it will be replaced. |
|
153 */ |
|
154 void setSlide(int index, const QPixmap& pixmap); |
|
155 |
|
156 /*! |
|
157 Sets slide to be shown in the middle of the viewport. No animation |
|
158 effect will be produced, unlike using showSlide. |
|
159 */ |
|
160 void setCenterIndex(int index); |
|
161 |
|
162 /*! |
|
163 Clears all slides. |
|
164 */ |
|
165 void clear(); |
|
166 |
|
167 /*! |
|
168 Shows previous slide using animation effect. |
|
169 */ |
|
170 void showPrevious(); |
|
171 |
|
172 /*! |
|
173 Shows next slide using animation effect. |
|
174 */ |
|
175 void showNext(); |
|
176 |
|
177 /*! |
|
178 Go to specified slide using animation effect. |
|
179 */ |
|
180 void showSlide(int index); |
|
181 |
|
182 /*! |
|
183 Rerender the widget. Normally this function will be automatically invoked |
|
184 whenever necessary, e.g. during the transition animation. |
|
185 */ |
|
186 void render(); |
|
187 |
|
188 /*! |
|
189 Schedules a rendering update. Unlike render(), this function does not cause |
|
190 immediate rendering. |
|
191 */ |
|
192 void triggerRender(); |
|
193 |
|
194 signals: |
|
195 void centerIndexChanged(int index); |
|
196 void ok(int index); |
|
197 void cancel(); |
|
198 |
|
199 protected: |
|
200 void paintEvent(QPaintEvent *event); |
|
201 void keyPressEvent(QKeyEvent* event); |
|
202 void mousePressEvent(QMouseEvent* event); |
|
203 void resizeEvent(QResizeEvent* event); |
|
204 void mouseMoveEvent(QMouseEvent* event); |
|
205 void mouseReleaseEvent(QMouseEvent* event); |
|
206 |
|
207 private slots: |
|
208 void updateAnimation(); |
|
209 void scroll(); |
|
210 |
|
211 private: |
|
212 PictureFlowPrivate* d; |
|
213 QTimer* m_scrollTimer; |
|
214 QPoint m_lastMoveEventPos; |
|
215 }; |
|
216 |
|
217 class GraphicsPictureFlow : public GraphicsFlowInterface |
|
218 { |
|
219 Q_OBJECT |
|
220 |
|
221 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) |
|
222 Q_PROPERTY(QSize slideSize READ slideSize WRITE setSlideSize) |
|
223 Q_PROPERTY(int slideCount READ slideCount) |
|
224 Q_PROPERTY(int centerIndex READ centerIndex WRITE setCenterIndex) |
|
225 |
|
226 public: |
|
227 |
|
228 /*! |
|
229 Creates a new PictureFlow widget. |
|
230 */ |
|
231 GraphicsPictureFlow(QObject* parent = 0); |
|
232 |
|
233 /*! |
|
234 Destroys the widget. |
|
235 */ |
|
236 ~GraphicsPictureFlow(); |
|
237 |
|
238 /*! |
|
239 Returns the background color. |
|
240 */ |
|
241 QColor backgroundColor() const; |
|
242 |
|
243 /*! |
|
244 Sets the background color. By default it is black. |
|
245 */ |
|
246 void setBackgroundColor(const QColor& c); |
|
247 |
|
248 /*! |
|
249 Returns the dimension of each slide (in pixels). |
|
250 */ |
|
251 QSize slideSize() const; |
|
252 |
|
253 /*! |
|
254 Sets the dimension of each slide (in pixels). |
|
255 */ |
|
256 void setSlideSize(QSize size); |
|
257 |
|
258 /*! |
|
259 Returns the total number of slides. |
|
260 */ |
|
261 int slideCount() const; |
|
262 |
|
263 /*! |
|
264 Returns QImage of specified slide. |
|
265 */ |
|
266 QImage slide(int index) const; |
|
267 |
|
268 /*! |
|
269 Returns the index of slide currently shown in the middle of the viewport. |
|
270 */ |
|
271 int centerIndex() const; |
|
272 |
|
273 /*! |
|
274 Return true if slide animation is ongoing |
|
275 */ |
|
276 bool slideAnimationOngoing() const; |
|
277 |
|
278 /*! |
|
279 Returns the effect applied to the reflection. |
|
280 */ |
|
281 ReflectionEffect reflectionEffect() const; |
|
282 |
|
283 /*! |
|
284 Sets the effect applied to the reflection. The default is PlainReflection. |
|
285 */ |
|
286 void setReflectionEffect(ReflectionEffect effect); |
|
287 |
|
288 QRect centralRect() const; |
|
289 |
|
290 void init(); |
|
291 |
|
292 public slots: |
|
293 |
|
294 /*! |
|
295 Adds a new slide. |
|
296 */ |
|
297 void addSlide(const QImage& image); |
|
298 |
|
299 /*! |
|
300 Adds a new slide. |
|
301 */ |
|
302 void addSlide(const QPixmap& pixmap); |
|
303 |
|
304 /*! |
|
305 Sets an image for specified slide. If the slide already exists, |
|
306 it will be replaced. |
|
307 */ |
|
308 void setSlide(int index, const QImage& image); |
|
309 |
|
310 /*! |
|
311 Sets a pixmap for specified slide. If the slide already exists, |
|
312 it will be replaced. |
|
313 */ |
|
314 void setSlide(int index, const QPixmap& pixmap); |
|
315 |
|
316 /*! |
|
317 Sets slide to be shown in the middle of the viewport. No animation |
|
318 effect will be produced, unlike using showSlide. |
|
319 */ |
|
320 void setCenterIndex(int index); |
|
321 |
|
322 /*! |
|
323 Clears all slides. |
|
324 */ |
|
325 void clear(); |
|
326 |
|
327 /*! |
|
328 Shows previous slide using animation effect. |
|
329 */ |
|
330 void showPrevious(); |
|
331 |
|
332 /*! |
|
333 Shows next slide using animation effect. |
|
334 */ |
|
335 void showNext(); |
|
336 |
|
337 /*! |
|
338 Go to specified slide using animation effect. |
|
339 */ |
|
340 void showSlide(int index); |
|
341 |
|
342 /*! |
|
343 Rerender the widget. Normally this function will be automatically invoked |
|
344 whenever necessary, e.g. during the transition animation. |
|
345 */ |
|
346 void render(); |
|
347 |
|
348 /*! |
|
349 Schedules a rendering update. Unlike render(), this function does not cause |
|
350 immediate rendering. |
|
351 */ |
|
352 void triggerRender(); |
|
353 |
|
354 signals: |
|
355 void centerIndexChanged(int index); |
|
356 void ok(int index); |
|
357 void cancel(); |
|
358 |
|
359 protected: |
|
360 void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); |
|
361 void resizeEvent(QGraphicsSceneResizeEvent* event); |
|
362 void keyPressEvent(QKeyEvent* event); |
|
363 void mouseMoveEvent(QGraphicsSceneMouseEvent* event); |
|
364 void mousePressEvent(QGraphicsSceneMouseEvent* event); |
|
365 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); |
|
366 |
|
367 private slots: |
|
368 void updateAnimation(); |
|
369 void scroll(); |
|
370 |
|
371 private: |
|
372 PictureFlowPrivate* d; |
|
373 QTimer* m_scrollTimer; |
|
374 QPoint m_lastMoveEventPos; |
|
375 }; |
|
376 |
|
377 } |
|
378 #endif // PICTUREFLOW_H |
|
379 |
|