kpresenter

KPrPartObject.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2005 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 "KPrPartObject.h"
22#include "KPrDocument.h"
23#include "KPrView.h"
24#include "KPrGradient.h"
25#include <KoDom.h>
26#include <KoXmlNS.h>
27#include "KoOasisContext.h"
28#include <tdeparts/partmanager.h>
29
30#include <tqpainter.h>
31#include <kdebug.h>
32using namespace std;
33
34KPrPartObject::KPrPartObject( KPrChild *_child )
35 : KPr2DObject()
36{
37 child = _child;
38 pen = KoPen( TQt::black, 1.0, TQt::NoPen );
39 _enableDrawing = true;
40}
41
42KPrPartObject &KPrPartObject::operator=( const KPrPartObject & )
43{
44 return *this;
45}
46
47void KPrPartObject::updateChildGeometry()
48{
49 KoTextZoomHandler* zh = child->parent()->zoomHandler();
50 child->setGeometry( zh->zoomRect( getRect() ), true );
51 child->setRotationPoint( TQPoint( zh->zoomItX( getOrig().x() + getSize().width() / 2 ),
52 zh->zoomItY( getOrig().y() + getSize().height() / 2 ) ) );
53}
54
55void KPrPartObject::rotate( float _angle )
56{
57 KPrObject::rotate( _angle );
58
59 child->setRotation( _angle );
60 KoTextZoomHandler* zh = child->parent()->zoomHandler();
61 child->setRotationPoint( TQPoint( zh->zoomItX( getOrig().x() + getSize().width() / 2 ),
62 zh->zoomItY( getOrig().y() + getSize().height() / 2 ) ) );
63}
64
65bool KPrPartObject::saveOasisObjectAttributes( KPOasisSaveContext &sc ) const
66{
67 kdDebug() << "KPrPartObject::saveOasisPart " << sc.partIndexObj << endl;
68
69 sc.xmlWriter.startElement( "draw:object" );
70 const TQString name = TQString( "Object_%1" ).arg( sc.partIndexObj + 1 );
71 ++sc.partIndexObj;
72 child->saveOasisAttributes( sc.xmlWriter, name );
73
74 sc.xmlWriter.endElement();
75 return true;
76}
77
78const char * KPrPartObject::getOasisElementName() const
79{
80 return "draw:frame";
81}
82
83
84void KPrPartObject::loadOasis(const TQDomElement &element, KoOasisContext&context, KPrLoadingInfo */*info*/)
85{
86 kdDebug()<<"void KPrPartObject::loadOasis(const TQDomElement &element)******************\n";
87
88 TQDomElement objectElement = KoDom::namedItemNS( element, KoXmlNS::draw, "object" );
89 child->loadOasis( element, objectElement );
90 if(element.hasAttributeNS( KoXmlNS::draw, "name" ))
91 KPrObject::objectName = element.attributeNS( KoXmlNS::draw, "name", TQString());
92 (void)child->loadOasisDocument( context.store(), context.manifestDocument() );
93}
94
95void KPrPartObject::draw( TQPainter *_painter, KoTextZoomHandler *_zoomhandler,
96 int pageNum, SelectionMode selectionMode, bool drawContour )
97{
98 updateChildGeometry();
99 double ow = ext.width();
100 double oh = ext.height();
101
102 TQSize size( _zoomhandler->zoomSize( ext ) );
103 int penw = ( ( pen.style() == TQt::NoPen ) ? 1 : int( pen.pointWidth() ) ) / 2;
104
105 TQPen pen2;
106 if ( drawContour )
107 pen2 = TQPen( TQt::black, 1, TQt::NoPen );
108 else {
109 pen2 = pen.zoomedPen( _zoomhandler );
110 }
111 _painter->save();
112 child->transform( *_painter );
113 _painter->setPen( TQt::NoPen );
114 _painter->setBrush( getBrush() );
115
116 if ( angle == 0 ) {
117 if ( getFillType() == FT_BRUSH || !gradient )
118 _painter->drawRect( penw, penw, _zoomhandler->zoomItX( ext.width() - 2 * penw ),
119 _zoomhandler->zoomItY( ext.height() - 2 * penw ) );
120 else {
121 gradient->setSize( size );
122 _painter->drawPixmap( penw, penw, gradient->pixmap(), 0, 0,
123 _zoomhandler->zoomItX( ow - 2 * penw ),
124 _zoomhandler->zoomItY( oh - 2 * penw ) );
125 }
126 }
127 else
128 {
129 if ( getFillType() == FT_BRUSH || !gradient )
130 _painter->drawRect( _zoomhandler->zoomItX( penw ), _zoomhandler->zoomItY( penw ),
131 _zoomhandler->zoomItX( ext.width() - 2 * penw ),
132 _zoomhandler->zoomItY( ext.height() - 2 * penw ) );
133 else {
134 gradient->setSize( size );
135 _painter->drawPixmap( penw, penw, gradient->pixmap(), 0, 0,
136 _zoomhandler->zoomItX( ow - 2 * penw ),
137 _zoomhandler->zoomItY( oh - 2 * penw ) );
138 }
139 }
140
141 _painter->setPen( pen2 );
142 _painter->setBrush( TQt::NoBrush );
143 _painter->drawRect( _zoomhandler->zoomItX( penw ), _zoomhandler->zoomItY( penw ),
144 _zoomhandler->zoomItX( ow - 2 * penw ), _zoomhandler->zoomItY( oh - 2 * penw ) );
145 paint( _painter, _zoomhandler, pageNum, selectionMode, drawContour );
146 _painter->restore();
147
148 KPrObject::draw( _painter, _zoomhandler, pageNum, selectionMode, drawContour );
149}
150
151void KPrPartObject::slot_changed( KoChild *_koChild )
152{
153 KoTextZoomHandler* zh = child->parent()->zoomHandler();
154 KoRect g = zh->unzoomRect( _koChild->geometry() );
155 KPrObject::setOrig( g.x(), g.y() );
156 KPrObject::setSize( g.width(), g.height() );
157}
158
159void KPrPartObject::paint( TQPainter *_painter, KoTextZoomHandler *_zoomHandler,
160 int /* pageNum */, bool /*drawingShadow*/, bool drawContour )
161{
162 if ( !_enableDrawing ) return;
163
164 if ( drawContour ) {
165 TQPen pen3( TQt::black, 1, TQt::DotLine );
166 _painter->setPen( pen3 );
167 _painter->setRasterOp( TQt::NotXorROP );
168 _painter->drawRect( _zoomHandler->zoomRect( KoRect( KoPoint( 0.0, 0.0 ), getSize() ) ) );
169 return;
170 }
171
172 if ( !child || !child->document() )
173 return;
174
175 int penw = ( pen.style() == TQt::NoPen ) ? 0 : int( pen.pointWidth() );
176 KoRect r( KoPoint( penw, penw ), KoPoint( getSize().width() - ( penw * 2.0 ),
177 getSize().height() - ( penw * 2.0 ) ) );
178 double zoomX = static_cast<double>( _zoomHandler->zoom() ) / 100;
179 double zoomY = static_cast<double>( _zoomHandler->zoom() ) / 100;
180 child->document()->paintEverything( *_painter,
181 _zoomHandler->zoomRect( r ),
182 true, // flicker?
183 0 /* View isn't known from here - is that a problem? */,
184 zoomX,
185 zoomY );
186}
187
188void KPrPartObject::activate( TQWidget *_widget )
189{
190 KPrView *view = dynamic_cast<KPrView*>( _widget );
191 KoDocument* part = child->document();
192 if ( !part )
193 return;
194 view->partManager()->addPart( part, false );
195 view->partManager()->setActivePart( part, view );
196}
197
198void KPrPartObject::deactivate()
199{
200}
201
202#include "KPrPartObject.moc"
Temporary information used only during loading.