/* VierGewinnt - A simple 4-in-a-row network game * * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de * http://www.seba-geek.de * * This file is part of VierGewinnt. * * VierGewinnt is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * VierGewinnt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VierGewinnt. If not, see . */ #include "renderarea.h" #include RenderArea::RenderArea(QWidget *parent) : QWidget(parent) { QSizePolicy tmppol; tmppol.setHorizontalPolicy(QSizePolicy::Maximum); tmppol.setVerticalPolicy(QSizePolicy::Maximum); setSizePolicy(tmppol); // this->antialiased = true; // pens xpen.setColor(Qt::green); xpen.setWidth(10); xpen.setJoinStyle(Qt::RoundJoin); xpen.setCapStyle(Qt::RoundCap); ypen.setColor(Qt::red); ypen.setWidth(10); mfact = 0.75; feld = 0; // just to clarify, also set in next statement setFeldInfo(7, 6, 0); } void RenderArea::setFeldInfo(int _x, int _y, VierGewinntWidget::Stein **_feld) { fx = _x; fy = _y; feld = _feld; } QSize RenderArea::minimumSizeHint() const { return QSize(320, 240); } QSize RenderArea::sizeHint() const { return QSize(640, 480); } void RenderArea::paintEvent(QPaintEvent * /*event*/) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); // Start with grid int fsize = std::min(width()/fx, height()/fy); // painter.drawLine(0, 0, width(), height()); painter.translate((width()-fsize*fx)/2, (height()-fsize*fy)/2); for(int i=0; i<=fx; i++) painter.drawLine(i*fsize, 0, i*fsize, fsize*fy); for(int i=0; i<=fy; i++) painter.drawLine(0, i*fsize, fsize*fx, i*fsize); if(feld==0) return; // paint x and o for(int i=0; ibutton()!=Qt::LeftButton) return; int fsize = std::min(width()/fx, height()/fy); int myrow = (event->x()-((width()-fsize*fx)/2))/fsize; if(myrow<0||myrow>=fx||event->x()-((width()-fsize*fx)/2)<0) return; addStein(myrow); }