File: basegraphicitem.h

package info (click to toggle)
qsstv 9.5.8-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,928 kB
  • sloc: cpp: 47,579; makefile: 4
file content (143 lines) | stat: -rw-r--r-- 3,582 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef BASEGRAPHICITEM_H
#define BASEGRAPHICITEM_H


#include <QtGui>

#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QtWidgets>
#endif

#include "gradientdialog.h"
#include <QGraphicsItem>

#define ARROWSIZE 12
#define RSIZE 10
#define HSIZE (RSIZE/2)

struct sitemParam
  {
 // must be set before returning parameters
    qreal zValue;
    int type;
    QPen pen;
    QBrush brush;
    QPointF position;

// are used dynamically, no need to setup
    QFont font;
    QString txt;
    int rotation;
    QImage im;
    double hShear;
    double vShear;
    sgradientParam gradient;
    QRectF rct;
    bool locked;
    QLineF line;
    bool modified;
    QColor fillColor;
    QMenu *menu;
};

enum ResizeCorners
{
  TOP_LEFT,
  TOP,
  TOP_RIGHT,
  RIGHT,
  BOTTOM_RIGHT,
  BOTTOM,
  BOTTOM_LEFT,
  LEFT,
  ROTATE
};




class graphItemBase: public QAbstractGraphicsShapeItem
{
public:
enum egraphType {BASE=QGraphicsItem::UserType+1,RECTANGLE,ELLIPSE,IMAGE,LINE,TEXT,REPLAY,SBORDER};
  graphItemBase(QMenu *cntxtMenu);
  ~graphItemBase();
  virtual void drawItem(QPainter *painter)=0;
  virtual QPainterPath shape() const;
  virtual QRectF boundingRect() const;
  void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
  void drawBorder(QPainter *painter);
  QPainterPath qt_graphicsItem_shapeFromPath(const QPainterPath &path, const QPen &pen) const;

  void mousePressEvent(QGraphicsSceneMouseEvent * event);
  void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
  void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
  void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
  void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
  void hoverMoveEvent(QGraphicsSceneHoverEvent * event);
  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
  bool mousePosOnHandles(QPointF pos);
  void load(QDataStream &str);
  void save(QDataStream &str);
  void setTransform ( int rot,double hs,double vs);
  QRectF rect() {return param.rct;}
  void setImage(QImage ima) {param.im=ima;}
  sitemParam getParam();
  void setParam(sitemParam sp);
  QString text() const { return param.txt;}

  virtual void setText(const QString &) { }
  virtual void setFont(QFont) {	}
  void setBrush(QColor c)
    {
      param.fillColor=c;
      QAbstractGraphicsShapeItem::setBrush(param.fillColor);
    }
  void setBrush(sgradientParam p,QRectF rct)
    {
      param.gradient=p;
      QAbstractGraphicsShapeItem::setBrush(buildGradient(param.gradient,rct));
    }
  void setLocked(bool b) {param.locked=b;}
  void setGradient(sgradientParam pm) { param.modified=true; param.gradient=pm;}
  virtual void setRect( const QRectF & rectangle )
    {
      param.rct=rectangle;
      param.modified=true;
    }
  virtual void setRect( qreal x, qreal y, qreal width, qreal height )
    {
      param.rct=QRectF(x,y,width,height);
      param.modified=true;
    }
  int type() { return param.type;}
  sitemParam *getParamPtr() {return &param;}
  bool markedForDeletion;


protected:

  QRectF m_ActualRect;
  QRectF m_CornerRect;
  bool selected;
  QVector<QRectF> m_ResizeHandles;
  //! Arrow line used as rotation handle
  QLineF m_RotateLine;
  //! Arrow head
  QPolygonF m_AngleHandle;
  double m_Angle;
  bool m_IsResizing;
  bool m_MousePressed;
  ResizeCorners m_ResizeCorner;

  sitemParam param;
  void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);

private:
    void setTransform ();
};

#define NUMITEMTYPES (graphItemBase::SBORDER-graphItemBase::BASE+1)
extern QString itemTypeStr[NUMITEMTYPES];

#endif // BASEGRAPHICITEM_H