Grid 0.1
QT Widget representing a grid

Grid Class Reference

A click sensitive grid widget. More...

#include <grid.h>

List of all members.

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.

Detailed Description

A click sensitive grid widget.

Author:
F.Satzger
Todo:
Keybased input

This widget provides a dynamic grid which is sensitive to clicks (if not disabled).


Constructor & Destructor Documentation

Grid::Grid ( QWidget *  parent = 0,
unsigned int  w = 1,
unsigned int  h = 1 
)
Grid::~Grid ( ) [virtual]

Member Function Documentation

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).

Parameters:
x
y
Returns:
false if (x,y) out of bounds
bool Grid::clearCell ( QPoint  p)
void Grid::clearCells ( char  state)

Clears all cells with a specific state.

Parameters:
state
See also:
clearCell(unsigned int x, unsigned int y)
void Grid::clearGrid ( )
void Grid::clicked ( QPoint  cell,
Qt::MouseButton  button 
) const [signal]

Signals a click to a cell.

Parameters:
cellCell user clicked on
buttonMousebutton used
QPoint Grid::decodePosition ( QPoint  p) const [protected, virtual]

Decodes a position to "cell coordinates".

Parameters:
pCoordinate (pixels) relative to widget
Returns:
Coordinates of cell containing the given point
void Grid::deleteGrid ( ) [protected]
bool Grid::getAutoSet ( )

Returns if autoSet is enabled.

See also:
setAutoSet
char Grid::getCell ( QPoint  p) const

Returns state of a cell.

See also:
getCell(unsigned int x, unsigned int y) const
char Grid::getCell ( unsigned int  x,
unsigned int  y 
) const

Returns state of a cell.

Parameters:
x
y
Returns:
Cell state. If coordinates are out of bounds, 0 is returned.
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.

Parameters:
enableautoSet enabled if true
See also:
getAutoSet
bool Grid::setCell ( QPoint  p,
char  state = 1 
)
bool Grid::setCell ( unsigned int  x,
unsigned int  y,
char  state = 1 
)

Sets a cell.

Parameters:
x
y
state[optional] Defaults to 1
Returns:
false if (x,y) out of bounds
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.

Parameters:
widthLength of first array dimension
heightLength of second array dimension
gridNew grid state array
void Grid::setGridSize ( unsigned int  width,
unsigned int  height,
bool  preserve = true 
)

Resizes the grid.

Parameters:
width
height
preservePreserves 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.

Member Data Documentation

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.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables