Changeset View
Changeset View
Standalone View
Standalone View
src/panels/information/pixmapviewer.cpp
Show All 30 Lines | 27 | PixmapViewer::PixmapViewer(QWidget* parent, Transition transition) : | |||
---|---|---|---|---|---|
31 | m_sizeHint() | 31 | m_sizeHint() | ||
32 | { | 32 | { | ||
33 | setMinimumWidth(KIconLoader::SizeEnormous); | 33 | setMinimumWidth(KIconLoader::SizeEnormous); | ||
34 | setMinimumHeight(KIconLoader::SizeEnormous); | 34 | setMinimumHeight(KIconLoader::SizeEnormous); | ||
35 | 35 | | |||
36 | m_animation.setDuration(150); | 36 | m_animation.setDuration(150); | ||
37 | m_animation.setCurveShape(QTimeLine::LinearCurve); | 37 | m_animation.setCurveShape(QTimeLine::LinearCurve); | ||
38 | 38 | | |||
39 | if (m_transition != NoTransition) { | 39 | if (m_transition != Transition::NoTransition) { | ||
40 | connect(&m_animation, &QTimeLine::valueChanged, this, static_cast<void(PixmapViewer::*)()>(&PixmapViewer::update)); | 40 | connect(&m_animation, &QTimeLine::valueChanged, this, static_cast<void(PixmapViewer::*)()>(&PixmapViewer::update)); | ||
41 | connect(&m_animation, &QTimeLine::finished, this, &PixmapViewer::checkPendingPixmaps); | 41 | connect(&m_animation, &QTimeLine::finished, this, &PixmapViewer::checkPendingPixmaps); | ||
42 | } | 42 | } | ||
43 | } | 43 | } | ||
44 | 44 | | |||
45 | PixmapViewer::~PixmapViewer() | 45 | PixmapViewer::~PixmapViewer() | ||
46 | { | 46 | { | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | void PixmapViewer::setPixmap(const QPixmap& pixmap) | 49 | void PixmapViewer::setPixmap(const QPixmap& pixmap) | ||
50 | { | 50 | { | ||
51 | if (pixmap.isNull()) { | 51 | if (pixmap.isNull()) { | ||
52 | return; | 52 | return; | ||
53 | } | 53 | } | ||
54 | 54 | | |||
55 | if ((m_transition != NoTransition) && (m_animation.state() == QTimeLine::Running)) { | 55 | if ((m_transition != Transition::NoTransition) && (m_animation.state() == QTimeLine::Running)) { | ||
56 | m_pendingPixmaps.enqueue(pixmap); | 56 | m_pendingPixmaps.enqueue(pixmap); | ||
57 | if (m_pendingPixmaps.count() > 5) { | 57 | if (m_pendingPixmaps.count() > 5) { | ||
58 | // don't queue more than 5 pixmaps | 58 | // don't queue more than 5 pixmaps | ||
59 | m_pendingPixmaps.takeFirst(); | 59 | m_pendingPixmaps.takeFirst(); | ||
60 | } | 60 | } | ||
61 | return; | 61 | return; | ||
62 | } | 62 | } | ||
63 | 63 | | |||
64 | m_oldPixmap = m_pixmap.isNull() ? pixmap : m_pixmap; | 64 | m_oldPixmap = m_pixmap.isNull() ? pixmap : m_pixmap; | ||
65 | m_pixmap = pixmap; | 65 | m_pixmap = pixmap; | ||
66 | update(); | 66 | update(); | ||
67 | 67 | | |||
68 | const bool animate = (m_transition != NoTransition) && | 68 | const bool animate = (m_transition != Transition::NoTransition) && | ||
69 | (m_pixmap.size() != m_oldPixmap.size()); | 69 | (m_pixmap.size() != m_oldPixmap.size()); | ||
70 | if (animate) { | 70 | if (animate) { | ||
71 | m_animation.start(); | 71 | m_animation.start(); | ||
72 | } | 72 | } | ||
73 | } | 73 | } | ||
74 | 74 | | |||
75 | void PixmapViewer::setSizeHint(const QSize& size) | 75 | void PixmapViewer::setSizeHint(const QSize& size) | ||
76 | { | 76 | { | ||
77 | m_sizeHint = size; | 77 | m_sizeHint = size; | ||
78 | updateGeometry(); | 78 | updateGeometry(); | ||
79 | } | 79 | } | ||
80 | 80 | | |||
81 | QSize PixmapViewer::sizeHint() const | 81 | QSize PixmapViewer::sizeHint() const | ||
82 | { | 82 | { | ||
83 | return m_sizeHint; | 83 | return m_sizeHint; | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | void PixmapViewer::paintEvent(QPaintEvent* event) | 86 | void PixmapViewer::paintEvent(QPaintEvent* event) | ||
87 | { | 87 | { | ||
88 | QWidget::paintEvent(event); | 88 | QWidget::paintEvent(event); | ||
89 | 89 | | |||
90 | QPainter painter(this); | 90 | QPainter painter(this); | ||
91 | 91 | | |||
92 | if (m_transition != NoTransition) { | 92 | if (m_transition != Transition::NoTransition) { | ||
93 | const float value = m_animation.currentValue(); | 93 | const float value = m_animation.currentValue(); | ||
94 | const int scaledWidth = static_cast<int>((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value)); | 94 | const int scaledWidth = static_cast<int>((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value)); | ||
95 | const int scaledHeight = static_cast<int>((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value)); | 95 | const int scaledHeight = static_cast<int>((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value)); | ||
96 | 96 | | |||
97 | const bool useOldPixmap = (m_transition == SizeTransition) && | 97 | const bool useOldPixmap = (m_transition == Transition::Size) && | ||
98 | (m_oldPixmap.width() > m_pixmap.width()); | 98 | (m_oldPixmap.width() > m_pixmap.width()); | ||
99 | const QPixmap& largePixmap = useOldPixmap ? m_oldPixmap : m_pixmap; | 99 | const QPixmap& largePixmap = useOldPixmap ? m_oldPixmap : m_pixmap; | ||
100 | if (!largePixmap.isNull()) { | 100 | if (!largePixmap.isNull()) { | ||
101 | const QPixmap scaledPixmap = largePixmap.scaled(scaledWidth, | 101 | const QPixmap scaledPixmap = largePixmap.scaled(scaledWidth, | ||
102 | scaledHeight, | 102 | scaledHeight, | ||
103 | Qt::IgnoreAspectRatio, | 103 | Qt::IgnoreAspectRatio, | ||
104 | Qt::FastTransformation); | 104 | Qt::FastTransformation); | ||
105 | 105 | | |||
Show All 20 Lines |