Grid 0.1
QT Widget representing a grid
|
A click sensitive grid widget. More...
#include <grid.h>
Signals | |
void | clicked (QPoint cell, Qt::MouseButton button) const |
Signals a click to a cell. | |
Public Member Functions | |
Grid (QWidget *parent=0, unsigned int w=1, unsigned int h=1) | |
void | setGridSize (unsigned int width, unsigned int height, bool preserve=true) |
Resizes the grid. | |
void | setGrid (const char *const *grid, unsigned int width, unsigned int height) |
Sets a complete new grid. The grid pointer should be deleted by the caller. | |
bool | setCell (unsigned int x, unsigned int y, char state=1) |
Sets a cell. | |
bool | setCell (QPoint p, char state=1) |
Sets a cell. | |
bool | clearCell (unsigned int x, unsigned int y) |
Clears a cell. Same as setGrid (x, y, 0). | |
bool | clearCell (QPoint p) |
Clears a cell. | |
void | clearCells (char state) |
Clears all cells with a specific state. | |
void | clearGrid () |
Clears grid. | |
char | getCell (QPoint p) const |
Returns state of a cell. | |
char | getCell (unsigned int x, unsigned int y) const |
Returns state of a cell. | |
const char *const | getGrid () const |
Returns complete grid. | |
const QSize | getGridSize () const |
Returns grid size. | |
void | setCellColor (char state, QColor color) |
Sets the color for a cell state. | |
void | setAutoSet (bool enable) |
Sets if autoSet function is activated. If autoSet is activated, grid cells get set automatically on leftclick and deset on rightclick. | |
bool | getAutoSet () |
Returns if autoSet is enabled. | |
virtual | ~Grid () |
Protected Member Functions | |
virtual void | paintEvent (QPaintEvent *) |
virtual void | paintGrid (QPainter &) |
virtual void | paintGridState (QPainter &) |
virtual void | mouseReleaseEvent (QMouseEvent *) |
virtual QPoint | decodePosition (QPoint p) const |
Decodes a position to "cell coordinates". | |
virtual QSize | cellSize () const |
Returns size of one cell. | |
void | deleteGrid () |
Protected Attributes | |
unsigned int | gridWidth |
Number of grid cells in a row. | |
unsigned int | gridHeight |
Number of grid cells in a column. | |
char ** | gridState |
Array of the states of Grid::gridWidth times Grid::gridHeight cells. | |
QVector< QColor > | colors |
Colors used for grid states. | |
bool | autoSet |
Sets cells automatically on mouse click. |
A click sensitive grid widget.
This widget provides a dynamic grid which is sensitive to clicks (if not disabled).
Grid::Grid | ( | QWidget * | parent = 0 , |
unsigned int | w = 1 , |
||
unsigned int | h = 1 |
||
) |
Grid::~Grid | ( | ) | [virtual] |
QSize Grid::cellSize | ( | ) | const [protected, virtual] |
Returns size of one cell.
bool Grid::clearCell | ( | unsigned int | x, |
unsigned int | y | ||
) |
Clears a cell. Same as setGrid (x, y, 0).
x | |
y |
bool Grid::clearCell | ( | QPoint | p | ) |
Clears a cell.
void Grid::clearCells | ( | char | state | ) |
Clears all cells with a specific state.
state |
void Grid::clearGrid | ( | ) |
Clears grid.
void Grid::clicked | ( | QPoint | cell, |
Qt::MouseButton | button | ||
) | const [signal] |
Signals a click to a cell.
cell | Cell user clicked on |
button | Mousebutton used |
QPoint Grid::decodePosition | ( | QPoint | p | ) | const [protected, virtual] |
Decodes a position to "cell coordinates".
p | Coordinate (pixels) relative to widget |
void Grid::deleteGrid | ( | ) | [protected] |
bool Grid::getAutoSet | ( | ) |
Returns if autoSet is enabled.
char Grid::getCell | ( | QPoint | p | ) | const |
Returns state of a cell.
char Grid::getCell | ( | unsigned int | x, |
unsigned int | y | ||
) | const |
Returns state of a cell.
x | |
y |
const char *const Grid::getGrid | ( | ) | const |
Returns complete grid.
const QSize Grid::getGridSize | ( | ) | const |
Returns grid size.
void Grid::mouseReleaseEvent | ( | QMouseEvent * | m | ) | [protected, virtual] |
void Grid::paintEvent | ( | QPaintEvent * | e | ) | [protected, virtual] |
void Grid::paintGrid | ( | QPainter & | p | ) | [protected, virtual] |
void Grid::paintGridState | ( | QPainter & | p | ) | [protected, virtual] |
void Grid::setAutoSet | ( | bool | enable | ) |
Sets if autoSet function is activated. If autoSet is activated, grid cells get set automatically on leftclick and deset on rightclick.
enable | autoSet enabled if true |
bool Grid::setCell | ( | QPoint | p, |
char | state = 1 |
||
) |
Sets a cell.
bool Grid::setCell | ( | unsigned int | x, |
unsigned int | y, | ||
char | state = 1 |
||
) |
Sets a cell.
x | |
y | |
state | [optional] Defaults to 1 |
void Grid::setCellColor | ( | char | state, |
QColor | color | ||
) |
Sets the color for a cell state.
void Grid::setGrid | ( | const char *const * | grid, |
unsigned int | width, | ||
unsigned int | height | ||
) |
Sets a complete new grid. The grid pointer should be deleted by the caller.
width | Length of first array dimension |
height | Length of second array dimension |
grid | New grid state array |
void Grid::setGridSize | ( | unsigned int | width, |
unsigned int | height, | ||
bool | preserve = true |
||
) |
Resizes the grid.
width | |
height | |
preserve | Preserves current grid state if true. If new grid is bigger than old one, new cells get set to 0. If grid is smaller, grid state is clipped right/bottom. |
bool Grid::autoSet [protected] |
Sets cells automatically on mouse click.
QVector<QColor> Grid::colors [protected] |
Colors used for grid states.
unsigned int Grid::gridHeight [protected] |
Number of grid cells in a column.
char** Grid::gridState [protected] |
Array of the states of Grid::gridWidth times Grid::gridHeight cells.
unsigned int Grid::gridWidth [protected] |
Number of grid cells in a row.