-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmygraphicsitem.cpp
63 lines (57 loc) · 1.72 KB
/
mygraphicsitem.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
#include "mygraphicsitem.h"
#include <QPainter>
#include <QPen>
#include <QRectF>
#include <QDebug>
#include <QGraphicsItem>
#include <QGraphicsSceneMouseEvent>
MyGraphicsItem::MyGraphicsItem(int inputRow, int inputCol, QColor color, qreal x, qreal y, qreal width, qreal height,QGraphicsItem *parent):
QGraphicsRectItem(x,y,width,height,parent)
{
setFlags(QGraphicsItem::ItemIsSelectable);
bgdColor = color;
marginColor = Qt::transparent;
row = inputRow;
col = inputCol;
activeness = false;
}
MyGraphicsItem::~MyGraphicsItem()
{
}
QRectF MyGraphicsItem::boundingRect() const
{
return QRectF(-30, -30, 60, 60);
}
void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// Q_UNUSED(option)
// Q_UNUSED(widget)
// QBrush brush(QColor(200,125,125));
// painter->setBrush(brush);
// painter->drawRect(-100, -100, 200, 200);
QPen pen(Qt::black, 2);
//painter->setPen(pen);
QGraphicsRectItem::setPen(pen);
QGraphicsRectItem::setBrush(QBrush(bgdColor));
QGraphicsRectItem::paint(painter, option, widget);
QPen newpen(marginColor, 5);
painter->setPen(newpen);
painter->drawRect(-28,-28,56,56);
painter->setPen(pen);
if(type != "")
painter->drawImage(QRectF(-25,-25,50,50),QImage(":/pic/pic/" + color + "_" + type + ".png"));
}
void MyGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
if(!activeness)
return;
if(event->button() == Qt::LeftButton) {
// if(marginColor != Qt::transparent) {
// marginColor = Qt::transparent;
// }
// else {
// marginColor = Qt::blue;
// }
// update();
emit checkerClicked(row, col);
}
}