X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/da3bc09d21b43837873c899e2fbda1fa6c2a2e5e..20aedc53294376e05b79da5ea775f740b7a1aa49:/src/pixmapviewer.cpp diff --git a/src/pixmapviewer.cpp b/src/pixmapviewer.cpp index 36d583c1d..79e2487a7 100644 --- a/src/pixmapviewer.cpp +++ b/src/pixmapviewer.cpp @@ -1,6 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * + * Copyright (C) 2006 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -23,10 +22,11 @@ #include #include #include -#include +#include -PixmapViewer::PixmapViewer(QWidget* parent) : +PixmapViewer::PixmapViewer(QWidget* parent, Transition transition) : QWidget(parent), + m_transition(transition), m_animationStep(0) { setMinimumWidth(K3Icon::SizeEnormous); @@ -48,8 +48,13 @@ void PixmapViewer::setPixmap(const QPixmap& pixmap) m_oldPixmap = m_pixmap.isNull() ? pixmap : m_pixmap; m_pixmap = pixmap; + update(); - m_animation.start(); + const bool animate = (m_transition != NoTransition) && + (m_pixmap.size() != m_oldPixmap.size()); + if (animate) { + m_animation.start(); + } } void PixmapViewer::paintEvent(QPaintEvent* event) @@ -65,11 +70,14 @@ void PixmapViewer::paintEvent(QPaintEvent* event) const int x = (width() - scaledWidth ) / 2; const int y = (height() - scaledHeight) / 2; - if (m_oldPixmap.width() > m_pixmap.width()) { - painter.drawPixmap(x, y, m_oldPixmap.scaled(scaledWidth, scaledHeight)); - } else { - painter.drawPixmap(x, y, m_pixmap.scaled(scaledWidth, scaledHeight)); - } + const bool useOldPixmap = (m_transition == SizeTransition) && + (m_oldPixmap.width() > m_pixmap.width()); + const QPixmap& largePixmap = useOldPixmap ? m_oldPixmap : m_pixmap; + const QPixmap scaledPixmap = largePixmap.scaled(scaledWidth, + scaledHeight, + Qt::IgnoreAspectRatio, + Qt::SmoothTransformation); + painter.drawPixmap(x, y, scaledPixmap); } #include "pixmapviewer.moc"