-
Notifications
You must be signed in to change notification settings - Fork 4
/
oval.cpp
92 lines (76 loc) · 1.86 KB
/
oval.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
#include "oval.h"
#include <QTWidgets>
#include <iostream>
Oval::Oval(const QColor &color, int x,int y)
{
this->x = x;
this->y = y;
this->color = color;
this->dispText = "Oval";
setZValue((x + y) % 2);
setFlags(ItemIsSelectable | ItemIsMovable);
setAcceptHoverEvents(true);
}
Oval::Oval(const QColor &color, int x,int y, QString text)
{
this->x = x;
this->y = y;
this->color = color;
this->dispText = text;
setZValue((x + y) % 2);
setFlags(ItemIsSelectable | ItemIsMovable);
setAcceptHoverEvents(true);
}
QRectF Oval::boundingRect() const
{
return QRectF(0,0,90,40);
}
int Oval::type() const
{
return 1;
}
QPainterPath Oval::shape() const
{
QPainterPath path;
path.addRect(0,0,90,40);
return path;
}
void Oval::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
QColor fillColor = color;
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(fillColor);
painter->setPen(QPen(Qt::black, 0));
painter->drawEllipse(0,0,90,40);
QFont font("Times", 10);
font.setStyleStrategy(QFont::ForceOutline);
painter->setFont(font);
painter->save();
painter->drawText(20,20, dispText);
painter->restore();
}
void Oval::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
update();
}
void Oval::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (event->modifiers() & Qt::ShiftModifier) {
stuff << event->pos();
update();
return;
}
QGraphicsItem::mouseMoveEvent(event);
}
void Oval::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
}