summaryrefslogtreecommitdiff
path: root/noncore/games/kcheckers/field.cpp
blob: aacfc1c6f2c431d0e9028f05de53999ac84b4540 (plain)
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

#include <qpainter.h>

#include "field.h"


Field::Field(QWidget* parent,int i):QWidget(parent)
{
  pixmap=new QPixmap(SIZE,SIZE);
  CHECK_PTR(pixmap);
  number=i;

  pattern=NULL;
  picture=NULL;
  frame=NULL;
}


void Field::paintEvent(QPaintEvent*)
{
  bitBlt(this,0,0,pixmap);
}


void Field::mousePressEvent(QMouseEvent* mouseevent)
{
  if(mouseevent->button()!=Qt::LeftButton) return;
  emit click(number);
}


void Field::draw()
{
  QPainter paint;
  paint.begin(pixmap);

  if(pattern) paint.drawImage(0,0,*pattern);

  if(label.length())
  {
    paint.setPen(white);
    paint.setFont(QFont(font().family(),10));
    paint.drawText(2,11,label);
  }

  if(picture) paint.drawImage(0,0,*picture);

  if(frame) paint.drawImage(0,0,*frame);

  paint.end();
  update();
}


void Field::setFrame(QImage* image)
{
  frame=image;
  draw();
}


void Field::setPicture(QImage* image)
{
  picture=image;
  draw();
}


void Field::setPattern(QImage* image)
{
  pattern=image;
  draw();
}


void Field::setLabel(const QString & string)
{
  label=string;
  draw();
}