]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/pixmapviewer.h
Merge branch 'release/20.08'
[dolphin.git] / src / panels / information / pixmapviewer.h
1 /*
2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef PIXMAPVIEWER_H
8 #define PIXMAPVIEWER_H
9
10 #include <QPixmap>
11 #include <QQueue>
12 #include <QTimeLine>
13 #include <QWidget>
14
15 class QPaintEvent;
16 class QMovie;
17
18 /**
19 * @brief Widget which shows a pixmap centered inside the boundaries.
20 *
21 * When the pixmap is changed, a smooth transition is done from the old pixmap
22 * to the new pixmap.
23 */
24 class PixmapViewer : public QWidget
25 {
26 Q_OBJECT
27
28 public:
29 enum Transition
30 {
31 /** No transition is done when the pixmap is changed. */
32 NoTransition,
33
34 /**
35 * The old pixmap is replaced by the new pixmap and the size is
36 * adjusted smoothly to the size of the new pixmap.
37 */
38 DefaultTransition,
39
40 /**
41 * If the old pixmap and the new pixmap have the same content, but
42 * a different size it is recommended to use Transition::SizeTransition
43 * instead of Transition::DefaultTransition. In this case it is assured
44 * that the larger pixmap is used for downscaling, which leads
45 * to an improved scaling output.
46 */
47 SizeTransition
48 };
49
50 explicit PixmapViewer(QWidget* parent,
51 Transition transition = DefaultTransition);
52
53 ~PixmapViewer() override;
54 void setPixmap(const QPixmap& pixmap);
55 QPixmap pixmap() const;
56
57 /**
58 * Sets the size hint to \a size and triggers a relayout
59 * of the parent widget. Per default no size hint is given.
60 */
61 void setSizeHint(const QSize& size);
62 QSize sizeHint() const override;
63
64 void setAnimatedImageFileName(const QString& fileName);
65 QString animatedImageFileName() const;
66
67 void stopAnimatedImage();
68
69 /**
70 * Checks if \a mimeType has a format supported by QMovie.
71 */
72 static bool isAnimatedMimeType(const QString &mimeType);
73
74 protected:
75 void paintEvent(QPaintEvent* event) override;
76
77 private Q_SLOTS:
78 void checkPendingPixmaps();
79 void updateAnimatedImageFrame();
80
81 private:
82 QPixmap m_pixmap;
83 QPixmap m_oldPixmap;
84 QMovie* m_animatedImage;
85 QQueue<QPixmap> m_pendingPixmaps;
86 QTimeLine m_animation;
87 Transition m_transition;
88 int m_animationStep;
89 QSize m_sizeHint;
90 bool m_hasAnimatedImage;
91 };
92
93 inline QPixmap PixmapViewer::pixmap() const
94 {
95 return m_pixmap;
96 }
97
98
99 #endif