Grid 0.1
QT Widget representing a grid

grid.h

Go to the documentation of this file.
00001 
00008 #ifndef GRID_H
00009 #define GRID_H
00010 
00011 #include <QWidget>
00012 #include <QApplication>
00013 #include <algorithm>
00014 #include <QPainter>
00015 #include <QMouseEvent>
00016 #include <cmath>
00017 
00018 class Grid : public QWidget
00019 {
00020                 Q_OBJECT
00021         public:
00022                 Grid(QWidget *parent = 0,unsigned int w=1,unsigned int h=1);
00023 
00030                 void setGridSize(unsigned int width, unsigned int height, bool preserve=true);
00037                 void setGrid(const char *const * grid, unsigned int width, unsigned int height);
00044                 bool setCell(unsigned int x,unsigned int y, char state=1);
00048                 bool setCell(QPoint p, char state=1);
00055                 bool clearCell (unsigned int x, unsigned int y);
00059                 bool clearCell (QPoint p);
00064                 void clearCells(char state);
00068                 void clearGrid();
00072                 char getCell(QPoint p) const;
00078                 char getCell(unsigned int x, unsigned int y) const;
00079 
00082                 const char *const * getGrid() const;
00083 
00086                 const QSize getGridSize()const;
00087 
00090                 void setCellColor(char state,QColor color);
00091 
00098                 void setAutoSet(bool enable);
00099 
00103                 bool getAutoSet();
00104 
00105                 virtual ~Grid();
00106 
00107         protected:
00108                 virtual void paintEvent(QPaintEvent *);
00109                 virtual void paintGrid(QPainter&);
00110                 virtual void paintGridState(QPainter&);
00111                 virtual void mouseReleaseEvent(QMouseEvent *);
00116                 virtual QPoint decodePosition(QPoint p) const;
00119                 virtual QSize cellSize() const;
00120 
00122                 unsigned int gridWidth;
00124                 unsigned int gridHeight;
00126                 char** gridState;
00127 
00128 
00129         signals:
00134                 void clicked(QPoint cell, Qt::MouseButton button) const;
00135         public slots:
00136 
00137         protected:
00138                 void deleteGrid();
00139 
00141                 QVector<QColor> colors;
00142 
00144                 bool autoSet;
00145 
00146 };
00147 
00148 #endif // GRID_H
 All Classes Files Functions Variables