pictureflow.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. @class: PictureFlow
  3. @descprition: This class extends an additional feature to
  4. PictureFlow (http://pictureflow.googlecode.com). It also displays a caption whenever
  5. a slide is displayed.
  6. @author: Mirko Perkusich
  7. Taciana Rached
  8. */
  9. /*
  10. Copyright (c) 2010 Embedded Systems and Pervasive Laboratory, Federal
  11. University of Campina Grande, Brazil, Angelo Perkusich, Mirko Perkusich,
  12. Taciana Rached
  13. Permission is hereby granted, free of charge, to any person obtaining a
  14. copy of this software and associated documentation files (the
  15. "Software"), to deal in the Software without restriction, including
  16. without limitation the rights to use, copy, modify, merge, publish,
  17. distribute, sublicense, and/or sell copies of the Software, and to
  18. permit persons to whom the Software is furnished to do so, subject to
  19. the following conditions:
  20. The above copyright notice and this permission notice shall be included
  21. in all copies or substantial portions of the Software.
  22. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  23. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  25. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  26. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  27. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  28. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. /*
  31. PictureFlow - animated image show widget
  32. http://pictureflow.googlecode.com
  33. Copyright (C) 2008 Ariya Hidayat (ariya@kde.org)
  34. Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
  35. Permission is hereby granted, free of charge, to any person obtaining a copy
  36. of this software and associated documentation files (the "Software"), to deal
  37. in the Software without restriction, including without limitation the rights
  38. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  39. copies of the Software, and to permit persons to whom the Software is
  40. furnished to do so, subject to the following conditions:
  41. The above copyright notice and this permission notice shall be included in
  42. all copies or substantial portions of the Software.
  43. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  44. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  45. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  46. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  47. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  48. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  49. THE SOFTWARE.
  50. */
  51. #ifndef PICTUREFLOW_H
  52. #define PICTUREFLOW_H
  53. #include <qwidget.h>
  54. #include <QDebug>
  55. class PictureFlowPrivate;
  56. /*!
  57. Class PictureFlow implements an image show widget with animation effect
  58. like Apple's CoverFlow (in iTunes and iPod). Images are arranged in form
  59. of slides, one main slide is shown at the center with few slides on
  60. the left and right sides of the center slide. When the next or previous
  61. slide is brought to the front, the whole slides flow to the right or
  62. the right with smooth animation effect; until the new slide is finally
  63. placed at the center.
  64. */
  65. class PictureFlow : public QWidget
  66. {
  67. Q_OBJECT
  68. Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
  69. Q_PROPERTY(QSize slideSize READ slideSize WRITE setSlideSize)
  70. Q_PROPERTY(int slideCount READ slideCount)
  71. Q_PROPERTY(int centerIndex READ centerIndex WRITE setCenterIndex)
  72. public:
  73. enum ReflectionEffect
  74. {
  75. NoReflection,
  76. PlainReflection,
  77. BlurredReflection
  78. };
  79. /*!
  80. Creates a new PictureFlow widget.
  81. */
  82. PictureFlow(QWidget* parent = 0);
  83. /*!
  84. Destroys the widget.
  85. */
  86. ~PictureFlow();
  87. /*!
  88. Returns the background color.
  89. */
  90. QColor backgroundColor() const;
  91. /*!
  92. Sets the background color. By default it is black.
  93. */
  94. void setBackgroundColor(const QColor& c);
  95. /*!
  96. Returns the dimension of each slide (in pixels).
  97. */
  98. QSize slideSize() const;
  99. /*!
  100. Sets the dimension of each slide (in pixels).
  101. */
  102. void setSlideSize(QSize size);
  103. /*!
  104. Returns the total number of slides.
  105. */
  106. int slideCount() const;
  107. /*!
  108. Returns QImage of specified slide.
  109. */
  110. QImage slide(int index) const;
  111. /*!
  112. Returns the index of slide currently shown in the middle of the viewport.
  113. */
  114. int centerIndex() const;
  115. /*!
  116. Returns the effect applied to the reflection.
  117. */
  118. ReflectionEffect reflectionEffect() const;
  119. /*!
  120. Sets the effect applied to the reflection. The default is PlainReflection.
  121. */
  122. void setReflectionEffect(ReflectionEffect effect);
  123. public slots:
  124. /*!
  125. Adds a new slide.
  126. */
  127. void addSlide(const QImage& image);
  128. /*!
  129. Adds a new slide.
  130. */
  131. void addSlide(const QPixmap& pixmap);
  132. /*!
  133. Adds a new caption
  134. */
  135. void addSlideCaption(QString caption);
  136. /*!
  137. Sets an image for specified slide. If the slide already exists,
  138. it will be replaced.
  139. */
  140. void setSlide(int index, const QImage& image);
  141. /*!
  142. Sets a caption for the specified slide.
  143. */
  144. void setSlideCaption(int index, QString caption);
  145. /*!
  146. Sets a pixmap for specified slide. If the slide already exists,
  147. it will be replaced.
  148. */
  149. void setSlide(int index, const QPixmap& pixmap);
  150. /*!
  151. Sets slide to be shown in the middle of the viewport. No animation
  152. effect will be produced, unlike using showSlide.
  153. */
  154. void setCenterIndex(int index);
  155. /*!
  156. Clears all slides.
  157. */
  158. void clear();
  159. /*!
  160. Shows previous slide using animation effect.
  161. */
  162. void showPrevious();
  163. /*!
  164. Shows next slide using animation effect.
  165. */
  166. void showNext();
  167. /*!
  168. Go to specified slide using animation effect.
  169. */
  170. void showSlide(int index);
  171. /*!
  172. Rerender the widget. Normally this function will be automatically invoked
  173. whenever necessary, e.g. during the transition animation.
  174. */
  175. void render();
  176. /*!
  177. Schedules a rendering update. Unlike render(), this function does not cause
  178. immediate rendering.
  179. */
  180. void triggerRender();
  181. signals:
  182. void centerIndexChanged(int index);
  183. void mouseClicked();
  184. protected:
  185. void paintEvent(QPaintEvent *event);
  186. void keyPressEvent(QKeyEvent* event);
  187. void mousePressEvent(QMouseEvent* event);
  188. void resizeEvent(QResizeEvent* event);
  189. private slots:
  190. void updateAnimation();
  191. private:
  192. PictureFlowPrivate* d;
  193. };
  194. #endif // PICTUREFLOW_H