kword
KWTextImage.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <kdebug.h>
00021
00022 #include <KoPictureCollection.h>
00023
00024 #include "KWDocument.h"
00025 #include "defs.h"
00026 #include "KWTextFrameSet.h"
00027
00028 #include "KWTextImage.h"
00029
00030 KWTextImage::KWTextImage( KWTextDocument *textdoc, const QString & filename )
00031 : KoTextCustomItem( textdoc ), place( PlaceInline )
00032 {
00033 KWDocument * doc = textdoc->textFrameSet()->kWordDocument();
00034 if ( !filename.isEmpty() )
00035 {
00036 m_image = doc->pictureCollection()->loadPicture( filename );
00037 Q_ASSERT( !m_image.isNull() );
00038 resize();
00039 }
00040 }
00041
00042 void KWTextImage::setImage( const KoPictureCollection & collection )
00043 {
00044 kdDebug(32001) << "Loading text image " << m_image.getKey().toString() << " (in KWTextImage::setImage)" << endl;
00045 m_image=collection.findPicture( m_image.getKey() );
00046 Q_ASSERT( !m_image.isNull() );
00047 kdDebug(32001) << "size: " << m_image.getOriginalSize().width() << "x" << m_image.getOriginalSize().height() << endl;
00048 resize();
00049 }
00050
00051 void KWTextImage::resize()
00052 {
00053 if ( m_deleted )
00054 return;
00055 if ( !m_image.isNull() ) {
00056
00057 width = m_image.getOriginalSize().width();
00058
00059 width = KoTextZoomHandler::ptToLayoutUnitPt( width );
00060 height = m_image.getOriginalSize().height();
00061 height = KoTextZoomHandler::ptToLayoutUnitPt( height );
00062 kdDebug() << "KWTextImage::resize: " << width << ", " << height << endl;
00063
00064 }
00065 }
00066
00067 void KWTextImage::drawCustomItem( QPainter* p, int x, int y, int wpix, int hpix, int , int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected, int , bool drawingShadow)
00068 {
00069 if ( drawingShadow )
00070 return;
00071
00072
00073
00074
00075 if ( m_image.isNull() ) {
00076 kdDebug() << "KWTextImage::draw null image!" << endl;
00077 p->fillRect( x, y, 50, 50, cg.dark() );
00078 return;
00079 }
00080
00081 QSize imgSize( wpix, hpix );
00082
00083 QRect rect( QPoint(x, y), imgSize );
00084 if ( !rect.intersects( QRect( cx, cy, cw, ch ) ) )
00085 return;
00086
00087 QPixmap pixmap=m_image.generatePixmap( imgSize, true );
00088
00089 p->drawPixmap( x, y, pixmap );
00090
00091
00092
00093 if ( selected && placement() == PlaceInline && p->device()->devType() != QInternal::Printer ) {
00094 p->fillRect( rect , QBrush( cg.highlight(), QBrush::Dense4Pattern) );
00095 }
00096 }
00097
00098 void KWTextImage::save( QDomElement & parentElem )
00099 {
00100
00101 KWDocument * doc = static_cast<KWTextDocument *>(parent)->textFrameSet()->kWordDocument();
00102
00103 QDomElement imageElem = parentElem.ownerDocument().createElement( "PICTURE" );
00104 parentElem.appendChild( imageElem );
00105
00106 QDomElement elem = parentElem.ownerDocument().createElement( "KEY" );
00107 imageElem.appendChild( elem );
00108 image().getKey().saveAttributes( elem );
00109
00110 doc->addTextImageRequest( this );
00111 }
00112
00113 void KWTextImage::load( QDomElement & parentElem )
00114 {
00115
00116 KWDocument * doc = static_cast<KWTextDocument *>(parent)->textFrameSet()->kWordDocument();
00117
00118
00119 QDomNode node=parentElem.namedItem( "PICTURE" );
00120 if ( node.isNull() )
00121 {
00122 node=parentElem.namedItem( "IMAGE" );
00123 }
00124 QDomElement image = node.toElement();
00125 if ( image.isNull() )
00126 image = parentElem;
00127
00128 QDomElement keyElement = image.namedItem( "KEY" ).toElement();
00129 if ( !keyElement.isNull() )
00130 {
00131 KoPictureKey key;
00132 key.loadAttributes( keyElement );
00133 m_image.setKey(key);
00134 doc->addTextImageRequest( this );
00135 }
00136 else
00137 {
00138
00139 QDomElement filenameElement = image.namedItem( "FILENAME" ).toElement();
00140 if ( !filenameElement.isNull() )
00141 {
00142 QString filename = filenameElement.attribute( "value" );
00143 m_image.setKey( KoPictureKey( filename ) );
00144 doc->addTextImageRequest( this );
00145 }
00146 else
00147 {
00148 kdError(32001) << "Missing KEY or FILENAME tag in IMAGE (KWTextImage::load)" << endl;
00149 }
00150 }
00151 }
00152
00153 KoPictureKey KWTextImage::getKey( void ) const
00154 {
00155 return m_image.getKey();
00156 }
00157
00158 void KWTextImage::saveOasis( KoXmlWriter&, KoSavingContext& ) const
00159 {
00160
00161 }
|