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);
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);
/***************************************************************************
- * 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 <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);
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)
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,
/***************************************************************************
- * 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 *
/**
* @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
QPixmap m_pixmap;
QPixmap m_oldPixmap;
QTimeLine m_animation;
+ Transition m_transition;
int m_animationStep;
};