]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/pixmapviewer.cpp
Fix small problems with enums. Sort by type works like a charm :)
[dolphin.git] / src / pixmapviewer.cpp
index 36d583c1d059ddd2241e573a7c1ba4f06d1a615b..79e2487a70d22ad5fc0158a7f65e14c1e8ffed32 100644 (file)
@@ -1,6 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz                                      *
- *   peter.penz@gmx.at                                                     *
+ *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
  *                                                                         *
  *   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  *
 #include <kiconloader.h>
 #include <QtGui/QPainter>
 #include <QtGui/QPixmap>
-#include <QtGui/QPaintEvent>
+#include <QtGui/QKeyEvent>
 
-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"