00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "objects.h"
00020
00021 #include "field.h"
00022
00023 Field::Field(QWidget *parent, const char *name ) : QWidget(parent,name) {
00024 setFixedSize(game.scrwidth, game.scrheight);
00025 setBackgroundColor(white);
00026 timer = new QTimer(this);
00027
00028 playing = false;
00029
00030 connect(timer, SIGNAL(timeout()), SLOT(Timer()));
00031 }
00032
00033 Field::~Field(){
00034 delete timer;
00035 }
00036
00037 void Field::setPixmap(QPixmap *pix) {
00038 this->pix = pix;
00039 }
00040
00041
00042
00043 void Field::mousePressEvent(QMouseEvent *e){
00044 game.button_press(e->x(), e->y());
00045 }
00046
00047 void Field::mouseReleaseEvent(QMouseEvent *e){
00048 game.button_release(e->x(), e->y());
00049 }
00050
00051 void Field::enterEvent(QEvent *) {
00052 if (playing && !timer->isActive()) {
00053 playing = true;
00054 timer->start(250, FALSE);
00055 }
00056 }
00057
00058 void Field::leaveEvent(QEvent *) {
00059 if (timer->isActive() && playing) {
00060 playing = true;
00061 timer->stop();
00062 }
00063 }
00064
00065 void Field::stopTimer() {
00066 playing = false;
00067 if (timer->isActive())
00068 timer->stop();
00069 }
00070
00071 void Field::startTimer() {
00072 playing = true;
00073 if (!timer->isActive())
00074 timer->start(250, FALSE);
00075 }
00076
00077 void Field::Timer(){
00078 game.update();
00079 }
00080
00081 void Field::paintEvent(QPaintEvent *) {
00082 bitBlt(this, 0, 0, pix);
00083 }