This repository was archived by the owner on May 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardWidget.cpp
More file actions
104 lines (93 loc) · 1.89 KB
/
CardWidget.cpp
File metadata and controls
104 lines (93 loc) · 1.89 KB
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
#include "CardWidget.h"
#include "ui_CardWidget.h"
#include <QPainter>
#include <QPen>
#include <QTimer>
#include <QTime>
CardWidget::CardWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CardWidget)
{
ui->setupUi(this);
int row = 0;
int col = 0;
bool isSelected = false;
QPixmap image;
hintTime=new QTimer(this);
hintTime->setSingleShot(true);
connect(hintTime, SIGNAL(timeout()), this, SLOT(repaint()));
}
CardWidget::~CardWidget()
{
delete ui;
}
void CardWidget::paintEvent(QPaintEvent *)
{
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
QPainter p(this);
p.drawPixmap(1,1,image);
if(isSelected)
{
QPen pen;
pen.setColor(Qt::green);
pen.setWidth(5);
p.setPen(pen);
p.drawRoundRect(this->rect());
}
if(hintTime->isActive())
{
QPen pen;
pen.setColor(Qt::red);
pen.setWidth(5);
p.setPen(pen);
p.drawEllipse(this->rect());
}
}
void CardWidget::mousePressEvent(QMouseEvent *)
{
emit beClicked(this);
}
int CardWidget::get_row()
{
return row;
}
int CardWidget::get_col()
{
return col;
}
void CardWidget::set_row(int r)
{
row = r;
}
void CardWidget::set_col(int c)
{
col = c;
}
void CardWidget::set_selected(bool select)
{
isSelected = select;
}
void CardWidget::set_image(QPixmap image)
{
this->image = image;
}
void CardWidget::showHint()
{
hintTime->start(2000);
this->repaint();
}
//CardWidget& CardWidget::operator =(const CardWidget &right)
//{
// if(this==&right) return *this;
//// int row;//x轴坐标
//// int col;//y轴坐标
//// bool isSelected;//是否被选中
//// QPixmap image;
//// QTimer* hintTime;
// this->row=right.row;
// this->col=right.col;
// this->isSelected=right.isSelected;
// this->image=right.image;
// this->hintTime=right.hintTime;
// return *this;
//}