~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kpresenter/part/animations/strategy/KPrAttributeRotate.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
 * Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include "KPrAttributeRotate.h"
 
21
#include "../KPrAnimationCache.h"
 
22
#include "KoShape.h"
 
23
#include "KPrShapeAnimations.h"
 
24
#include "KoTextBlockData.h"
 
25
#include "KoTextShapeData.h"
 
26
#include <QTextDocument>
 
27
#include <QTextLayout>
 
28
#include "kdebug.h"
 
29
 
 
30
KPrAttributeRotate::KPrAttributeRotate() : KPrAnimationAttribute("rotate")
 
31
{
 
32
}
 
33
 
 
34
void KPrAttributeRotate::updateCache(KPrAnimationCache *cache, KPrShapeAnimation *shapeAnimation, qreal value)
 
35
{
 
36
    qreal tx = 0.0, ty = 0.0;
 
37
    KoShape * shape = shapeAnimation->shape();
 
38
    KoTextBlockData * textBlockData = shapeAnimation->textBlockData();
 
39
    QTransform transform;
 
40
    if (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;
 
49
                }
 
50
            }
 
51
        }
 
52
    }
 
53
    else {
 
54
        tx = shape->size().width() * cache->zoom() / 2;
 
55
        ty = shape->size().height() * cache->zoom() / 2;
 
56
    }
 
57
    transform.translate(tx, ty).rotate(value).translate(-tx, -ty);
 
58
    cache->update(shape, shapeAnimation->textBlockData(),"transform", transform);
 
59
}
 
60
 
 
61
void KPrAttributeRotate::initCache(KPrAnimationCache *animationCache, int step, KPrShapeAnimation * shapeAnimation, qreal startValue, qreal endValue)
 
62
{
 
63
    qreal tx = 0.0, ty = 0.0;
 
64
    KoShape * shape = shapeAnimation->shape();
 
65
    KoTextBlockData * textBlockData = shapeAnimation->textBlockData();
 
66
    if (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;
 
75
                }
 
76
            }
 
77
        }
 
78
    }
 
79
    else {
 
80
        tx = shape->size().width() * animationCache->zoom() / 2;
 
81
        ty = shape->size().height() * animationCache->zoom() / 2;
 
82
    }
 
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));
 
85
}