diff -u killustrator/GClipart.cc ki/GClipart.cc --- killustrator/GClipart.cc Mon Jul 2 22:38:13 2001 +++ ki/GClipart.cc Mon Jul 16 14:00:37 2001 @@ -21,51 +21,59 @@ */ -#include +#include "GClipart.h" + #include #include -#include "GDocument.h" #include +#include + +#include "GDocument.h" GClipart::GClipart (GDocument *doc) :GObject(doc) { - - pic = 0L; + pix = 0L; } GClipart::GClipart (GDocument *doc, const QDomElement &element) : GObject (doc, element.namedItem("gobject").toElement()) { - url=element.attribute("src"); - QWinMetaFile wmf; - if (url.isLocalFile () && wmf.load (url.path ())) { - QRect r = wmf.bbox (); - width = (r.right () - r.left ()) * 72.0 / wmf.dpi (); - height = (r.bottom () - r.top ()) * 72.0 / wmf.dpi (); - pic = new QPicture (); - wmf.paint (pic); - } - else - // construct a malformed url - url = KURL (); - calcBoundingBox (); + url = element.attribute("src"); + QWinMetaFile wmf; + if(url.isLocalFile () && wmf.load (url.path ())) + { + QRect r = wmf.bbox (); + width = (r.right () - r.left ()) * 72.0 / wmf.dpi (); + height = (r.bottom () - r.top ()) * 72.0 / wmf.dpi (); + pix = new QPixmap(qRound(width),qRound(height)); + QPainter p(pix); + p.setBackgroundMode(TransparentMode); + p.eraseRect(0,0,qRound(width),qRound(height)); + wmf.paint (pix); + } + else + // construct a malformed url + url = KURL (); + calcBoundingBox (); } GClipart::GClipart (GDocument *doc, const QString &name) :GObject(doc) ,url (name) { - QWinMetaFile wmf; - wmf.load(name); - QRect r = wmf.bbox (); - - width = (r.right () - r.left ()) * 72.0 / wmf.dpi (); - height = (r.bottom () - r.top ()) * 72.0 / wmf.dpi (); - pic = new QPicture (); - wmf.paint (pic); - calcBoundingBox (); + QWinMetaFile wmf; + wmf.load(name); + QRect r = wmf.bbox (); + width = (r.right () - r.left ()) * 72.0 / wmf.dpi (); + height = (r.bottom () - r.top ()) * 72.0 / wmf.dpi (); + pix = new QPixmap(qRound(width),qRound(height)); + QPainter p(pix); + p.setBackgroundMode(TransparentMode); + p.eraseRect(0,0,qRound(width),qRound(height)); + wmf.paint (pix); + calcBoundingBox (); } GClipart::GClipart (const GClipart& obj) @@ -74,62 +82,60 @@ url = obj.url; width = obj.width; height = obj.height; + if (obj.pix) + pix = new QPixmap (*obj.pix); calcBoundingBox (); } -QString GClipart::typeName () const { +QString GClipart::typeName () const +{ return i18n("Clipart object"); } -void GClipart::draw (QPainter& p, bool /*withBasePoints*/, bool outline, bool) { +void GClipart::draw (QPainter& p, bool /*withBasePoints*/, bool outline, bool) +{ p.save (); - if (outline) { + p.setWorldMatrix (tmpMatrix, true); + if (outline) + { p.setPen (black); - p.drawRect (qRound (box.x ()), qRound (box.y ()), qRound (box.width ()), qRound (box.height ())); + p.drawRect (0, 0, qRound (width), qRound (height)); + int w5 = qRound (width / 5.0); + int h5 = qRound (height / 5.0); + p.drawLine (0, w5, w5, 0); + p.drawLine (qRound (width) - w5, qRound (height), qRound (width), qRound (height) - h5); } - else { - if (! url.isMalformed ()) { - p.setWorldMatrix (tmpMatrix, true); - QWMatrix mx = p.worldMatrix (); - QRect mr = mx.map (QRect (0, 0, qRound (width), qRound (height))); - QRect oldWin = p.window (); - QRect vPort = p.viewport (); - p.setViewport (mr); - p.setWorldMatrix (QWMatrix ()); - p.drawPicture (*pic); - p.setWindow (oldWin); - p.setViewport (vPort); - } - else { + else + { + if (pix != 0L) + p.drawPixmap (0, 0, *pix); + else + { p.setPen (gray); - p.fillRect (qRound (box.x ()), qRound (box.y ()), qRound (box.width ()), qRound (box.height ()), - gray); + p.fillRect (0, 0, qRound (width), qRound (height), gray); } } p.restore (); -} +} -void GClipart::calcBoundingBox () { +void GClipart::calcBoundingBox () +{ calcUntransformedBoundingBox (Coord (0, 0), Coord (width, 0), Coord (width, height), Coord (0, height)); } -GObject* GClipart::copy () { +GObject* GClipart::copy () +{ return new GClipart (*this); } -/*GObject* GClipart::create (GDocument *doc, const QDomElement &element) +QDomElement GClipart::writeToXml (QDomDocument &document) { - return new GClipart (doc, element); -}*/ - -QDomElement GClipart::writeToXml (QDomDocument &document) { - - // FIXME (Werner): Make this store internal/external depening on the user's wish - QDomElement element=document.createElement("clipart"); - element.setAttribute ("src", url.url ()); - element.appendChild(GObject::writeToXml(document)); - return element; + // FIXME (Werner): Make this store internal/external depening on the user's wish + QDomElement element=document.createElement("clipart"); + element.setAttribute ("src", url.url ()); + element.appendChild(GObject::writeToXml(document)); + return element; } #include diff -u killustrator/GClipart.h ki/GClipart.h --- killustrator/GClipart.h Mon Jul 2 22:38:13 2001 +++ ki/GClipart.h Mon Jul 16 13:56:35 2001 @@ -25,11 +25,11 @@ #ifndef GClipart_h_ #define GClipart_h_ -#include #include +#include class QWinMetaFile; -class QPicture; +class QPixmap; class QPainter; class GClipart : public GObject @@ -38,7 +38,6 @@ public: GClipart (GDocument* parent, const QString &name); GClipart (GDocument* parent, const QDomElement &element); - GClipart (GDocument* parent ); GClipart (const GClipart& obj); ~GClipart () {} @@ -49,7 +48,6 @@ virtual QString typeName () const; virtual GObject* copy (); - //virtual GObject* create (GDocument *doc, const QDomElement &element); virtual QDomElement writeToXml(QDomDocument &document); @@ -57,7 +55,7 @@ void calcBoundingBox (); private: - QPicture *pic; + QPixmap *pix; KURL url; float width, height; };