Plasma
zoom.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "zoom_p.h" 00021 00022 #include <kdebug.h> 00023 00024 namespace Plasma 00025 { 00026 00027 ZoomAnimation::ZoomAnimation(QObject *parent) 00028 : EasingAnimation(parent), 00029 m_zoom(0) 00030 { 00031 } 00032 00033 ZoomAnimation::~ZoomAnimation() 00034 { 00035 } 00036 00037 void ZoomAnimation::setZoom(qreal zoom) 00038 { 00039 m_zoom = zoom; 00040 } 00041 00042 qreal ZoomAnimation::zoom() const 00043 { 00044 return m_zoom; 00045 } 00046 00047 void ZoomAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) 00048 { 00049 QGraphicsWidget *w = targetWidget(); 00050 if (!w) { 00051 return; 00052 } 00053 00054 if (oldState == Stopped && newState == Running) { 00055 w->setTransformOriginPoint(w->size().width()/2, w->size().height()/2); 00056 w->setScale(direction() == Forward ? 1 : m_zoom); 00057 } else if (newState == Stopped) { 00058 w->setScale(direction() == Forward ? m_zoom : 1); 00059 } 00060 } 00061 00062 void ZoomAnimation::updateEffectiveTime(int currentTime) 00063 { 00064 QGraphicsWidget *w = targetWidget(); 00065 if (w) { 00066 qreal delta = currentTime / qreal(duration()); 00067 if (m_zoom != 1) { 00068 delta = (1 - m_zoom) * delta; 00069 w->setScale(1 - delta); 00070 } else { 00071 w->setScale(delta); 00072 } 00073 } 00074 } 00075 00076 } //namespace Plasma
KDE 4.6 API Reference