From 1b15dd24e9c28cdc5ee5a16d7ce646d4618107b9 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sat, 24 Jul 2010 22:23:16 +0000 Subject: Sourcecode hierarchy cleanup: Move class PixmapViewer from "src" to "src/panels/information" svn path=/trunk/KDE/kdebase/apps/; revision=1154154 --- src/CMakeLists.txt | 3 +- src/panels/information/pixmapviewer.cpp | 130 ++++++++++++++++++++++++++++++++ src/panels/information/pixmapviewer.h | 98 ++++++++++++++++++++++++ src/pixmapviewer.cpp | 130 -------------------------------- src/pixmapviewer.h | 98 ------------------------ 5 files changed, 229 insertions(+), 230 deletions(-) create mode 100644 src/panels/information/pixmapviewer.cpp create mode 100644 src/panels/information/pixmapviewer.h delete mode 100644 src/pixmapviewer.cpp delete mode 100644 src/pixmapviewer.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 021edee38..09e58b720 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -102,9 +102,9 @@ set(dolphin_SRCS dolphincontextmenu.cpp filterbar/filterbar.cpp main.cpp - pixmapviewer.cpp panels/information/informationpanel.cpp panels/information/informationpanelcontent.cpp + panels/information/pixmapviewer.cpp panels/information/phononwidget.cpp panels/folders/ktreeview.cpp panels/places/placespanel.cpp @@ -197,7 +197,6 @@ install(TARGETS dolphin ${INSTALL_TARGETS_DEFAULT_ARGS}) ########################################## set(kcm_dolphinviewmodes_PART_SRCS - pixmapviewer.cpp settings/kcm/kcmdolphinviewmodes.cpp settings/viewmodes/columnviewsettingspage.cpp settings/viewmodes/detailsviewsettingspage.cpp diff --git a/src/panels/information/pixmapviewer.cpp b/src/panels/information/pixmapviewer.cpp new file mode 100644 index 000000000..416e53f1f --- /dev/null +++ b/src/panels/information/pixmapviewer.cpp @@ -0,0 +1,130 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "pixmapviewer.h" + +#include + +#include +#include +#include +#include + +PixmapViewer::PixmapViewer(QWidget* parent, Transition transition) : + QWidget(parent), + m_transition(transition), + m_animationStep(0), + m_sizeHint() +{ + setMinimumWidth(KIconLoader::SizeEnormous); + setMinimumHeight(KIconLoader::SizeEnormous); + + 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() +{ +} + +void PixmapViewer::setPixmap(const QPixmap& pixmap) +{ + if (pixmap.isNull()) { + 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(); + + const bool animate = (m_transition != NoTransition) && + (m_pixmap.size() != m_oldPixmap.size()); + if (animate) { + m_animation.start(); + } +} + +void PixmapViewer::setSizeHint(const QSize& size) +{ + m_sizeHint = size; + updateGeometry(); +} + +QSize PixmapViewer::sizeHint() const +{ + return m_sizeHint; +} + +void PixmapViewer::paintEvent(QPaintEvent* event) +{ + QWidget::paintEvent(event); + + QPainter painter(this); + + if (m_transition != NoTransition) { + const float value = m_animation.currentValue(); + const int scaledWidth = static_cast((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value)); + const int scaledHeight = static_cast((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value)); + + 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::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" diff --git a/src/panels/information/pixmapviewer.h b/src/panels/information/pixmapviewer.h new file mode 100644 index 000000000..c15750bb7 --- /dev/null +++ b/src/panels/information/pixmapviewer.h @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef PIXMAPVIEWER_H +#define PIXMAPVIEWER_H + +#include +#include +#include +#include + +class QPaintEvent; + +/** + * @brief Widget which shows a pixmap centered inside the boundaries. + * + * 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: + 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); + QPixmap pixmap() const; + + /** + * Sets the size hint to \a size and triggers a relayout + * of the parent widget. Per default no size hint is given. + */ + void setSizeHint(const QSize& size); + virtual QSize sizeHint() const; + +protected: + virtual void paintEvent(QPaintEvent* event); + +private Q_SLOTS: + void checkPendingPixmaps(); + +private: + QPixmap m_pixmap; + QPixmap m_oldPixmap; + QQueue m_pendingPixmaps; + QTimeLine m_animation; + Transition m_transition; + int m_animationStep; + QSize m_sizeHint; +}; + +inline QPixmap PixmapViewer::pixmap() const +{ + return m_pixmap; +} + + +#endif diff --git a/src/pixmapviewer.cpp b/src/pixmapviewer.cpp deleted file mode 100644 index 416e53f1f..000000000 --- a/src/pixmapviewer.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "pixmapviewer.h" - -#include - -#include -#include -#include -#include - -PixmapViewer::PixmapViewer(QWidget* parent, Transition transition) : - QWidget(parent), - m_transition(transition), - m_animationStep(0), - m_sizeHint() -{ - setMinimumWidth(KIconLoader::SizeEnormous); - setMinimumHeight(KIconLoader::SizeEnormous); - - 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() -{ -} - -void PixmapViewer::setPixmap(const QPixmap& pixmap) -{ - if (pixmap.isNull()) { - 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(); - - const bool animate = (m_transition != NoTransition) && - (m_pixmap.size() != m_oldPixmap.size()); - if (animate) { - m_animation.start(); - } -} - -void PixmapViewer::setSizeHint(const QSize& size) -{ - m_sizeHint = size; - updateGeometry(); -} - -QSize PixmapViewer::sizeHint() const -{ - return m_sizeHint; -} - -void PixmapViewer::paintEvent(QPaintEvent* event) -{ - QWidget::paintEvent(event); - - QPainter painter(this); - - if (m_transition != NoTransition) { - const float value = m_animation.currentValue(); - const int scaledWidth = static_cast((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value)); - const int scaledHeight = static_cast((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value)); - - 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::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" diff --git a/src/pixmapviewer.h b/src/pixmapviewer.h deleted file mode 100644 index c15750bb7..000000000 --- a/src/pixmapviewer.h +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef PIXMAPVIEWER_H -#define PIXMAPVIEWER_H - -#include -#include -#include -#include - -class QPaintEvent; - -/** - * @brief Widget which shows a pixmap centered inside the boundaries. - * - * 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: - 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); - QPixmap pixmap() const; - - /** - * Sets the size hint to \a size and triggers a relayout - * of the parent widget. Per default no size hint is given. - */ - void setSizeHint(const QSize& size); - virtual QSize sizeHint() const; - -protected: - virtual void paintEvent(QPaintEvent* event); - -private Q_SLOTS: - void checkPendingPixmaps(); - -private: - QPixmap m_pixmap; - QPixmap m_oldPixmap; - QQueue m_pendingPixmaps; - QTimeLine m_animation; - Transition m_transition; - int m_animationStep; - QSize m_sizeHint; -}; - -inline QPixmap PixmapViewer::pixmap() const -{ - return m_pixmap; -} - - -#endif -- cgit v1.3