]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/pixmapviewer.h
Update e-mail address from peter.penz@gmx.at to peter.penz19@gmail.com
[dolphin.git] / src / panels / information / pixmapviewer.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef PIXMAPVIEWER_H
21 #define PIXMAPVIEWER_H
22
23 #include <QWidget>
24 #include <QPixmap>
25 #include <QQueue>
26 #include <QTimeLine>
27
28 class QPaintEvent;
29
30 /**
31 * @brief Widget which shows a pixmap centered inside the boundaries.
32 *
33 * When the pixmap is changed, a smooth transition is done from the old pixmap
34 * to the new pixmap.
35 */
36 class PixmapViewer : public QWidget
37 {
38 Q_OBJECT
39
40 public:
41 enum Transition
42 {
43 /** No transition is done when the pixmap is changed. */
44 NoTransition,
45
46 /**
47 * The old pixmap is replaced by the new pixmap and the size is
48 * adjusted smoothly to the size of the new pixmap.
49 */
50 DefaultTransition,
51
52 /**
53 * If the old pixmap and the new pixmap have the same content, but
54 * a different size it is recommended to use Transition::SizeTransition
55 * instead of Transition::DefaultTransition. In this case it is assured
56 * that the larger pixmap is used for downscaling, which leads
57 * to an improved scaling output.
58 */
59 SizeTransition
60 };
61
62 explicit PixmapViewer(QWidget* parent,
63 Transition transition = DefaultTransition);
64
65 virtual ~PixmapViewer();
66 void setPixmap(const QPixmap& pixmap);
67 QPixmap pixmap() const;
68
69 /**
70 * Sets the size hint to \a size and triggers a relayout
71 * of the parent widget. Per default no size hint is given.
72 */
73 void setSizeHint(const QSize& size);
74 virtual QSize sizeHint() const;
75
76 protected:
77 virtual void paintEvent(QPaintEvent* event);
78
79 private Q_SLOTS:
80 void checkPendingPixmaps();
81
82 private:
83 QPixmap m_pixmap;
84 QPixmap m_oldPixmap;
85 QQueue<QPixmap> m_pendingPixmaps;
86 QTimeLine m_animation;
87 Transition m_transition;
88 int m_animationStep;
89 QSize m_sizeHint;
90 };
91
92 inline QPixmap PixmapViewer::pixmap() const
93 {
94 return m_pixmap;
95 }
96
97
98 #endif