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