1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/imageitem.cpp Mon Jun 29 10:28:28 2009 +0000
1.3 @@ -0,0 +1,148 @@
1.4 +#include "imageitem.h"
1.5 +
1.6 +#include "branchitem.h"
1.7 +#include "mapobj.h" // z-values
1.8 +
1.9 +#include <QString>
1.10 +#include <iostream>
1.11 +using namespace std;
1.12 +
1.13 +uint ImageItem::saveCounter=0; // create instance
1.14 +
1.15 +ImageItem::ImageItem()
1.16 +{
1.17 + init();
1.18 +}
1.19 +
1.20 +ImageItem::ImageItem (const QList<QVariant> &data, TreeItem *parent):TreeItem (data,parent)
1.21 +{
1.22 + init();
1.23 +}
1.24 +
1.25 +ImageItem::~ImageItem()
1.26 +{
1.27 + //cout <<"Destr ImageItem\n";
1.28 + if (lmo) delete lmo;
1.29 +}
1.30 +
1.31 +void ImageItem::init()
1.32 +{
1.33 + type=Image;
1.34 + imageType=Undefined;
1.35 + originalFilename="no original name available";
1.36 + zValue=Z_FLOATIMG;
1.37 + posMode=Relative;
1.38 +}
1.39 +
1.40 +ImageItem::ImageType ImageItem::getImageType()
1.41 +{
1.42 + return imageType;
1.43 +}
1.44 +
1.45 +bool ImageItem::load(const QString &fname)
1.46 +{
1.47 + bool ok=pixmap.load (fname);
1.48 + if (lmo && ok)
1.49 + {
1.50 + setOriginalFilename (fname);
1.51 + setHeading (originalFilename);
1.52 + ((FloatImageObj*)lmo)->load (pixmap);
1.53 + }
1.54 + return ok;
1.55 +}
1.56 +
1.57 +FloatImageObj* ImageItem::createMapObj(QGraphicsScene *scene)
1.58 +{
1.59 + FloatImageObj *fio=new FloatImageObj (scene);
1.60 + fio->setTreeItem (this);
1.61 + lmo=fio;
1.62 + fio->setParObj ( parentItem->getLMO());
1.63 + if (((BranchItem*)parentItem)->isScrolled() || !parentItem->getLMO()->isVisibleObj() )
1.64 + fio->setVisibility (false);
1.65 + initLMO();
1.66 + fio->setZValue(zValue);
1.67 + fio->setRelPos (pos);
1.68 + return fio;
1.69 +}
1.70 +
1.71 +void ImageItem::setZValue(int z)
1.72 +{
1.73 + zValue=z;
1.74 + if (lmo) ((FloatImageObj*)lmo)->setZValue(z);
1.75 +}
1.76 +
1.77 +void ImageItem::setOriginalFilename(const QString & fn)
1.78 +{
1.79 + originalFilename=fn;
1.80 +
1.81 + // Set short name. Search from behind:
1.82 + int i=originalFilename.findRev("/");
1.83 + if (i>=0) originalFilename=originalFilename.remove (0,i+1);
1.84 + setHeading (originalFilename);
1.85 +}
1.86 +
1.87 +QString ImageItem::getOriginalFilename()
1.88 +{
1.89 + return originalFilename;
1.90 +}
1.91 +
1.92 +void ImageItem::resetSaveCounter()
1.93 +{
1.94 + saveCounter=0;
1.95 +}
1.96 +
1.97 +void ImageItem::save(const QString &fn, const QString &format)
1.98 +{
1.99 + pixmap.save (fn,qPrintable (format));
1.100 +}
1.101 +
1.102 +QString ImageItem::saveToDir (const QString &tmpdir,const QString &prefix)
1.103 +{
1.104 + if (hidden) return "";
1.105 +
1.106 + saveCounter++;
1.107 +
1.108 + /* FIXME-3 QString useOrientAttr;
1.109 + if (useOrientation)
1.110 + useOrientAttr=attribut ("useOrientation","true");
1.111 + else
1.112 + useOrientAttr=attribut ("useOrientation","false");
1.113 + */
1.114 +
1.115 + /*FIXME-3 QString saveInMapAttr;
1.116 + if (saveInMap)
1.117 + saveInMapAttr=attribut ("saveInMap","true");
1.118 + else
1.119 +
1.120 + saveInMapAttr=attribut ("saveInMap","false");
1.121 + */
1.122 +
1.123 + /* FIXME-3 QString exportAttr;
1.124 + if (floatExport)
1.125 + exportAttr=attribut ("floatExport","true");
1.126 + else
1.127 + exportAttr=attribut ("floatExport","false");
1.128 + */
1.129 +
1.130 +
1.131 + QString zAttr=attribut ("zValue",QString().setNum(zValue));
1.132 + QString url;
1.133 +
1.134 + url="images/"+prefix+"image-" + QString().number(saveCounter,10) + ".png" ;
1.135 +
1.136 + // And really save the image
1.137 + pixmap.save (tmpdir +"/"+ url, "PNG");
1.138 +
1.139 + QString nameAttr=attribut ("originalName",originalFilename);
1.140 +
1.141 + return singleElement ("floatimage",
1.142 + getAttr()
1.143 +// +useOrientAttr
1.144 +// +saveInMapAttr
1.145 +// +exportAttr
1.146 + +zAttr
1.147 + +attribut ("href",QString ("file:")+url)
1.148 + +nameAttr
1.149 + );
1.150 +}
1.151 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/imageitem.h Mon Jun 29 10:28:28 2009 +0000
2.3 @@ -0,0 +1,50 @@
2.4 +#ifndef IMAGEITEM_H
2.5 +#define IMAGEITEM_H
2.6 +
2.7 +#include <QList>
2.8 +#include <QPixmap>
2.9 +#include <QVariant>
2.10 +
2.11 +#include "floatimageobj.h"
2.12 +#include "treeitem.h"
2.13 +
2.14 +
2.15 +class ImageItem: public TreeItem
2.16 +{
2.17 +public:
2.18 + enum ImageType {Undefined,Pixmap,SVG};
2.19 +
2.20 +public:
2.21 + ImageItem();
2.22 + ImageItem(const QList<QVariant> &data, TreeItem *parent = 0);
2.23 +
2.24 + ~ImageItem();
2.25 +
2.26 +protected:
2.27 + void init();
2.28 + ImageType imageType;
2.29 +public:
2.30 + virtual ImageType getImageType();
2.31 +
2.32 + virtual bool load (const QString &fname);
2.33 + virtual FloatImageObj* createMapObj(QGraphicsScene *scene); //! Create classic object in GraphicsView
2.34 +
2.35 +protected:
2.36 + QPixmap pixmap;
2.37 + QString originalFilename;
2.38 + static uint saveCounter; // numerate the files during saveToDir
2.39 + int zValue;
2.40 +
2.41 +public:
2.42 + virtual void setZValue(int z);
2.43 + virtual void setOriginalFilename(const QString &);
2.44 + virtual QString getOriginalFilename();
2.45 + virtual void resetSaveCounter();
2.46 + virtual void save (const QString &fn, const QString &format);
2.47 + virtual QString saveToDir(const QString &,const QString&);
2.48 +
2.49 +};
2.50 +
2.51 +
2.52 +#endif
2.53 +