--- queensgui/src/board.cpp 2007/07/19 21:34:15 1 +++ queensgui/src/board.cpp 2009/09/16 18:53:22 327 @@ -19,7 +19,11 @@ ***************************************************************************/ #include #include -#include +#include +//Added by qt3to4: +#include +#include +#include #include "board.h" @@ -27,31 +31,33 @@ Board::Board(QWidget *parent, const char *name) : QWidget(parent, name) { - m_hasData = false; + m_sol = NULL; } Board::~Board() { + if (m_sol != NULL) + delete m_sol; } -void Board::setMatrix(Solution sol) +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;icopy(); + this->repaint(true); } + void Board::paintEvent( QPaintEvent *event ) { QPainter p (this); @@ -60,12 +66,12 @@ p.drawLine(i*30, 0, i*30, m_size*30); } - if (m_hasData) { - QBrush brush( black); + if (m_sol != NULL) { + QBrush brush( Qt::black); p.setBrush( brush ); for (int i=0; igetMatrix(i,j)) p.drawPie( (i*30)+10, (j*30)+10, 10, 10 ,0, 16*360); } } @@ -73,10 +79,10 @@ void Board::mousePressEvent( QMouseEvent *event) { - if (event->button() == LeftButton) { + if (event->button() == Qt::LeftButton) { this->repaint(true); QPainter p( this ); - QPen bluePen( blue ); + QPen bluePen( Qt::blue ); p.setPen( bluePen ); int x = event->x() / 30; int y = event->y() / 30; @@ -84,7 +90,7 @@ 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 ); + QPen redPen( Qt::red ); p.setPen( redPen ); int startx,stopx; @@ -92,7 +98,7 @@ starty = stopy = y; startx = stopx = x; - // første skrå linie + // f�rste skr� linie while (startx > 0 && starty > 0) { startx--; starty--; @@ -104,7 +110,7 @@ } p.drawLine(QPoint( (startx*30)+5, (starty*30)+5), QPoint( (stopx*30)+25, (stopy*30)+25)); - //næste skrå linie + //n�ste skr� linie startx = stopx = x; starty = stopy = y; while (startx > 0 && starty < (m_size-1) ) { @@ -122,7 +128,12 @@ void Board::setSize( int size ) { - m_hasData = false; + if (m_sol != NULL) + { + delete m_sol; + m_sol = NULL; + } + m_size = size; this->setMaximumSize( (size * 30)+1, (size * 30)+1 ); this->setMinimumSize( size * 30, size * 30); @@ -130,7 +141,10 @@ void Board::contextMenuEvent( QContextMenuEvent *event) { - QPopupMenu *contextMenu = new QPopupMenu( this ); + if (m_sol == NULL) + return; + + Q3PopupMenu *contextMenu = new Q3PopupMenu( this ); contextMenu->setCheckable( false ); contextMenu->insertItem("Rotate left", this, SLOT( rotateLeft() ) ); contextMenu->insertItem("Rotate right", this, SLOT( rotateRight() ) ); @@ -143,28 +157,28 @@ void Board::rotateLeft() { - m_sol.rotate90(); + m_sol->rotate90(); repaint( true ); } void Board::rotateRight() { - m_sol.rotate90(); - m_sol.rotate90(); - m_sol.rotate90(); + m_sol->rotate90(); + m_sol->rotate90(); + m_sol->rotate90(); repaint( true ); } void Board::mirrorV() { - m_sol.mirror(); + m_sol->mirror(); repaint( true ); } void Board::mirrorH() { - m_sol.mirror(); - m_sol.rotate90(); - m_sol.rotate90(); + m_sol->mirror(); + m_sol->rotate90(); + m_sol->rotate90(); repaint( true ); }