• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Animators

defaultAnimator.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2007 Aaron Seigo <aseigo@kde.org>
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 "defaultAnimator.h"
00021 
00022 #include <QGraphicsItem>
00023 #include <QPainter>
00024 
00025 #include <KDebug>
00026 
00027 DefaultAnimator::DefaultAnimator(QObject *parent, const QVariantList& list)
00028     : Plasma::AnimationDriver(parent)
00029 {
00030     Q_UNUSED(list)
00031 }
00032 
00033 int DefaultAnimator::animationFps(Plasma::Animator::Animation animation) const
00034 {
00035     switch (animation) {
00036         case Plasma::Animator::AppearAnimation:
00037             return 20;
00038         case Plasma::Animator::DisappearAnimation:
00039             return 20;
00040 
00041         default:
00042             return 0;
00043     }
00044 }
00045 
00046 int DefaultAnimator::elementAnimationFps(Plasma::Animator::Animation animation) const
00047 {
00048     switch (animation) {
00049         case Plasma::Animator::AppearAnimation:
00050             return 20;
00051         case Plasma::Animator::DisappearAnimation:
00052             return 20;
00053 
00054         default:
00055             return 0;
00056     }
00057 }
00058 
00059 void DefaultAnimator::itemAppear(qreal progress, QGraphicsItem* item)
00060 {
00061     //kDebug() << "DefaultAnimator::appear(" << progress << ", " << item << ")";
00062     if (progress >= 1) {
00063         item->resetTransform();
00064         return;
00065     }
00066     item->resetTransform();
00067     item->scale(progress, progress);
00068     QRectF r = item->boundingRect();
00069     item->translate(r.width() / 2 * progress, r.height() / 2 * progress);
00070 }
00071 
00072 void DefaultAnimator::itemDisappear(qreal progress, QGraphicsItem* item)
00073 {
00074     if (progress >= 1) {
00075         //item->resetTransform();
00076         return;
00077     }
00078     item->resetTransform();
00079     item->scale(1-progress,1-progress);
00080     QRectF r = item->boundingRect();
00081     item->translate(r.width() / 2 * progress, r.height() / 2 * progress);
00082 }
00083 
00084 QPixmap DefaultAnimator::elementAppear(qreal progress, const QPixmap& pixmap)
00085 {
00086     //kDebug() << progress;
00087     QPixmap pix = pixmap;
00088 
00089     if (progress < 1) {
00090         QColor alpha;
00091         alpha.setAlphaF(progress);
00092 
00093         QPainter painter(&pix);
00094         painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
00095         painter.fillRect(pix.rect(), alpha);
00096     }
00097 
00098     return pix;
00099 }
00100 
00101 QPixmap DefaultAnimator::elementDisappear(qreal progress, const QPixmap& pixmap)
00102 {
00103     //kDebug() << progress;
00104     QPixmap pix = pixmap;
00105 
00106     if (progress > 0) {
00107         QColor alpha;
00108         alpha.setAlphaF(1 - progress);
00109 
00110         QPainter painter(&pix);
00111         painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
00112         painter.fillRect(pix.rect(), alpha);
00113     }
00114 
00115     return pix;
00116 }
00117 
00118 #include "defaultAnimator.moc"

Animators

Skip menu "Animators"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal