File indexing completed on 2024-05-12 16:36:48

0001 /* This file is part of the KDE project
0002  * Copyright ( C ) 2007 Thorsten Zachmann <zachmann@kde.org>
0003  * Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (  at your option ) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #include "KPrShapeManagerAnimationStrategy.h"
0022 
0023 #include <QPainter>
0024 #include <KoShape.h>
0025 #include <KoShapeManager.h>
0026 #include <KoPAPageBase.h>
0027 
0028 #include "KPrShapeAnimations.h"
0029 #include "KPrPlaceholderShape.h"
0030 #include "animations/KPrAnimationCache.h"
0031 #include "KPrPageSelectStrategyBase.h"
0032 #include "StageDebug.h"
0033 
0034 KPrShapeManagerAnimationStrategy::KPrShapeManagerAnimationStrategy( KoShapeManager *shapeManager, KPrAnimationCache* animationCache,
0035                                                                     KPrPageSelectStrategyBase * strategy )
0036 : KoShapeManagerPaintingStrategy( shapeManager )
0037 , m_animationCache( animationCache )
0038 , m_strategy( strategy )
0039 {
0040 }
0041 
0042 KPrShapeManagerAnimationStrategy::~KPrShapeManagerAnimationStrategy()
0043 {
0044     delete m_strategy;
0045 }
0046 
0047 void KPrShapeManagerAnimationStrategy::paint( KoShape * shape, QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintContext)
0048 {
0049     if ( ! dynamic_cast<KPrPlaceholderShape *>( shape ) && m_strategy->page()->displayShape( shape ) ) {
0050         if ( m_animationCache->value(shape, "visibility", true).toBool() ) {
0051             painter.save();
0052             QTransform animationTransform = m_animationCache->value(shape, "transform", QTransform()).value<QTransform>();
0053             QTransform transform(painter.transform() * shape->absoluteTransformation(&converter));
0054             if (animationTransform.isScaling()) {
0055                 transform = animationTransform * transform;
0056             } else {
0057                 transform = transform * animationTransform;
0058             }
0059 
0060             painter.setTransform(transform);
0061             // paint shape
0062             shapeManager()->paintShape( shape, painter, converter, paintContext);
0063             painter.restore();  // for the transform
0064         }
0065     }
0066 }
0067 
0068 void KPrShapeManagerAnimationStrategy::adapt( KoShape * shape, QRectF & rect )
0069 {
0070     Q_UNUSED(shape)
0071     Q_UNUSED(rect)
0072 }