22#include <KoPictureCollection.h>
24#include "KWDocument.h"
26#include "KWTextFrameSet.h"
28#include "KWTextImage.h"
31 : KoTextCustomItem( textdoc ), place( PlaceInline )
33 KWDocument * doc = textdoc->
textFrameSet()->kWordDocument();
34 if ( !filename.isEmpty() )
36 m_image = doc->pictureCollection()->loadPicture( filename );
37 Q_ASSERT( !m_image.isNull() );
42void KWTextImage::setImage(
const KoPictureCollection & collection )
44 kdDebug(32001) <<
"Loading text image " << m_image.getKey().toString() <<
" (in KWTextImage::setImage)" << endl;
45 m_image=collection.findPicture( m_image.getKey() );
46 Q_ASSERT( !m_image.isNull() );
47 kdDebug(32001) <<
"size: " << m_image.getOriginalSize().width() <<
"x" << m_image.getOriginalSize().height() << endl;
51void KWTextImage::resize()
55 if ( !m_image.isNull() ) {
57 width = m_image.getOriginalSize().width();
59 width = KoTextZoomHandler::ptToLayoutUnitPt( width );
60 height = m_image.getOriginalSize().height();
61 height = KoTextZoomHandler::ptToLayoutUnitPt( height );
62 kdDebug() <<
"KWTextImage::resize: " << width <<
", " << height << endl;
67void KWTextImage::drawCustomItem( TQPainter* p,
int x,
int y,
int wpix,
int hpix,
int ,
int cx,
int cy,
int cw,
int ch,
const TQColorGroup& cg,
bool selected,
int ,
bool drawingShadow)
75 if ( m_image.isNull() ) {
76 kdDebug() <<
"KWTextImage::draw null image!" << endl;
77 p->fillRect( x, y, 50, 50, cg.dark() );
81 TQSize imgSize( wpix, hpix );
83 TQRect rect( TQPoint(x, y), imgSize );
84 if ( !rect.intersects( TQRect( cx, cy, cw, ch ) ) )
87 TQPixmap pixmap=m_image.generatePixmap( imgSize,
true );
89 p->drawPixmap( x, y, pixmap );
93 if ( selected && placement() == PlaceInline && p->device()->devType() != TQInternal::Printer ) {
94 p->fillRect( rect , TQBrush( cg.highlight(), TQBrush::Dense4Pattern) );
98void KWTextImage::save( TQDomElement & parentElem )
101 KWDocument * doc =
static_cast<KWTextDocument *
>(parent)->textFrameSet()->kWordDocument();
103 TQDomElement imageElem = parentElem.ownerDocument().createElement(
"PICTURE" );
104 parentElem.appendChild( imageElem );
106 TQDomElement elem = parentElem.ownerDocument().createElement(
"KEY" );
107 imageElem.appendChild( elem );
108 image().getKey().saveAttributes( elem );
110 doc->addTextImageRequest(
this );
113void KWTextImage::load( TQDomElement & parentElem )
116 KWDocument * doc =
static_cast<KWTextDocument *
>(parent)->textFrameSet()->kWordDocument();
119 TQDomNode node=parentElem.namedItem(
"PICTURE" );
122 node=parentElem.namedItem(
"IMAGE" );
124 TQDomElement image = node.toElement();
125 if ( image.isNull() )
128 TQDomElement keyElement = image.namedItem(
"KEY" ).toElement();
129 if ( !keyElement.isNull() )
132 key.loadAttributes( keyElement );
134 doc->addTextImageRequest(
this );
139 TQDomElement filenameElement = image.namedItem(
"FILENAME" ).toElement();
140 if ( !filenameElement.isNull() )
142 TQString filename = filenameElement.attribute(
"value" );
143 m_image.setKey( KoPictureKey( filename ) );
144 doc->addTextImageRequest(
this );
148 kdError(32001) <<
"Missing KEY or FILENAME tag in IMAGE (KWTextImage::load)" << endl;
155 return m_image.getKey();
158void KWTextImage::saveOasis( KoXmlWriter&, KoSavingContext& )
const
This is our KoTextDocument reimplementation, to create KWTextParag instead of KoTextParags,...
KWTextFrameSet * textFrameSet() const
Return the text frameset in which this document is.
KWTextImage(KWTextDocument *textdoc, const TQString &filename)
Set filename to load a real file from the disk Otherwise use setImage() - this is what's done on load...
KoPictureKey getKey(void) const
Get the key of the picture.