~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

Viewing changes to kpresenter/part/animations/KPrAnimate.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
1
/* This file is part of the KDE project
2
2
 * Copyright (C) 2010 Thorsten Zachmann <zachmann@kde.org>
 
3
 * Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com>
3
4
 *
4
5
 * This library is free software; you can redistribute it and/or
5
6
 * modify it under the terms of the GNU Library General Public
20
21
#include "KPrAnimate.h"
21
22
 
22
23
#include "KPrAnimationCache.h"
23
 
 
24
 
KPrAnimate::KPrAnimate()
 
24
#include <KoXmlNS.h>
 
25
#include <KoXmlReader.h>
 
26
#include <KoShapeLoadingContext.h>
 
27
#include <KoShapeSavingContext.h>
 
28
#include <KoTextBlockData.h>
 
29
#include <KoShapeLoadingContext.h>
 
30
#include <KoShapeSavingContext.h>
 
31
#include <KoXmlReader.h>
 
32
#include "KoXmlWriter.h"
 
33
 
 
34
#include "KPrAnimationCache.h"
 
35
#include "KPrShapeAnimation.h"
 
36
 
 
37
#include "strategy/KPrSmilValues.h"
 
38
#include "strategy/KPrAnimationValue.h"
 
39
#include "strategy/KPrAnimationAttribute.h"
 
40
#include "strategy/KPrAttributeX.h"
 
41
#include "strategy/KPrAttributeY.h"
 
42
#include "strategy/KPrAttributeWidth.h"
 
43
#include "strategy/KPrAttributeHeight.h"
 
44
#include "strategy/KPrAttributeRotate.h"
 
45
 
 
46
#include "KoShape.h"
 
47
#include <kdebug.h>
 
48
 
 
49
KPrAnimate::KPrAnimate(KPrShapeAnimation *shapeAnimation)
 
50
: KPrAnimationBase(shapeAnimation)
 
51
,m_attribute(0)
 
52
,m_values(0)
25
53
{
26
54
}
27
55
 
28
56
KPrAnimate::~KPrAnimate()
29
57
{
 
58
    if(m_attribute)
 
59
        delete m_attribute;
 
60
    if(m_values)
 
61
        delete m_values;
30
62
}
31
63
 
32
64
bool KPrAnimate::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context)
33
65
{
34
 
    Q_UNUSED(element);
35
 
    Q_UNUSED(context);
36
 
    return true;
37
 
}
38
 
 
39
 
void KPrAnimate::saveOdf(KoShapeSavingContext &context) const
40
 
{
41
 
    Q_UNUSED(context);
42
 
}
43
 
 
44
 
void KPrAnimate::init(KPrAnimationCache *animationCache) const
45
 
{
46
 
    Q_UNUSED(animationCache);
 
66
    KPrAnimationBase::loadOdf(element, context);
 
67
    bool retval = true;
 
68
    // attributeName
 
69
    QString attributeName(element.attributeNS(KoXmlNS::smil, "attributeName", QString()));
 
70
    if (attributeName == "x") {
 
71
        m_attribute = new KPrAttributeX();
 
72
    }
 
73
    else if (attributeName == "y") {
 
74
        m_attribute = new KPrAttributeY();
 
75
    }
 
76
    else if (attributeName == "width") {
 
77
        m_attribute = new KPrAttributeWidth();
 
78
    }
 
79
    else if (attributeName == "height") {
 
80
        m_attribute = new KPrAttributeHeight();
 
81
    }
 
82
    else if (attributeName == "rotate") {
 
83
        m_attribute = new KPrAttributeRotate();
 
84
    }
 
85
    else {
 
86
        kWarning(33003) << "attributeName" << attributeName << "not yet supported";
 
87
        retval = false;
 
88
    }
 
89
 
 
90
    if (!retval){
 
91
        return false;
 
92
    }
 
93
 
 
94
    // calcMode
 
95
    KPrAnimationValue::SmilCalcMode smilCalcMode = KPrAnimationValue::linear;
 
96
    QString calcMode = element.attributeNS(KoXmlNS::smil, "calcMode", "linear");
 
97
    if(calcMode == "linear"){
 
98
        smilCalcMode = KPrAnimationValue::linear;
 
99
    } else if (calcMode == "discrete") {
 
100
        smilCalcMode = KPrAnimationValue::discrete;
 
101
        kWarning(33003) << "calcMode discrete not yes supported";
 
102
        retval = false;
 
103
    } else if (calcMode == "paced") {
 
104
        smilCalcMode = KPrAnimationValue::paced;
 
105
        kWarning(33003) << "calcMode paced not yes supported";
 
106
        retval = false;
 
107
    } else if (calcMode == "spline") {
 
108
        smilCalcMode = KPrAnimationValue::spline;
 
109
        kWarning(33003) << "calcMode spline not yes supported";
 
110
        retval = false;
 
111
    }
 
112
 
 
113
 
 
114
    // value
 
115
    QString formula = element.attributeNS(KoXmlNS::anim, "formula", QString());
 
116
    if (!formula.isEmpty()) {
 
117
        kWarning(33003) << "formula not yes supported";
 
118
        retval = false;
 
119
    }
 
120
    else {
 
121
        QString values = element.attributeNS(KoXmlNS::smil, "values", QString());
 
122
        if (!values.isEmpty()) {
 
123
            QString keyTimes = element.attributeNS(KoXmlNS::smil, "keyTimes", QString());
 
124
            QString keySplines = element.attributeNS(KoXmlNS::smil, "keySplines", QString());
 
125
            KPrSmilValues * smilValue = new KPrSmilValues(m_shapeAnimation);
 
126
            retval = retval && smilValue->loadValues(values, keyTimes, keySplines, smilCalcMode);
 
127
            m_values = smilValue;
 
128
        }
 
129
        else {
 
130
            QString from = element.attributeNS(KoXmlNS::smil, "from", "0");
 
131
            QString to = element.attributeNS(KoXmlNS::smil, "to", "0");
 
132
            QString by = element.attributeNS(KoXmlNS::smil, "by", "0");
 
133
            kWarning(33003) << "from to by not yes supported";
 
134
            retval = false;
 
135
        }
 
136
    }
 
137
    return retval;
 
138
}
 
139
 
 
140
bool KPrAnimate::saveOdf(KoPASavingContext & paContext) const
 
141
{
 
142
    KoXmlWriter &writer = paContext.xmlWriter();
 
143
    writer.startElement("anim:animate");
 
144
    saveAttribute(paContext);
 
145
    writer.endElement();
 
146
    return true;
 
147
}
 
148
 
 
149
void KPrAnimate::init(KPrAnimationCache *animationCache, int step)
 
150
{
 
151
    m_animationCache = animationCache;
 
152
    m_values->setCache(m_animationCache);
 
153
    m_attribute->initCache(animationCache, step, m_shapeAnimation, m_values->startValue(), m_values->endValue());
 
154
}
 
155
 
 
156
void KPrAnimate::next(int currentTime)
 
157
{
 
158
    qreal value = m_values->value(qreal(currentTime)/qreal(animationDuration()));
 
159
    m_attribute->updateCache(m_animationCache, m_shapeAnimation, value);
 
160
}
 
161
 
 
162
bool KPrAnimate::saveAttribute(KoPASavingContext &paContext) const
 
163
{
 
164
    KPrAnimationBase::saveAttribute(paContext);
 
165
    KoXmlWriter &writer = paContext.xmlWriter();
 
166
    writer.addAttribute("smil:attributeName", m_attribute->attributeName());
 
167
    m_values->saveOdf(paContext);
 
168
    return true;
47
169
}