┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2007-05-03 05:52:11 +0000
committerPeter Penz <[email protected]>2007-05-03 05:52:11 +0000
commit0bdc4821e4d3f426711185516347e1ae0ad88943 (patch)
tree2b25febdcebf368d1ee14230d8054d24772ca555
parent7f2033899d72527c5fcb533644f4068eeb2f332a (diff)
allow to specify a transition type
svn path=/trunk/KDE/kdebase/apps/; revision=660579
-rw-r--r--src/iconsizedialog.cpp4
-rw-r--r--src/pixmapviewer.cpp15
-rw-r--r--src/pixmapviewer.h34
3 files changed, 41 insertions, 12 deletions
diff --git a/src/iconsizedialog.cpp b/src/iconsizedialog.cpp
index 55256e87c..88f1fbeb8 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 e4d417d47..4e3aa4830 100644
--- a/src/pixmapviewer.cpp
+++ b/src/pixmapviewer.cpp
@@ -1,6 +1,5 @@
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
+ * Copyright (C) 2006 by Peter Penz <[email protected]> *
* *
* 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,
diff --git a/src/pixmapviewer.h b/src/pixmapviewer.h
index 54ed5232c..df4bd13b3 100644
--- a/src/pixmapviewer.h
+++ b/src/pixmapviewer.h
@@ -1,6 +1,5 @@
/***************************************************************************
- * Copyright (C) 2006 by Peter Penz *
+ * Copyright (C) 2006 by Peter Penz <[email protected]> *
* *
* 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 <[email protected]>
+ * 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;
};