]>
cloud.milkyroute.net Git - dolphin.git/blob - src/pixmapviewer.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "pixmapviewer.h"
22 #include <kiconloader.h>
23 #include <QtGui/QPainter>
24 #include <QtGui/QPixmap>
25 #include <QtGui/QKeyEvent>
27 PixmapViewer::PixmapViewer(QWidget
* parent
, Transition transition
) :
29 m_transition(transition
),
32 setMinimumWidth(K3Icon::SizeEnormous
);
33 setMinimumWidth(K3Icon::SizeEnormous
);
35 m_animation
.setDuration(300);
36 connect(&m_animation
, SIGNAL(valueChanged(qreal
)), this, SLOT(update()));
39 PixmapViewer::~PixmapViewer()
43 void PixmapViewer::setPixmap(const QPixmap
& pixmap
)
45 if (pixmap
.isNull()) {
49 m_oldPixmap
= m_pixmap
.isNull() ? pixmap
: m_pixmap
;
53 const bool animate
= (m_transition
!= NoTransition
) &&
54 (m_pixmap
.size() != m_oldPixmap
.size());
60 void PixmapViewer::paintEvent(QPaintEvent
* event
)
62 QWidget::paintEvent(event
);
64 QPainter
painter(this);
66 const float value
= m_animation
.currentValue();
68 const int scaledWidth
= static_cast<int>((m_oldPixmap
.width() * (1.0 - value
)) + (m_pixmap
.width() * value
));
69 const int scaledHeight
= static_cast<int>((m_oldPixmap
.height() * (1.0 - value
)) + (m_pixmap
.height() * value
));
70 const int x
= (width() - scaledWidth
) / 2;
71 const int y
= (height() - scaledHeight
) / 2;
73 const bool useOldPixmap
= (m_transition
== SizeTransition
) &&
74 (m_oldPixmap
.width() > m_pixmap
.width());
75 const QPixmap
& largePixmap
= useOldPixmap
? m_oldPixmap
: m_pixmap
;
76 const QPixmap scaledPixmap
= largePixmap
.scaled(scaledWidth
,
78 Qt::IgnoreAspectRatio
,
79 Qt::SmoothTransformation
);
80 painter
.drawPixmap(x
, y
, scaledPixmap
);
83 #include "pixmapviewer.moc"