| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the ActiveQt framework of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:BSD$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** BSD License Usage | 
| 18 | ** Alternatively, you may use this file under the terms of the BSD license | 
| 19 | ** as follows: | 
| 20 | ** | 
| 21 | ** "Redistribution and use in source and binary forms, with or without | 
| 22 | ** modification, are permitted provided that the following conditions are | 
| 23 | ** met: | 
| 24 | **   * Redistributions of source code must retain the above copyright | 
| 25 | **     notice, this list of conditions and the following disclaimer. | 
| 26 | **   * Redistributions in binary form must reproduce the above copyright | 
| 27 | **     notice, this list of conditions and the following disclaimer in | 
| 28 | **     the documentation and/or other materials provided with the | 
| 29 | **     distribution. | 
| 30 | **   * Neither the name of The Qt Company Ltd nor the names of its | 
| 31 | **     contributors may be used to endorse or promote products derived | 
| 32 | **     from this software without specific prior written permission. | 
| 33 | ** | 
| 34 | ** | 
| 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
| 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
| 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
| 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
| 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
| 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
| 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
| 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
| 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | 
| 46 | ** | 
| 47 | ** $QT_END_LICENSE$ | 
| 48 | ** | 
| 49 | ** | 
| 50 | ****************************************************************************/ | 
| 51 |  | 
| 52 | /* | 
| 53 |   ORIGINAL COPYRIGHT HEADER | 
| 54 |   PictureFlow - animated image show widget | 
| 55 |   http://pictureflow.googlecode.com | 
| 56 |  | 
| 57 |   Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) | 
| 58 |  | 
| 59 |   Permission is hereby granted, free of charge, to any person obtaining a copy | 
| 60 |   of this software and associated documentation files (the "Software"), to deal | 
| 61 |   in the Software without restriction, including without limitation the rights | 
| 62 |   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
| 63 |   copies of the Software, and to permit persons to whom the Software is | 
| 64 |   furnished to do so, subject to the following conditions: | 
| 65 |  | 
| 66 |   The above copyright notice and this permission notice shall be included in | 
| 67 |   all copies or substantial portions of the Software. | 
| 68 |  | 
| 69 |   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
| 70 |   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
| 71 |   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
| 72 |   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
| 73 |   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| 74 |   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
| 75 |   THE SOFTWARE. | 
| 76 | */ | 
| 77 |  | 
| 78 | #ifndef PICTUREFLOW_H | 
| 79 | #define PICTUREFLOW_H | 
| 80 |  | 
| 81 | #include <QWidget> | 
| 82 |  | 
| 83 | class PictureFlowPrivate; | 
| 84 |  | 
| 85 | /*! | 
| 86 |   Class PictureFlow implements an image show widget with animation effect | 
| 87 |   like Apple's CoverFlow (in iTunes and iPod). Images are arranged in form | 
| 88 |   of slides, one main slide is shown at the center with few slides on | 
| 89 |   the left and right sides of the center slide. When the next or previous | 
| 90 |   slide is brought to the front, the whole slides flow to the right or | 
| 91 |   the right with smooth animation effect; until the new slide is finally | 
| 92 |   placed at the center. | 
| 93 |  | 
| 94 |  */ | 
| 95 | class PictureFlow : public QWidget | 
| 96 | { | 
| 97 | Q_OBJECT | 
| 98 |  | 
| 99 |   Q_PROPERTY(int slideCount READ slideCount WRITE setSlideCount) | 
| 100 |   Q_PROPERTY(int currentSlide READ currentSlide WRITE setCurrentSlide) | 
| 101 |   Q_PROPERTY(QSize slideSize READ slideSize WRITE setSlideSize) | 
| 102 |   Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor) | 
| 103 |  | 
| 104 | public: | 
| 105 |   /*! | 
| 106 |     Creates a new PictureFlow widget. | 
| 107 |   */ | 
| 108 |   PictureFlow(QWidget* parent = 0); | 
| 109 |  | 
| 110 |   /*! | 
| 111 |     Destroys the widget. | 
| 112 |   */ | 
| 113 |   ~PictureFlow(); | 
| 114 |  | 
| 115 |   /*! | 
| 116 |     Returns the total number of slides. | 
| 117 |   */ | 
| 118 |   int slideCount() const; | 
| 119 |  | 
| 120 |   /*! | 
| 121 |     Sets the total number of slides. | 
| 122 |   */ | 
| 123 |   void setSlideCount(int count); | 
| 124 |  | 
| 125 |   /*! | 
| 126 |     Returns the dimension of each slide (in pixels). | 
| 127 |   */ | 
| 128 |   QSize slideSize() const; | 
| 129 |  | 
| 130 |   /*! | 
| 131 |     Sets the dimension of each slide (in pixels). | 
| 132 |   */ | 
| 133 |   void setSlideSize(QSize size); | 
| 134 |  | 
| 135 |   /*! | 
| 136 |     Sets the zoom factor (in percent). | 
| 137 |   */ | 
| 138 |   void setZoomFactor(int zoom); | 
| 139 |  | 
| 140 |   /*! | 
| 141 |     Returns the zoom factor (in percent). | 
| 142 |   */ | 
| 143 |   int zoomFactor() const; | 
| 144 |  | 
| 145 |   /*! | 
| 146 |     Clears any caches held to free up memory | 
| 147 |   */ | 
| 148 |   void clearCaches(); | 
| 149 |  | 
| 150 |   /*! | 
| 151 |     Returns QImage of specified slide. | 
| 152 |     This function will be called only whenever necessary, e.g. the 100th slide | 
| 153 |     will not be retrived when only the first few slides are visible. | 
| 154 |   */ | 
| 155 |   virtual QImage slide(int index) const; | 
| 156 |  | 
| 157 |   /*! | 
| 158 |     Sets an image for specified slide. If the slide already exists, | 
| 159 |     it will be replaced. | 
| 160 |   */ | 
| 161 |   virtual void setSlide(int index, const QImage& image); | 
| 162 |  | 
| 163 |   virtual void setSlideCaption(int index, QString caption); | 
| 164 |  | 
| 165 |   /*! | 
| 166 |     Sets a pixmap for specified slide. If the slide already exists, | 
| 167 |     it will be replaced. | 
| 168 |   */ | 
| 169 |   virtual void setSlide(int index, const QPixmap& pixmap); | 
| 170 |  | 
| 171 |   /*! | 
| 172 |     Returns the index of slide currently shown in the middle of the viewport. | 
| 173 |   */ | 
| 174 |   int currentSlide() const; | 
| 175 |  | 
| 176 | public slots: | 
| 177 |  | 
| 178 |   /*! | 
| 179 |     Sets slide to be shown in the middle of the viewport. No animation | 
| 180 |     effect will be produced, unlike using showSlide. | 
| 181 |   */ | 
| 182 |   void setCurrentSlide(int index); | 
| 183 |  | 
| 184 |   /*! | 
| 185 |     Clears images of all slides. | 
| 186 |   */ | 
| 187 |   void clear(); | 
| 188 |  | 
| 189 |   /*! | 
| 190 |     Rerender the widget. Normally this function will be automatically invoked | 
| 191 |     whenever necessary, e.g. during the transition animation. | 
| 192 |   */ | 
| 193 |   void render(); | 
| 194 |  | 
| 195 |   /*! | 
| 196 |     Shows previous slide using animation effect. | 
| 197 |   */ | 
| 198 |   void showPrevious(); | 
| 199 |  | 
| 200 |   /*! | 
| 201 |     Shows next slide using animation effect. | 
| 202 |   */ | 
| 203 |   void showNext(); | 
| 204 |  | 
| 205 |   /*! | 
| 206 |     Go to specified slide using animation effect. | 
| 207 |   */ | 
| 208 |   void showSlide(int index); | 
| 209 |  | 
| 210 | signals: | 
| 211 |   void itemActivated(int index); | 
| 212 |   void inputReceived(); | 
| 213 |  | 
| 214 | protected: | 
| 215 |   void paintEvent(QPaintEvent *event) override; | 
| 216 |   void keyPressEvent(QKeyEvent *event) override; | 
| 217 |   void mouseMoveEvent(QMouseEvent *event) override; | 
| 218 |   void mousePressEvent(QMouseEvent *event) override; | 
| 219 |   void mouseReleaseEvent(QMouseEvent *event) override; | 
| 220 |   void resizeEvent(QResizeEvent *event) override; | 
| 221 |   void timerEvent(QTimerEvent *event) override; | 
| 222 |  | 
| 223 | private: | 
| 224 |   PictureFlowPrivate* d; | 
| 225 | }; | 
| 226 |  | 
| 227 | #endif // PICTUREFLOW_H | 
| 228 |  |