1
/* This file is part of the KDE project
2
* Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or ( at your option ) any later version.
9
* This library 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 GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#include "KPrAttributeRotate.h"
21
#include "../KPrAnimationCache.h"
23
#include "KPrShapeAnimations.h"
24
#include "KoTextBlockData.h"
25
#include "KoTextShapeData.h"
26
#include <QTextDocument>
27
#include <QTextLayout>
30
KPrAttributeRotate::KPrAttributeRotate() : KPrAnimationAttribute("rotate")
34
void KPrAttributeRotate::updateCache(KPrAnimationCache *cache, KPrShapeAnimation *shapeAnimation, qreal value)
36
qreal tx = 0.0, ty = 0.0;
37
KoShape * shape = shapeAnimation->shape();
38
KoTextBlockData * textBlockData = shapeAnimation->textBlockData();
41
if (KoTextShapeData *textShapeData = dynamic_cast<KoTextShapeData*>(shape->userData())) {
42
QTextDocument *textDocument = textShapeData->document();
43
for (int i = 0; i < textDocument->blockCount(); i++) {
44
QTextBlock textBlock = textDocument->findBlockByNumber(i);
45
if (textBlock.userData() == textBlockData) {
46
QTextLayout *layout = textBlock.layout();
47
tx = layout->minimumWidth() * cache->zoom() / 2;
48
ty = layout->boundingRect().height() * cache->zoom() / 2;
54
tx = shape->size().width() * cache->zoom() / 2;
55
ty = shape->size().height() * cache->zoom() / 2;
57
transform.translate(tx, ty).rotate(value).translate(-tx, -ty);
58
cache->update(shape, shapeAnimation->textBlockData(),"transform", transform);
61
void KPrAttributeRotate::initCache(KPrAnimationCache *animationCache, int step, KPrShapeAnimation * shapeAnimation, qreal startValue, qreal endValue)
63
qreal tx = 0.0, ty = 0.0;
64
KoShape * shape = shapeAnimation->shape();
65
KoTextBlockData * textBlockData = shapeAnimation->textBlockData();
67
if (KoTextShapeData *textShapeData = dynamic_cast<KoTextShapeData*>(shape->userData())) {
68
QTextDocument *textDocument = textShapeData->document();
69
for (int i = 0; i < textDocument->blockCount(); i++) {
70
QTextBlock textBlock = textDocument->findBlockByNumber(i);
71
if (textBlock.userData() == textBlockData) {
72
QTextLayout *layout = textBlock.layout();
73
tx = layout->minimumWidth() * animationCache->zoom() / 2;
74
ty = layout->boundingRect().height() * animationCache->zoom() / 2;
80
tx = shape->size().width() * animationCache->zoom() / 2;
81
ty = shape->size().height() * animationCache->zoom() / 2;
83
animationCache->init(step, shape, textBlockData, "transform", QTransform().translate(tx, ty).rotate(startValue).translate(-tx, -ty));
84
animationCache->init(step + 1, shape, textBlockData, "transform", QTransform().translate(tx, ty).rotate(endValue).translate(-tx, -ty));