1 /* This file is part of the KDE project
2 *
3 * Copyright (C) 2010 Thorsten Zachmann <zachmann@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "KPrFadeOverColorStrategy.h"
22 #include "KPrFadeEffectFactory.h"
23
24 #include <QWidget>
25 #include <QPainter>
26 #include <QGraphicsPixmapItem>
27 #include <QGraphicsView>
28
29 #include <KoXmlNS.h>
30 #include <KoXmlReader.h>
31 #include <KoXmlWriter.h>
32 #include <KoGenStyle.h>
33
34
KPrFadeOverColorStrategy()35 KPrFadeOverColorStrategy::KPrFadeOverColorStrategy()
36 : KPrPageEffectStrategy(KPrFadeEffectFactory::FadeOverColor, "fade", "fadeOverColor", false, true)
37 , m_fadeColor(Qt::black)
38 {
39 }
40
~KPrFadeOverColorStrategy()41 KPrFadeOverColorStrategy::~KPrFadeOverColorStrategy()
42 {
43 }
44
setup(const KPrPageEffect::Data & data,QTimeLine & timeLine)45 void KPrFadeOverColorStrategy::setup(const KPrPageEffect::Data &data, QTimeLine &timeLine)
46 {
47 timeLine.setFrameRange(0, 1000); // TODO might not be needed
48 data.m_graphicsView->setBackgroundBrush(m_fadeColor);
49 data.m_oldPageItem->setZValue(1);
50 data.m_newPageItem->setZValue(2);
51 data.m_newPageItem->setOpacity(0);
52 data.m_oldPageItem->show();
53 data.m_newPageItem->show();
54 }
55
paintStep(QPainter & p,int currPos,const KPrPageEffect::Data & data)56 void KPrFadeOverColorStrategy::paintStep(QPainter &p, int currPos, const KPrPageEffect::Data &data)
57 {
58 Q_UNUSED(p);
59 Q_UNUSED(currPos);
60 Q_UNUSED(data);
61 }
62
next(const KPrPageEffect::Data & data)63 void KPrFadeOverColorStrategy::next(const KPrPageEffect::Data &data)
64 {
65 int frame = data.m_timeLine.frameForTime(data.m_currentTime);
66 if (frame >= data.m_timeLine.endFrame()) {
67 finish(data);
68 }
69 else {
70 qreal value = 1 - (data.m_timeLine.valueForTime(data.m_currentTime) * qreal(2.0));
71 if (value >= 0) {
72 data.m_oldPageItem->setOpacity(value);
73 }
74 else {
75 data.m_oldPageItem->hide();
76 data.m_newPageItem->setOpacity(-value);
77 }
78 }
79 }
80
finish(const KPrPageEffect::Data & data)81 void KPrFadeOverColorStrategy::finish(const KPrPageEffect::Data &data)
82 {
83 data.m_graphicsView->hide();
84 }
85
saveOdfSmilAttributes(KoXmlWriter & xmlWriter) const86 void KPrFadeOverColorStrategy::saveOdfSmilAttributes(KoXmlWriter & xmlWriter) const
87 {
88 KPrPageEffectStrategy::saveOdfSmilAttributes(xmlWriter);
89 xmlWriter.addAttribute("smil:fadeColor", m_fadeColor.name());
90 }
91
saveOdfSmilAttributes(KoGenStyle & style) const92 void KPrFadeOverColorStrategy::saveOdfSmilAttributes(KoGenStyle & style) const
93 {
94 KPrPageEffectStrategy::saveOdfSmilAttributes(style);
95 style.addProperty("smil:fadeColor", m_fadeColor.name());
96 }
97
loadOdfSmilAttributes(const KoXmlElement & element)98 void KPrFadeOverColorStrategy::loadOdfSmilAttributes(const KoXmlElement & element)
99 {
100 // use black as default
101 m_fadeColor.setNamedColor(element.attributeNS(KoXmlNS::smil, "fadeColor", "#000000"));
102 }
103