]> cloud.milkyroute.net Git - dolphin.git/commitdiff
allow to specify a transition type
authorPeter Penz <peter.penz19@gmail.com>
Thu, 3 May 2007 05:52:11 +0000 (05:52 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 3 May 2007 05:52:11 +0000 (05:52 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=660579

src/iconsizedialog.cpp
src/pixmapviewer.cpp
src/pixmapviewer.h

index 55256e87cd9831bb7a418d5d7503539c757706b7..88f1fbeb82884ef37368c1f2cdaaa1f85e917c51 100644 (file)
@@ -72,7 +72,7 @@ IconSizeDialog::IconSizeDialog(QWidget* parent) :
             this, SLOT(updateIconSize(int)));
     new QLabel(i18n("Large"), iconSizeHBox);
 
-    m_iconSizeViewer = new PixmapViewer(iconSizeBox);
+    m_iconSizeViewer = new PixmapViewer(iconSizeBox, PixmapViewer::SizeTransition);
     m_iconSizeViewer->setMinimumWidth(K3Icon::SizeEnormous);
     m_iconSizeViewer->setFixedHeight(K3Icon::SizeEnormous);
     m_iconSizeViewer->setEraseColor(iconBackgroundColor);
@@ -95,7 +95,7 @@ IconSizeDialog::IconSizeDialog(QWidget* parent) :
             this, SLOT(updatePreviewSize(int)));
     new QLabel(i18n("Large"), previewSizeHBox);
 
-    m_previewSizeViewer = new PixmapViewer(previewSizeBox);
+    m_previewSizeViewer = new PixmapViewer(previewSizeBox, PixmapViewer::SizeTransition);
     m_previewSizeViewer->setMinimumWidth(K3Icon::SizeEnormous);
     m_previewSizeViewer->setFixedHeight(K3Icon::SizeEnormous);
     m_previewSizeViewer->setEraseColor(iconBackgroundColor);
index e4d417d47171c3d8da2967fc4f9e7a61274435c5..4e3aa4830f9d1926dbe508ab0d58c6a5e5d36315 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  *
@@ -25,8 +24,9 @@
 #include <QtGui/QPixmap>
 #include <QtGui/QPaintEvent>
 
-PixmapViewer::PixmapViewer(QWidget* parent) :
+PixmapViewer::PixmapViewer(QWidget* parent, Transition transition) :
     QWidget(parent),
+    m_transition(transition),
     m_animationStep(0)
 {
     setMinimumWidth(K3Icon::SizeEnormous);
@@ -48,8 +48,11 @@ void PixmapViewer::setPixmap(const QPixmap& pixmap)
 
     m_oldPixmap = m_pixmap.isNull() ? pixmap : m_pixmap;
     m_pixmap = pixmap;
+    update();
 
-    m_animation.start();
+    if (m_transition != NoTransition) {
+        m_animation.start();
+    }
 }
 
 void PixmapViewer::paintEvent(QPaintEvent* event)
@@ -65,7 +68,9 @@ void PixmapViewer::paintEvent(QPaintEvent* event)
     const int x = (width()  - scaledWidth ) / 2;
     const int y = (height() - scaledHeight) / 2;
 
-    const QPixmap& largePixmap = (m_oldPixmap.width() > m_pixmap.width()) ? m_oldPixmap : m_pixmap;
+    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,
index 54ed5232c8e56933ef0fe1452f8c71772d4084dc..df4bd13b393259218dc5d742d791636e8e397862 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  *
@@ -30,14 +29,38 @@ class QPaintEvent;
 /**
  * @brief Widget which shows a pixmap centered inside the boundaries.
  *
- * @see IconsViewSettingsPage
- * @author Peter Penz <peter.penz@gmx.at>
+ * When the pixmap is changed, a smooth transition is done from the old pixmap
+ * to the new pixmap.
  */
 class PixmapViewer : public QWidget
 {
     Q_OBJECT
+
 public:
-    explicit PixmapViewer(QWidget* parent);
+    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);
+
     virtual ~PixmapViewer();
     void setPixmap(const QPixmap& pixmap);
     const QPixmap& pixmap() const
@@ -52,6 +75,7 @@ private:
     QPixmap m_pixmap;
     QPixmap m_oldPixmap;
     QTimeLine m_animation;
+    Transition m_transition;
     int m_animationStep;
 };