-
Notifications
You must be signed in to change notification settings - Fork 0
/
kl2dview.cpp
74 lines (64 loc) · 1.45 KB
/
kl2dview.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 "kl2dview.h"
#include "module/klmbase.h"
KL2DView::KL2DView(int id, QWidget *parent):
QWidget(parent),
module(NULL),
id(id)
{
// this->setFixedSize(200,200);
}
KL2DView::~KL2DView()
{
}
void KL2DView::setModule(KLMBase *module)
{
if(this->module){
disconnect(module, SIGNAL(destroyed()), this, SLOT(h_moduleDestroy()));
}
this->module = module;
if(module){
connect(module, SIGNAL(destroyed()), this, SLOT(h_moduleDestroy()));
}
this->repaint();
}
void KL2DView::setId(int id)
{
this->id = id;
}
const int KL2DView::getId()
{
return id;
}
void KL2DView::paintEvent(QPaintEvent *event)
{
//qDebug()<<this;
QPainter painter;
painter.begin(this);
//painter.setRenderHint(QPainter::Antialiasing);
// painter.setPen(Qt::NoPen);
// for (int x = 0; x < width(); x += 10) {
// for (int y = 0; y < height(); y += 10) {
// if((x / 10) % 2 == (y / 10) % 2){
// painter.fillRect(x, y, 10, 10, QColor(255,255,255));
// }else{
// painter.fillRect(x, y, 10, 10, QColor(225,225,225));
// }
// }
// }
if(module){
module->paint2D(id, &painter, event);
}
painter.end();
}
void KL2DView::resizeEvent(QResizeEvent *event)
{
if(module){
module->viewResize2D(id, event);
}
}
void KL2DView::h_moduleDestroy()
{
this->module = NULL;
this->repaint();
KL2DView::~KL2DView();
}