mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Smoother animations for the pixmap viewer if the pixmap is changed constantly during small time slots (thanks to Rafael Fernández López for the original patch!).
svn path=/trunk/KDE/kdebase/apps/; revision=700580
This commit is contained in:
parent
548104b1fb
commit
d3178ea15f
3 changed files with 68 additions and 33 deletions
|
@ -133,14 +133,8 @@ void IconSizeDialog::updateIconSize(int value)
|
|||
{
|
||||
KIconLoader iconLoader;
|
||||
m_iconSizeViewer->setPixmap(iconLoader.loadIcon("folder", K3Icon::Desktop, iconSize(value)));
|
||||
|
||||
if (m_previewSizeSlider != 0) {
|
||||
int previewSizeValue = m_previewSizeSlider->value();
|
||||
if (previewSizeValue < value) {
|
||||
// assure that the preview size is never smaller than the icon size
|
||||
previewSizeValue = value;
|
||||
}
|
||||
updatePreviewSize(previewSizeValue);
|
||||
updatePreviewSize(m_previewSizeSlider->value());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,10 @@
|
|||
#include "pixmapviewer.h"
|
||||
|
||||
#include <kiconloader.h>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QPixmap>
|
||||
#include <QtGui/QKeyEvent>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QKeyEvent>
|
||||
|
||||
PixmapViewer::PixmapViewer(QWidget* parent, Transition transition) :
|
||||
QWidget(parent),
|
||||
|
@ -30,10 +31,15 @@ PixmapViewer::PixmapViewer(QWidget* parent, Transition transition) :
|
|||
m_animationStep(0)
|
||||
{
|
||||
setMinimumWidth(K3Icon::SizeEnormous);
|
||||
setMinimumWidth(K3Icon::SizeEnormous);
|
||||
setMinimumHeight(K3Icon::SizeEnormous);
|
||||
|
||||
m_animation.setDuration(300);
|
||||
connect(&m_animation, SIGNAL(valueChanged(qreal)), this, SLOT(update()));
|
||||
m_animation.setDuration(150);
|
||||
m_animation.setCurveShape(QTimeLine::LinearCurve);
|
||||
|
||||
if (m_transition != NoTransition) {
|
||||
connect(&m_animation, SIGNAL(valueChanged(qreal)), this, SLOT(update()));
|
||||
connect(&m_animation, SIGNAL(finished()), this, SLOT(checkPendingPixmaps()));
|
||||
}
|
||||
}
|
||||
|
||||
PixmapViewer::~PixmapViewer()
|
||||
|
@ -46,6 +52,15 @@ void PixmapViewer::setPixmap(const QPixmap& pixmap)
|
|||
return;
|
||||
}
|
||||
|
||||
if ((m_transition != NoTransition) && (m_animation.state() == QTimeLine::Running)) {
|
||||
m_pendingPixmaps.enqueue(pixmap);
|
||||
if (m_pendingPixmaps.count() > 5) {
|
||||
// don't queue more than 5 pixmaps
|
||||
m_pendingPixmaps.takeFirst();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_oldPixmap = m_pixmap.isNull() ? pixmap : m_pixmap;
|
||||
m_pixmap = pixmap;
|
||||
update();
|
||||
|
@ -63,21 +78,40 @@ void PixmapViewer::paintEvent(QPaintEvent* event)
|
|||
|
||||
QPainter painter(this);
|
||||
|
||||
const float value = m_animation.currentValue();
|
||||
if (m_transition != NoTransition) {
|
||||
const float value = m_animation.currentValue();
|
||||
const int scaledWidth = static_cast<int>((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value));
|
||||
const int scaledHeight = static_cast<int>((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value));
|
||||
|
||||
const int scaledWidth = static_cast<int>((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value));
|
||||
const int scaledHeight = static_cast<int>((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value));
|
||||
const int x = (width() - scaledWidth ) / 2;
|
||||
const int y = (height() - scaledHeight) / 2;
|
||||
const int x = (width() - scaledWidth ) / 2;
|
||||
const int y = (height() - scaledHeight) / 2;
|
||||
|
||||
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,
|
||||
Qt::SmoothTransformation);
|
||||
painter.drawPixmap(x, y, scaledPixmap);
|
||||
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,
|
||||
Qt::FastTransformation);
|
||||
painter.drawPixmap(x, y, scaledPixmap);
|
||||
} else {
|
||||
const int x = (width() - m_pixmap.width() ) / 2;
|
||||
const int y = (height() - m_pixmap.height()) / 2;
|
||||
painter.drawPixmap(x, y, m_pixmap);
|
||||
}
|
||||
}
|
||||
|
||||
void PixmapViewer::checkPendingPixmaps()
|
||||
{
|
||||
if (m_pendingPixmaps.count() > 0) {
|
||||
QPixmap pixmap = m_pendingPixmaps.dequeue();
|
||||
m_oldPixmap = m_pixmap.isNull() ? pixmap : m_pixmap;
|
||||
m_pixmap = pixmap;
|
||||
update();
|
||||
m_animation.start();
|
||||
} else {
|
||||
m_oldPixmap = m_pixmap;
|
||||
}
|
||||
}
|
||||
|
||||
#include "pixmapviewer.moc"
|
||||
|
|
|
@ -20,9 +20,10 @@
|
|||
#ifndef PIXMAPVIEWER_H
|
||||
#define PIXMAPVIEWER_H
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QPixmap>
|
||||
#include <QtCore/QTimeLine>
|
||||
#include <QWidget>
|
||||
#include <QPixmap>
|
||||
#include <QQueue>
|
||||
#include <QTimeLine>
|
||||
|
||||
class QPaintEvent;
|
||||
|
||||
|
@ -63,21 +64,27 @@ public:
|
|||
|
||||
virtual ~PixmapViewer();
|
||||
void setPixmap(const QPixmap& pixmap);
|
||||
const QPixmap& pixmap() const
|
||||
{
|
||||
return m_pixmap;
|
||||
}
|
||||
inline const QPixmap& pixmap() const;
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* event);
|
||||
|
||||
private Q_SLOTS:
|
||||
void checkPendingPixmaps();
|
||||
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
QPixmap m_oldPixmap;
|
||||
QQueue<QPixmap> m_pendingPixmaps;
|
||||
QTimeLine m_animation;
|
||||
Transition m_transition;
|
||||
int m_animationStep;
|
||||
};
|
||||
|
||||
const QPixmap& PixmapViewer::pixmap() const
|
||||
{
|
||||
return m_pixmap;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue