-
Notifications
You must be signed in to change notification settings - Fork 4
/
parallelogram.cpp
119 lines (94 loc) · 2.63 KB
/
parallelogram.cpp
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
#include "parallelogram.h"
#include <QtWidgets>
Parallel::Parallel(const QColor &color, int x, int y)
{
this->x = x;
this->y = y;
this->color = color;
dispText = "Parallel";
setZValue((x + y) % 2);
setFlags(ItemIsSelectable | ItemIsMovable);
setAcceptHoverEvents(true);
}
Parallel::Parallel(const QColor &color, int x, int y, QString text)
{
this->x = x;
this->y = y;
this->color = color;
dispText = text;
setZValue((x + y) % 2);
setFlags(ItemIsSelectable | ItemIsMovable);
setAcceptHoverEvents(true);
}
QRectF Parallel::boundingRect() const
{
return QRectF(0, 0, 110, 70);
}
QPainterPath Parallel::shape() const
{
QPainterPath path;
path.addRect(0, 0, 130, 80);
return path;
}
void Parallel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
QColor fillColor = (option->state & QStyle::State_Selected) ? color.dark(150) : color;
if (option->state & QStyle::State_MouseOver)
fillColor = fillColor.light(125);
QPen oldPen = painter->pen();
QPen pen = oldPen;
int width = 0;
if (option->state & QStyle::State_Selected)
width += 2;
pen.setWidth(width);
QBrush b = painter->brush();
painter->setBrush(QBrush(fillColor.dark(option->state & QStyle::State_Sunken ? 120 : 100)));
//painter->drawRect(QRect(1, 1, 100, 60));
//commented out
//painter->setBrush(b);
painter->setPen(QPen(Qt::black, 1));
//added by me (Dennis
QBrush fillbrush;
fillbrush.setColor(fillColor);
fillbrush.setStyle(Qt::SolidPattern);
//Make trapezoid
QPolygon poly;
poly << QPoint(20,35); //A A->B->C->D
poly << QPoint(110,35); //B
poly << QPoint(90,1); //C
poly << QPoint(1,1); //D
painter->drawPolygon(poly);
QPainterPath p;
p.addRegion(poly);
painter->fillPath(p,fillbrush);
QFont font("Times", 10);
font.setStyleStrategy(QFont::ForceOutline);
painter->setFont(font);
painter->save();
painter->drawText(20,20, dispText);
painter->restore();
}
void Parallel::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
update();
}
void Parallel::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (event->modifiers() & Qt::ShiftModifier) {
stuff << event->pos();
update();
return;
}
QGraphicsItem::mouseMoveEvent(event);
}
int Parallel::type() const
{
return 4;
}
void Parallel::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
update();
}