From 0bdc4821e4d3f426711185516347e1ae0ad88943 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 3 May 2007 05:52:11 +0000 Subject: [PATCH] allow to specify a transition type svn path=/trunk/KDE/kdebase/apps/; revision=660579 --- src/iconsizedialog.cpp | 4 ++-- src/pixmapviewer.cpp | 15 ++++++++++----- src/pixmapviewer.h | 34 +++++++++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/iconsizedialog.cpp b/src/iconsizedialog.cpp index 55256e87cd..88f1fbeb82 100644 --- a/src/iconsizedialog.cpp +++ b/src/iconsizedialog.cpp @@ -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); diff --git a/src/pixmapviewer.cpp b/src/pixmapviewer.cpp index e4d417d471..4e3aa4830f 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 * @@ -25,8 +24,9 @@ #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,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, diff --git a/src/pixmapviewer.h b/src/pixmapviewer.h index 54ed5232c8..df4bd13b39 100644 --- a/src/pixmapviewer.h +++ b/src/pixmapviewer.h @@ -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 * @@ -30,14 +29,38 @@ class QPaintEvent; /** * @brief Widget which shows a pixmap centered inside the boundaries. * - * @see IconsViewSettingsPage - * @author Peter Penz + * 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; };