-
Notifications
You must be signed in to change notification settings - Fork 1
/
cross.cpp
74 lines (58 loc) · 1.7 KB
/
cross.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
#include "qdigiplot.h"
#include "cross.h"
Cross::Cross(QGraphicsItem* parent, QGraphicsScene* scene) : QGraphicsItem(parent)
{
}
QRectF Cross::boundingRect() const
{
return QRectF(-5, -5, 5, 5);
}
void Cross::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(widget);
QColor fillColor = Qt::green;
if (option->state & QStyle::State_MouseOver)
fillColor = Qt::red;
QPen pen(fillColor);
painter->setPen(pen);
QVector<QLine> lineVec(2);
lineVec.append(QLine(-5, -5, 5, 5));
lineVec.append(QLine(5, -5, -5, 5));
painter->drawLines(lineVec);
}
CrossX::CrossX(QGraphicsItem* parent, QGraphicsScene* scene) : QGraphicsItem(parent)
{
}
QRectF CrossX::boundingRect() const
{
return QRectF(-4, -4, 4, 4);
}
void CrossX::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(widget);
QColor fillColor = Qt::blue;
QPen pen(fillColor);
painter->setPen(pen);
QVector<QLine> lineVec(2);
lineVec.append(QLine(0, -4, 0, 4));
lineVec.append(QLine(4, 0, -4, 0));
painter->drawLines(lineVec);
}
CrossY::CrossY(QGraphicsItem* parent, QGraphicsScene* scene) : QGraphicsItem(parent)
{
}
QRectF CrossY::boundingRect() const
{
return QRectF(-4, -4, 4, 4);
}
void CrossY::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(widget);
QColor fillColor = Qt::magenta;
QPen pen(fillColor);
painter->setPen(pen);
QVector<QLine> lineVec(2);
lineVec.append(QLine(0, -4, 0, 4));
lineVec.append(QLine(4, 0, -4, 0));
painter->drawLines(lineVec);
}