1 /* This file is part of the KDE project
2 * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net>
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 "CornersInWipeStrategy.h"
21 #include "FourBoxWipeEffectFactory.h"
22 #include <QWidget>
23 #include <QPainter>
24 #include <QPainterPath>
25 #include <QPainterPath>
26
27 const int StepCount = 250;
28
CornersInWipeStrategy(bool reverse)29 CornersInWipeStrategy::CornersInWipeStrategy( bool reverse )
30 : KPrPageEffectStrategy( reverse ? FourBoxWipeEffectFactory::CornersInReverse : FourBoxWipeEffectFactory::CornersIn, "fourBoxWipe", "cornersIn", reverse )
31 {
32 }
33
~CornersInWipeStrategy()34 CornersInWipeStrategy::~CornersInWipeStrategy()
35 {
36 }
37
setup(const KPrPageEffect::Data & data,QTimeLine & timeLine)38 void CornersInWipeStrategy::setup( const KPrPageEffect::Data &data, QTimeLine &timeLine )
39 {
40 Q_UNUSED( data );
41 timeLine.setFrameRange( 0, StepCount );
42 }
43
paintStep(QPainter & p,int currPos,const KPrPageEffect::Data & data)44 void CornersInWipeStrategy::paintStep( QPainter &p, int currPos, const KPrPageEffect::Data &data )
45 {
46 p.drawPixmap( QPoint( 0, 0 ), data.m_oldPage, data.m_widget->rect() );
47 p.setClipPath( clipPath( currPos, data.m_widget->rect() ) );
48 p.drawPixmap( QPoint( 0, 0 ), data.m_newPage, data.m_widget->rect() );
49 }
50
next(const KPrPageEffect::Data & data)51 void CornersInWipeStrategy::next( const KPrPageEffect::Data &data )
52 {
53 data.m_widget->update();
54 }
55
clipPath(int step,const QRect & area)56 QPainterPath CornersInWipeStrategy::clipPath( int step, const QRect &area )
57 {
58 int width_2 = area.width() >> 1;
59 int height_2 = area.height() >> 1;
60
61 qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount);
62 int stepx = static_cast<int>( width_2 * percent );
63 int stepy = static_cast<int>( height_2 * percent );
64
65 QPainterPath path;
66
67 if( ! reverse() )
68 {
69 QSize rectSize( stepx, stepy );
70
71 QRect topLeft( area.topLeft(), rectSize );
72 QRect topRight( area.topRight() - QPoint( stepx, 0 ), rectSize );
73 QRect bottomRight( area.bottomRight() - QPoint( stepx, stepy), rectSize );
74 QRect bottomLeft( area.bottomLeft() - QPoint( 0, stepy ), rectSize );
75
76 path.addRect( topLeft );
77 path.addRect( topRight );
78 path.addRect( bottomRight );
79 path.addRect( bottomLeft );
80 }
81 else
82 {
83 QRect horzRect( QPoint( 0, 0 ), QSize( 2 * stepx, area.height() ) );
84 horzRect.moveCenter( area.center() );
85 QRect vertRect( QPoint( 0, 0 ), QSize( area.width(), 2 * stepy ) );
86 vertRect.moveCenter( area.center() );
87
88 path.addRect( horzRect );
89 path.addRect( vertRect );
90 path.setFillRule( Qt::WindingFill );
91 }
92
93 return path;
94 }
95