/*************************************************************************** * Copyright (C) 2005 by Torben Nielsen * * torben@t-hoerup.dk * * * * This program 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. * * * * This program 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 this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include #include #include "board.h" Board::Board(QWidget *parent, const char *name) : QWidget(parent, name) { m_hasData = false; } Board::~Board() { } void Board::setMatrix(Solution sol) { m_hasData = true; m_sol = sol; this->repaint(true); } void Board::setMatrix(IntSolution sol) { m_hasData = true; m_sol = Solution(); for (int i=0;irepaint(true); } void Board::paintEvent( QPaintEvent *event ) { QPainter p (this); for (int i=0;i<(m_size+2);i++) { p.drawLine(0, i*30, m_size*30, i*30); p.drawLine(i*30, 0, i*30, m_size*30); } if (m_hasData) { QBrush brush( black); p.setBrush( brush ); for (int i=0; ibutton() == LeftButton) { this->repaint(true); QPainter p( this ); QPen bluePen( blue ); p.setPen( bluePen ); int x = event->x() / 30; int y = event->y() / 30; p.drawLine( QPoint(5,(y*30)+15), QPoint( (m_size*30)-5, (y*30)+15) ); p.drawLine( QPoint( (x*30)+15, 5), QPoint( (x*30)+15, (m_size*30)-5 ) ); QPen redPen( red ); p.setPen( redPen ); int startx,stopx; int starty,stopy; starty = stopy = y; startx = stopx = x; // første skrå linie while (startx > 0 && starty > 0) { startx--; starty--; } while (stopx < (m_size-1) && stopy < (m_size-1) ) { stopx++; stopy++; } p.drawLine(QPoint( (startx*30)+5, (starty*30)+5), QPoint( (stopx*30)+25, (stopy*30)+25)); //næste skrå linie startx = stopx = x; starty = stopy = y; while (startx > 0 && starty < (m_size-1) ) { startx--; starty++; } while (stopx < (m_size-1) && stopy >0) { stopx++; stopy--; } p.drawLine(QPoint( (startx*30)+5, (starty*30)+25), QPoint( (stopx*30)+25, (stopy*30)+5)); } } void Board::setSize( int size ) { m_hasData = false; m_size = size; this->setMaximumSize( (size * 30)+1, (size * 30)+1 ); this->setMinimumSize( size * 30, size * 30); } void Board::contextMenuEvent( QContextMenuEvent *event) { QPopupMenu *contextMenu = new QPopupMenu( this ); contextMenu->setCheckable( false ); contextMenu->insertItem("Rotate left", this, SLOT( rotateLeft() ) ); contextMenu->insertItem("Rotate right", this, SLOT( rotateRight() ) ); contextMenu->insertItem("Vertical mirror", this, SLOT ( mirrorV() ) ); contextMenu->insertItem("Horisontal mirror", this, SLOT( mirrorH() ) ); contextMenu->exec( event->globalPos() ); delete contextMenu; } void Board::rotateLeft() { m_sol.rotate90(); repaint( true ); } void Board::rotateRight() { m_sol.rotate90(); m_sol.rotate90(); m_sol.rotate90(); repaint( true ); } void Board::mirrorV() { m_sol.mirror(); repaint( true ); } void Board::mirrorH() { m_sol.mirror(); m_sol.rotate90(); m_sol.rotate90(); repaint( true ); }