┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/panels/information/pixmapviewer.cpp58
-rw-r--r--src/panels/information/pixmapviewer.h28
2 files changed, 4 insertions, 82 deletions
diff --git a/src/panels/information/pixmapviewer.cpp b/src/panels/information/pixmapviewer.cpp
index b18c9e64e..9ac9bd253 100644
--- a/src/panels/information/pixmapviewer.cpp
+++ b/src/panels/information/pixmapviewer.cpp
@@ -13,24 +13,14 @@
#include <QPainter>
#include <QStyle>
-PixmapViewer::PixmapViewer(QWidget *parent, Transition transition)
+PixmapViewer::PixmapViewer(QWidget *parent)
: QWidget(parent)
, m_animatedImage(nullptr)
- , m_transition(transition)
- , m_animationStep(0)
, m_sizeHint()
, m_hasAnimatedImage(false)
{
setMinimumWidth(KIconLoader::SizeEnormous);
setMinimumHeight(KIconLoader::SizeEnormous);
-
- m_animation.setDuration(150);
- m_animation.setEasingCurve(QEasingCurve::Linear);
-
- if (m_transition != NoTransition) {
- connect(&m_animation, &QTimeLine::valueChanged, this, QOverload<>::of(&PixmapViewer::update));
- connect(&m_animation, &QTimeLine::finished, this, &PixmapViewer::checkPendingPixmaps);
- }
}
PixmapViewer::~PixmapViewer()
@@ -43,16 +33,6 @@ void PixmapViewer::setPixmap(const QPixmap &pixmap)
return;
}
- if ((m_transition != NoTransition) && (m_animation.state() == QTimeLine::Running)) {
- m_pendingPixmaps.enqueue(pixmap);
- if (m_pendingPixmaps.count() > 5) {
- // don't queue more than 5 pixmaps
- m_pendingPixmaps.takeFirst();
- }
- return;
- }
-
- m_oldPixmap = m_pixmap.isNull() ? pixmap : m_pixmap;
m_pixmap = pixmap;
// Avoid flicker with static pixmap if an animated image is running
@@ -62,10 +42,7 @@ void PixmapViewer::setPixmap(const QPixmap &pixmap)
update();
- const bool animateTransition = (m_transition != NoTransition) && (m_pixmap.size() != m_oldPixmap.size());
- if (animateTransition) {
- m_animation.start();
- } else if (m_hasAnimatedImage) {
+ if (m_hasAnimatedImage) {
// If there is no transition animation but an animatedImage
// and it is not already running, start animating now
if (m_animatedImage->state() != QMovie::Running) {
@@ -117,40 +94,11 @@ void PixmapViewer::paintEvent(QPaintEvent *event)
QPainter painter(this);
- if (m_transition != NoTransition || (m_hasAnimatedImage && m_animatedImage->state() != QMovie::Running)) {
- const float value = m_animation.currentValue();
- const int scaledWidth = static_cast<int>((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value));
- const int scaledHeight = static_cast<int>((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value));
-
- const bool useOldPixmap = (m_transition == SizeTransition) && (m_oldPixmap.width() > m_pixmap.width());
- const QPixmap &largePixmap = useOldPixmap ? m_oldPixmap : m_pixmap;
- if (!largePixmap.isNull()) {
- QPixmap scaledPixmap = largePixmap.scaled(scaledWidth, scaledHeight, Qt::IgnoreAspectRatio, Qt::FastTransformation);
- scaledPixmap.setDevicePixelRatio(devicePixelRatioF());
-
- style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, scaledPixmap);
- }
- } else if (!m_pixmap.isNull()) {
+ if (!m_pixmap.isNull()) {
style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, m_pixmap);
}
}
-void PixmapViewer::checkPendingPixmaps()
-{
- if (!m_pendingPixmaps.isEmpty()) {
- QPixmap pixmap = m_pendingPixmaps.dequeue();
- m_oldPixmap = m_pixmap.isNull() ? pixmap : m_pixmap;
- m_pixmap = pixmap;
- update();
- m_animation.start();
- } else if (m_hasAnimatedImage) {
- m_animatedImage->setScaledSize(m_pixmap.size());
- m_animatedImage->start();
- } else {
- m_oldPixmap = m_pixmap;
- }
-}
-
void PixmapViewer::updateAnimatedImageFrame()
{
Q_ASSERT(m_animatedImage);
diff --git a/src/panels/information/pixmapviewer.h b/src/panels/information/pixmapviewer.h
index 32c06fe15..a71ce6677 100644
--- a/src/panels/information/pixmapviewer.h
+++ b/src/panels/information/pixmapviewer.h
@@ -26,27 +26,7 @@ class PixmapViewer : public QWidget
Q_OBJECT
public:
- enum Transition {
- /** No transition is done when the pixmap is changed. */
- NoTransition,
-
- /**
- * The old pixmap is replaced by the new pixmap and the size is
- * adjusted smoothly to the size of the new pixmap.
- */
- DefaultTransition,
-
- /**
- * If the old pixmap and the new pixmap have the same content, but
- * a different size it is recommended to use Transition::SizeTransition
- * instead of Transition::DefaultTransition. In this case it is assured
- * that the larger pixmap is used for downscaling, which leads
- * to an improved scaling output.
- */
- SizeTransition
- };
-
- explicit PixmapViewer(QWidget *parent, Transition transition = DefaultTransition);
+ explicit PixmapViewer(QWidget *parent);
~PixmapViewer() override;
void setPixmap(const QPixmap &pixmap);
@@ -73,17 +53,11 @@ protected:
void paintEvent(QPaintEvent *event) override;
private Q_SLOTS:
- void checkPendingPixmaps();
void updateAnimatedImageFrame();
private:
QPixmap m_pixmap;
- QPixmap m_oldPixmap;
QMovie *m_animatedImage;
- QQueue<QPixmap> m_pendingPixmaps;
- QTimeLine m_animation;
- Transition m_transition;
- int m_animationStep;
QSize m_sizeHint;
bool m_hasAnimatedImage;
};