/[projects]/queensgui/src/board.cpp
ViewVC logotype

Diff of /queensgui/src/board.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5 by torben, Fri Jul 20 01:22:53 2007 UTC revision 327 by torben, Wed Sep 16 18:53:22 2009 UTC
# Line 19  Line 19 
19   ***************************************************************************/   ***************************************************************************/
20  #include <qstring.h>  #include <qstring.h>
21  #include <qpainter.h>  #include <qpainter.h>
22  #include <qpopupmenu.h>  #include <q3popupmenu.h>
23    //Added by qt3to4:
24    #include <QMouseEvent>
25    #include <QContextMenuEvent>
26    #include <QPaintEvent>
27    
28  #include "board.h"  #include "board.h"
29    
# Line 39  Board::~Board() Line 43  Board::~Board()
43    
44  void Board::setMatrix(Solution* sol)  void Board::setMatrix(Solution* sol)
45  {  {
46          if (sol != NULL)  
47            if (m_sol != NULL)
48            {
49                    delete m_sol;
50                    m_sol = NULL;
51            }
52            
53            if (sol != NULL)
54                  m_sol = sol->copy();                  m_sol = sol->copy();
55                    
56          this->repaint(true);          this->repaint(true);
57  }  }
58    
 /*  
 void Board::setMatrix(IntSolution sol)  
 {  
 #warning need a closer look  
   
         m_hasData = true;  
         m_sol = Solution();  
         for (int i=0;i<m_size;i++)  
                 m_sol.matrix[i][ sol.imatrix[i] ] = true;  
         this->repaint(true);  
   
 }*/  
59    
60    
61  void Board::paintEvent( QPaintEvent *event )  void Board::paintEvent( QPaintEvent *event )
# Line 68  void Board::paintEvent( QPaintEvent *eve Line 67  void Board::paintEvent( QPaintEvent *eve
67          }          }
68                    
69          if (m_sol != NULL) {          if (m_sol != NULL) {
70                  QBrush brush( black);                  QBrush brush( Qt::black);
71                  p.setBrush( brush );                  p.setBrush( brush );
72                  for (int i=0; i<m_size; i++)                  for (int i=0; i<m_size; i++)
73                          for (int j=0; j<m_size; j++) {                          for (int j=0; j<m_size; j++) {
# Line 80  void Board::paintEvent( QPaintEvent *eve Line 79  void Board::paintEvent( QPaintEvent *eve
79    
80  void Board::mousePressEvent( QMouseEvent *event)  void Board::mousePressEvent( QMouseEvent *event)
81  {  {
82          if (event->button() == LeftButton) {          if (event->button() == Qt::LeftButton) {
83                  this->repaint(true);                  this->repaint(true);
84                  QPainter p( this );                  QPainter p( this );
85                  QPen bluePen( blue );                  QPen bluePen( Qt::blue );
86                  p.setPen( bluePen );                  p.setPen( bluePen );
87                  int x = event->x() / 30;                  int x = event->x() / 30;
88                  int y = event->y() / 30;                  int y = event->y() / 30;
# Line 91  void Board::mousePressEvent( QMouseEvent Line 90  void Board::mousePressEvent( QMouseEvent
90                  p.drawLine( QPoint(5,(y*30)+15), QPoint( (m_size*30)-5, (y*30)+15) );                  p.drawLine( QPoint(5,(y*30)+15), QPoint( (m_size*30)-5, (y*30)+15) );
91                  p.drawLine( QPoint( (x*30)+15, 5), QPoint( (x*30)+15, (m_size*30)-5 ) );                  p.drawLine( QPoint( (x*30)+15, 5), QPoint( (x*30)+15, (m_size*30)-5 ) );
92                    
93                  QPen redPen( red );                  QPen redPen( Qt::red );
94                  p.setPen( redPen );                  p.setPen( redPen );
95                    
96                  int startx,stopx;                  int startx,stopx;
# Line 134  void Board::setSize( int size ) Line 133  void Board::setSize( int size )
133                  delete m_sol;                  delete m_sol;
134                  m_sol = NULL;                  m_sol = NULL;
135          }          }
136            
137          m_size = size;          m_size = size;
138          this->setMaximumSize( (size * 30)+1, (size * 30)+1 );          this->setMaximumSize( (size * 30)+1, (size * 30)+1 );
139          this->setMinimumSize( size * 30, size * 30);          this->setMinimumSize( size * 30, size * 30);
# Line 144  void Board::contextMenuEvent( QContextMe Line 144  void Board::contextMenuEvent( QContextMe
144          if (m_sol == NULL)          if (m_sol == NULL)
145                  return;                  return;
146                    
147          QPopupMenu *contextMenu = new QPopupMenu( this );          Q3PopupMenu *contextMenu = new Q3PopupMenu( this );
148          contextMenu->setCheckable( false );          contextMenu->setCheckable( false );
149          contextMenu->insertItem("Rotate left", this, SLOT( rotateLeft() ) );          contextMenu->insertItem("Rotate left", this, SLOT( rotateLeft() ) );
150          contextMenu->insertItem("Rotate right", this, SLOT( rotateRight() ) );          contextMenu->insertItem("Rotate right", this, SLOT( rotateRight() ) );

Legend:
Removed from v.5  
changed lines
  Added in v.327

  ViewVC Help
Powered by ViewVC 1.1.20