/*************************************************************************** * Copyright (C) 2004 by Johan Maes - ON4QZ * * on4qz@telenet.be * * http://users.telenet.be/on4qz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef CANVASIT_H #define CANVASIT_H #include #include #include #include #include #define STRVERSION 3 #define MAGICNUMBER (('4'<<24)+('Q'<<16)+('Z'<<8)+STRVERSION) #define imageRTTI 1001 #define rectangleRTTI 1002 #define ellipseRTTI 1003 #define textRTTI 1004 #define lineRTTI 1005 #define FGC 0x0000ff #define BGC 0x00ff00 enum eSizing {SMOVE,SLT,SMT,SRT,SLC,SRC,SLB,SMB,SRB}; struct scanvasItemParam { scanvasItemParam() { type=-1; } QRect rect; QString text; QImage img; double shear; int angle; bool locked; int type; QFont font; int gradient; int lineWidth; QColor foreground; QColor background; }; /** canvasItemBase */ class canvasItemBase: public QCanvasRectangle { public: canvasItemBase(QCanvas *cnv); void setParam(scanvasItemParam ¶m,int depth); void getParam(scanvasItemParam ¶m); virtual ~canvasItemBase() {;} void load(QDataStream &str); void save(QDataStream &str); QColor foregroundColor() {return foreground;} QColor backgroundColor() {return background;} virtual void create(QPoint start,QPoint end)=0; virtual void updateActiveImage()=0; void setFinal(bool f) {final=f;updateActiveImage();} virtual void drawShape (QPainter &p); void setLocked(bool b) { locked=b;} bool isLocked() { return locked;} void setFont(QFont f) {font=f;} void setText(QString s) {text=s;} QString getText() {return text;} void setShear(double d) { shear=d; mtx.reset(); mtx.shear(shear,shear); mtx.rotate(angle); updateActiveImage(); } void setRotate(int r) {angle=r;mtx.reset();mtx.shear(shear,shear); mtx.rotate(angle);updateActiveImage();} double getShear() {return shear;} int getRotate() {return angle;} /** CanvasItem has the followin properties
QRect itemRect: holding the position and size as displayed
QColor fgc: the foreground color (including alpha channel)
QColor bgc: the background color (including alpha channel) */ eSizing checkGrip(QPoint cp); void moveBy(int x,int y); QPoint startPoint() {return itemRect.topLeft();} QPoint endPoint() {return itemRect.bottomRight();} QRect rect(){ return itemRect;} QImage &getActiveImage(){return activeImage;} QImage &getFullImage() {return fullImage;} void setGradient(int i) {gradient=i;updateActiveImage();} void setImage(QImage *im) {fullImage=im->copy();updateActiveImage();} void setGeometry(QPoint start,QPoint end); void applyColors(QColor fg,QColor bg,int lW); void changeFont(QFont newFont); QFont getFont() { return font; } QColor getPixel(int x,int y) { return activeImage.pixel(x-itemRect.x(),y-itemRect.y()); } protected: QImage fullImage; QImage activeImage; void pixmapToActiveImage(QPixmap &pm); // QPixmap pm; bool locked; // make object unmoveble bool final; // used while resizing an image // bool changed; // bool activeImageChanged; QRect itemRect; // QRect notNormalizedItemRect; bool negSlope; void convertPixmap(QPainter &p); void scaleImage(); QRect lt; QRect mt; QRect rt; QRect lc; QRect rc; QRect lb; QRect mb; QRect rb; QString text; int angle; double shear; QFont font; QWMatrix mtx; int gradient; //0=none 1=horizontal, 2=vertical QColor foreground; QColor background; int lineWidth; }; class rectangle: public canvasItemBase { public: rectangle(QCanvas *); ~rectangle(); void create(QPoint start,QPoint end); int rtti () const { return rectangleRTTI; } protected: void updateActiveImage(); }; class imageItem: public canvasItemBase { public: imageItem(QCanvas *canvas ); imageItem( QImage img, QCanvas *canvas ); void create(QPoint start,QPoint end); int rtti () const { return imageRTTI; } protected: void updateActiveImage(); }; class ellipse: public canvasItemBase { public: ellipse(QCanvas *); ~ellipse(); void create(QPoint start,QPoint end); int rtti () const { return ellipseRTTI; } protected: void updateActiveImage(); }; class textItem: public canvasItemBase { public: textItem(QCanvas *); ~textItem(); void create(QPoint start,QPoint end); int rtti () const { return textRTTI; } protected: QString convertedText; /** %t =time %d=date %c=mycall %f=to call */ void convertText(); void updateActiveImage(); }; class line: public canvasItemBase { public: line(QCanvas *); ~line(); void create(QPoint start,QPoint end); int rtti () const { return lineRTTI; } protected: void updateActiveImage(); }; #endif