--- queensgui/src/board.cpp 2010/04/20 14:29:53 653 +++ queensgui/src/board.cpp 2010/04/22 20:09:09 654 @@ -32,6 +32,7 @@ : QWidget(parent, name) { m_sol = NULL; + m_drawmarkers = false; } @@ -75,54 +76,66 @@ 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() == Qt::LeftButton) { + m_drawmarkers = true; + m_markerPoint = event->pos(); this->repaint(true); - QPainter p( this ); - QPen bluePen( Qt::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( Qt::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)); } }