21#include "KoPictureImage.h"
22#include "KoPictureKey.h"
31#include <tqapplication.h>
32#include <tqdragobject.h>
34KoPictureImage::KoPictureImage(
void) : m_cacheIsInFastMode(true)
37 m_cachedPixmap.setOptimization(TQPixmap::MemoryOptim);
40KoPictureImage::~KoPictureImage(
void)
44KoPictureBase* KoPictureImage::newCopy(
void)
const
46 return new KoPictureImage(*
this);
49KoPictureType::Type KoPictureImage::getType(
void)
const
51 return KoPictureType::TypeImage;
54bool KoPictureImage::isNull(
void)
const
56 return m_originalImage.isNull();
59void KoPictureImage::scaleAndCreatePixmap(
const TQSize& size,
bool fastMode)
61 if ((size==m_cachedSize)
62 && ((fastMode) || (!m_cacheIsInFastMode)))
72 if ( !isSlowResizeModeAllowed() )
74 kdDebug(30003) <<
"User has disallowed slow mode!" << endl;
81 m_cachedPixmap.convertFromImage(m_originalImage.scale( size ), TQPixmap::Color);
82 m_cacheIsInFastMode=
true;
86 m_cachedPixmap.convertFromImage(m_originalImage.smoothScale( size ), TQPixmap::Color);
87 m_cacheIsInFastMode=
false;
92void KoPictureImage::draw(TQPainter& painter,
int x,
int y,
int width,
int height,
int sx,
int sy,
int sw,
int sh,
bool fastMode)
95 if ( !width || !height )
97 TQSize origSize = getOriginalSize();
98 const bool scaleImage = painter.device()->isExtDev()
99 && ((width <= origSize.width()) || (height <= origSize.height()));
103 double xScale = double(width) / double(origSize.width());
104 double yScale = double(height) / double(origSize.height());
107 painter.translate( x, y );
108 painter.scale( xScale, yScale );
112 painter.drawImage(0, 0, m_originalImage);
117 TQSize screenSize( width, height );
120 scaleAndCreatePixmap(screenSize, fastMode);
124 painter.drawPixmap( x + sx, y + sy, m_cachedPixmap, sx, sy, sw, sh );
128bool KoPictureImage::loadData(
const TQByteArray& array,
const TQString& )
132 TQBuffer buffer(m_rawData);
133 buffer.open(IO_ReadWrite);
134 TQImageIO imageIO(&buffer,NULL);
139 kdError(30003) <<
"Image could not be loaded!" << endl;
143 m_originalImage=imageIO.image();
148bool KoPictureImage::save(TQIODevice* io)
const
150 kdDebug() << k_funcinfo <<
"writing raw data. size=" << m_rawData.size() << endl;
152 TQ_ULONG size=io->writeBlock(m_rawData);
153 return (size==m_rawData.size());
156TQSize KoPictureImage::getOriginalSize(
void)
const
158 return m_originalImage.size();
161TQPixmap KoPictureImage::generatePixmap(
const TQSize& size,
bool smoothScale)
163 scaleAndCreatePixmap(size,!smoothScale);
164 return m_cachedPixmap;
167TQString KoPictureImage::getMimeType(
const TQString& extension)
const
169 TQString fileName(
"/tmp/temp.");
172 const TQString mimetype( KMimeType::findByPath( fileName, 0 ,
true )->
name() );
174 kdDebug(30003) <<
"Image is mime type: " << mimetype << endl;
178TQDragObject* KoPictureImage::dragObject( TQWidget *dragSource,
const char *name )
180 return new TQImageDrag( m_originalImage, dragSource, name );
183TQImage KoPictureImage::generateImage(
const TQSize& size)
186 return m_originalImage.smoothScale( size );
189void KoPictureImage::clearCache(
void)
191 m_cachedPixmap.resize(0, 0);
192 m_cacheIsInFastMode=
true;
193 m_cachedSize=TQSize();
const char * name(StdAction id)