]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/pixmapviewer.h
Detect animated format using mimeType instead of file path
[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 <QPixmap>
24 #include <QQueue>
25 #include <QTimeLine>
26 #include <QWidget>
27
28 class QPaintEvent;
29 class QMovie;
30
31 /**
32 * @brief Widget which shows a pixmap centered inside the boundaries.
33 *
34 * When the pixmap is changed, a smooth transition is done from the old pixmap
35 * to the new pixmap.
36 */
37 class PixmapViewer : public QWidget
38 {
39 Q_OBJECT
40
41 public:
42 enum Transition
43 {
44 /** No transition is done when the pixmap is changed. */
45 NoTransition,
46
47 /**
48 * The old pixmap is replaced by the new pixmap and the size is
49 * adjusted smoothly to the size of the new pixmap.
50 */
51 DefaultTransition,
52
53 /**
54 * If the old pixmap and the new pixmap have the same content, but
55 * a different size it is recommended to use Transition::SizeTransition
56 * instead of Transition::DefaultTransition. In this case it is assured
57 * that the larger pixmap is used for downscaling, which leads
58 * to an improved scaling output.
59 */
60 SizeTransition
61 };
62
63 explicit PixmapViewer(QWidget* parent,
64 Transition transition = DefaultTransition);
65
66 ~PixmapViewer() override;
67 void setPixmap(const QPixmap& pixmap);
68 QPixmap pixmap() const;
69
70 /**
71 * Sets the size hint to \a size and triggers a relayout
72 * of the parent widget. Per default no size hint is given.
73 */
74 void setSizeHint(const QSize& size);
75 QSize sizeHint() const override;
76
77 void setAnimatedImageFileName(const QString& fileName);
78 QString animatedImageFileName() const;
79
80 void stopAnimatedImage();
81
82 /**
83 * Checks if \a mimeType has a format supported by QMovie.
84 */
85 static bool isAnimatedMimeType(const QString &mimeType);
86
87 protected:
88 void paintEvent(QPaintEvent* event) override;
89
90 private Q_SLOTS:
91 void checkPendingPixmaps();
92 void updateAnimatedImageFrame();
93
94 private:
95 QPixmap m_pixmap;
96 QPixmap m_oldPixmap;
97 QMovie* m_animatedImage;
98 QQueue<QPixmap> m_pendingPixmaps;
99 QTimeLine m_animation;
100 Transition m_transition;
101 int m_animationStep;
102 QSize m_sizeHint;
103 bool m_hasAnimatedImage;
104 };
105
106 inline QPixmap PixmapViewer::pixmap() const
107 {
108 return m_pixmap;
109 }
110
111
112 #endif