allow to specify a transition type

svn path=/trunk/KDE/kdebase/apps/; revision=660579
This commit is contained in:
Peter Penz 2007-05-03 05:52:11 +00:00
parent 7f2033899d
commit 0bdc4821e4
3 changed files with 41 additions and 12 deletions

View 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);

View 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,

View 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;
};