1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/* This file is part of the KDE project
Copyright (C) 1998, 1999 Reginald Stadlbauer <[email protected]>
Copyright (C) 2005 Thorsten Zachmann <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KPrPartObject.h"
#include "KPrDocument.h"
#include "KPrView.h"
#include "KPrGradient.h"
#include <KoDom.h>
#include <KoXmlNS.h>
#include "KoOasisContext.h"
#include <tdeparts/partmanager.h>
#include <tqpainter.h>
#include <kdebug.h>
using namespace std;
KPrPartObject::KPrPartObject( KPrChild *_child )
: KPr2DObject()
{
child = _child;
pen = KoPen( TQt::black, 1.0, Qt::NoPen );
_enableDrawing = true;
}
KPrPartObject &KPrPartObject::operator=( const KPrPartObject & )
{
return *this;
}
void KPrPartObject::updateChildGeometry()
{
KoTextZoomHandler* zh = child->parent()->zoomHandler();
child->setGeometry( zh->zoomRect( getRect() ), true );
child->setRotationPoint( TQPoint( zh->zoomItX( getOrig().x() + getSize().width() / 2 ),
zh->zoomItY( getOrig().y() + getSize().height() / 2 ) ) );
}
void KPrPartObject::rotate( float _angle )
{
KPrObject::rotate( _angle );
child->setRotation( _angle );
KoTextZoomHandler* zh = child->parent()->zoomHandler();
child->setRotationPoint( TQPoint( zh->zoomItX( getOrig().x() + getSize().width() / 2 ),
zh->zoomItY( getOrig().y() + getSize().height() / 2 ) ) );
}
bool KPrPartObject::saveOasisObjectAttributes( KPOasisSaveContext &sc ) const
{
kdDebug() << "KPrPartObject::saveOasisPart " << sc.partIndexObj << endl;
sc.xmlWriter.startElement( "draw:object" );
const TQString name = TQString( "Object_%1" ).arg( sc.partIndexObj + 1 );
++sc.partIndexObj;
child->saveOasisAttributes( sc.xmlWriter, name );
sc.xmlWriter.endElement();
return true;
}
const char * KPrPartObject::getOasisElementName() const
{
return "draw:frame";
}
void KPrPartObject::loadOasis(const TQDomElement &element, KoOasisContext&context, KPrLoadingInfo */*info*/)
{
kdDebug()<<"void KPrPartObject::loadOasis(const TQDomElement &element)******************\n";
TQDomElement objectElement = KoDom::namedItemNS( element, KoXmlNS::draw, "object" );
child->loadOasis( element, objectElement );
if(element.hasAttributeNS( KoXmlNS::draw, "name" ))
KPrObject::objectName = element.attributeNS( KoXmlNS::draw, "name", TQString());
(void)child->loadOasisDocument( context.store(), context.manifestDocument() );
}
void KPrPartObject::draw( TQPainter *_painter, KoTextZoomHandler *_zoomhandler,
int pageNum, SelectionMode selectionMode, bool drawContour )
{
updateChildGeometry();
double ow = ext.width();
double oh = ext.height();
TQSize size( _zoomhandler->zoomSize( ext ) );
int penw = ( ( pen.style() == TQt::NoPen ) ? 1 : int( pen.pointWidth() ) ) / 2;
TQPen pen2;
if ( drawContour )
pen2 = TQPen( TQt::black, 1, TQt::NoPen );
else {
pen2 = pen.zoomedPen( _zoomhandler );
}
_painter->save();
child->transform( *_painter );
_painter->setPen( TQt::NoPen );
_painter->setBrush( getBrush() );
if ( angle == 0 ) {
if ( getFillType() == FT_BRUSH || !gradient )
_painter->drawRect( penw, penw, _zoomhandler->zoomItX( ext.width() - 2 * penw ),
_zoomhandler->zoomItY( ext.height() - 2 * penw ) );
else {
gradient->setSize( size );
_painter->drawPixmap( penw, penw, gradient->pixmap(), 0, 0,
_zoomhandler->zoomItX( ow - 2 * penw ),
_zoomhandler->zoomItY( oh - 2 * penw ) );
}
}
else
{
if ( getFillType() == FT_BRUSH || !gradient )
_painter->drawRect( _zoomhandler->zoomItX( penw ), _zoomhandler->zoomItY( penw ),
_zoomhandler->zoomItX( ext.width() - 2 * penw ),
_zoomhandler->zoomItY( ext.height() - 2 * penw ) );
else {
gradient->setSize( size );
_painter->drawPixmap( penw, penw, gradient->pixmap(), 0, 0,
_zoomhandler->zoomItX( ow - 2 * penw ),
_zoomhandler->zoomItY( oh - 2 * penw ) );
}
}
_painter->setPen( pen2 );
_painter->setBrush( TQt::NoBrush );
_painter->drawRect( _zoomhandler->zoomItX( penw ), _zoomhandler->zoomItY( penw ),
_zoomhandler->zoomItX( ow - 2 * penw ), _zoomhandler->zoomItY( oh - 2 * penw ) );
paint( _painter, _zoomhandler, pageNum, selectionMode, drawContour );
_painter->restore();
KPrObject::draw( _painter, _zoomhandler, pageNum, selectionMode, drawContour );
}
void KPrPartObject::slot_changed( KoChild *_koChild )
{
KoTextZoomHandler* zh = child->parent()->zoomHandler();
KoRect g = zh->unzoomRect( _koChild->geometry() );
KPrObject::setOrig( g.x(), g.y() );
KPrObject::setSize( g.width(), g.height() );
}
void KPrPartObject::paint( TQPainter *_painter, KoTextZoomHandler *_zoomHandler,
int /* pageNum */, bool /*drawingShadow*/, bool drawContour )
{
if ( !_enableDrawing ) return;
if ( drawContour ) {
TQPen pen3( TQt::black, 1, TQt::DotLine );
_painter->setPen( pen3 );
_painter->setRasterOp( TQt::NotXorROP );
_painter->drawRect( _zoomHandler->zoomRect( KoRect( KoPoint( 0.0, 0.0 ), getSize() ) ) );
return;
}
if ( !child || !child->document() )
return;
int penw = ( pen.style() == TQt::NoPen ) ? 0 : int( pen.pointWidth() );
KoRect r( KoPoint( penw, penw ), KoPoint( getSize().width() - ( penw * 2.0 ),
getSize().height() - ( penw * 2.0 ) ) );
double zoomX = static_cast<double>( _zoomHandler->zoom() ) / 100;
double zoomY = static_cast<double>( _zoomHandler->zoom() ) / 100;
child->document()->paintEverything( *_painter,
_zoomHandler->zoomRect( r ),
true, // flicker?
0 /* View isn't known from here - is that a problem? */,
zoomX,
zoomY );
}
void KPrPartObject::activate( TQWidget *_widget )
{
KPrView *view = dynamic_cast<KPrView*>( _widget );
KoDocument* part = child->document();
if ( !part )
return;
view->partManager()->addPart( part, false );
view->partManager()->setActivePart( part, view );
}
void KPrPartObject::deactivate()
{
}
#include "KPrPartObject.moc"
|