--- queensgui/src/board.cpp 2007/07/19 21:34:15 1 +++ queensgui/src/board.cpp 2010/04/22 20:09:09 654 @@ -19,7 +19,11 @@ ***************************************************************************/ #include #include -#include +#include +//Added by qt3to4: +#include +#include +#include #include "board.h" @@ -27,31 +31,34 @@ Board::Board(QWidget *parent, const char *name) : QWidget(parent, name) { - m_hasData = false; + m_sol = NULL; + m_drawmarkers = false; } 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,69 +67,86 @@ 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); } } + + + if (m_drawmarkers == true) { + drawMarkerLines(); + m_drawmarkers = false; + } +} + +void Board::drawMarkerLines() +{ + QPainter p( this ); + QPen bluePen( Qt::blue ); + p.setPen( bluePen ); + int x = m_markerPoint.x() / 30; + int y = m_markerPoint.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( Qt::red ); + p.setPen( redPen ); + + int startx,stopx; + int starty,stopy; + starty = stopy = y; + startx = stopx = x; + + // first diagonal line + 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)); + + //next diagonal line + 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::mousePressEvent( QMouseEvent *event) { - if (event->button() == LeftButton) { + if (event->button() == Qt::LeftButton) { + m_drawmarkers = true; + m_markerPoint = event->pos(); 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; + 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 +154,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 +170,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 ); }