1 #ifndef BASEGRAPHICITEM_H 2 #define BASEGRAPHICITEM_H 3 4 5 #include <QtGui> 6 7 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 8 #include <QtWidgets> 9 #endif 10 11 #include "gradientdialog.h" 12 #include <QGraphicsItem> 13 14 #define ARROWSIZE 12 15 #define RSIZE 10 16 #define HSIZE (RSIZE/2) 17 18 struct sitemParam 19 { 20 // must be set before returning parameters 21 qreal zValue; 22 int type; 23 QPen pen; 24 QBrush brush; 25 QPointF position; 26 27 // are used dynamically, no need to setup 28 QFont font; 29 QString txt; 30 int rotation; 31 QImage im; 32 double hShear; 33 double vShear; 34 sgradientParam gradient; 35 QRectF rct; 36 bool locked; 37 QLineF line; 38 bool modified; 39 QColor fillColor; 40 QMenu *menu; 41 }; 42 43 enum ResizeCorners 44 { 45 TOP_LEFT, 46 TOP, 47 TOP_RIGHT, 48 RIGHT, 49 BOTTOM_RIGHT, 50 BOTTOM, 51 BOTTOM_LEFT, 52 LEFT, 53 ROTATE 54 }; 55 56 57 58 59 class graphItemBase: public QAbstractGraphicsShapeItem 60 { 61 public: 62 enum egraphType {BASE=QGraphicsItem::UserType+1,RECTANGLE,ELLIPSE,IMAGE,LINE,TEXT,REPLAY,SBORDER}; 63 graphItemBase(QMenu *cntxtMenu); 64 ~graphItemBase(); 65 virtual void drawItem(QPainter *painter)=0; 66 virtual QPainterPath shape() const; 67 virtual QRectF boundingRect() const; 68 void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); 69 void drawBorder(QPainter *painter); 70 QPainterPath qt_graphicsItem_shapeFromPath(const QPainterPath &path, const QPen &pen) const; 71 72 void mousePressEvent(QGraphicsSceneMouseEvent * event); 73 void mouseMoveEvent(QGraphicsSceneMouseEvent * event); 74 void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); 75 void hoverEnterEvent(QGraphicsSceneHoverEvent * event); 76 void hoverLeaveEvent(QGraphicsSceneHoverEvent *); 77 void hoverMoveEvent(QGraphicsSceneHoverEvent * event); 78 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); 79 bool mousePosOnHandles(QPointF pos); 80 void load(QDataStream &str); 81 void save(QDataStream &str); 82 void setTransform ( int rot,double hs,double vs); rect()83 QRectF rect() {return param.rct;} setImage(QImage ima)84 void setImage(QImage ima) {param.im=ima;} 85 sitemParam getParam(); 86 void setParam(sitemParam sp); text()87 QString text() const { return param.txt;} 88 setText(const QString &)89 virtual void setText(const QString &) { } setFont(QFont)90 virtual void setFont(QFont) { } setBrush(QColor c)91 void setBrush(QColor c) 92 { 93 param.fillColor=c; 94 QAbstractGraphicsShapeItem::setBrush(param.fillColor); 95 } setBrush(sgradientParam p,QRectF rct)96 void setBrush(sgradientParam p,QRectF rct) 97 { 98 param.gradient=p; 99 QAbstractGraphicsShapeItem::setBrush(buildGradient(param.gradient,rct)); 100 } setLocked(bool b)101 void setLocked(bool b) {param.locked=b;} setGradient(sgradientParam pm)102 void setGradient(sgradientParam pm) { param.modified=true; param.gradient=pm;} setRect(const QRectF & rectangle)103 virtual void setRect( const QRectF & rectangle ) 104 { 105 param.rct=rectangle; 106 param.modified=true; 107 } setRect(qreal x,qreal y,qreal width,qreal height)108 virtual void setRect( qreal x, qreal y, qreal width, qreal height ) 109 { 110 param.rct=QRectF(x,y,width,height); 111 param.modified=true; 112 } type()113 int type() { return param.type;} getParamPtr()114 sitemParam *getParamPtr() {return ¶m;} 115 bool markedForDeletion; 116 117 118 protected: 119 120 QRectF m_ActualRect; 121 QRectF m_CornerRect; 122 bool selected; 123 QVector<QRectF> m_ResizeHandles; 124 //! Arrow line used as rotation handle 125 QLineF m_RotateLine; 126 //! Arrow head 127 QPolygonF m_AngleHandle; 128 double m_Angle; 129 bool m_IsResizing; 130 bool m_MousePressed; 131 ResizeCorners m_ResizeCorner; 132 133 sitemParam param; 134 void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); 135 136 private: 137 void setTransform (); 138 }; 139 140 #define NUMITEMTYPES (graphItemBase::SBORDER-graphItemBase::BASE+1) 141 extern QString itemTypeStr[NUMITEMTYPES]; 142 143 #endif // BASEGRAPHICITEM_H 144