My Project
Signals | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
GridWidget Class Reference

#include <grid.h>

Inheritance diagram for GridWidget:

Signals

void cellClicked (QPoint pos)
 
void canUndo (bool can)
 
void canRedo (bool can)
 

Public Member Functions

 GridWidget (int rowCount=100, int columnCount=100, QWidget *parent=0)
 Constructor which receives the number of rows and columns in the grid. More...
 
 GridWidget (QWidget *parent)
 Default constructor. The properties of the grid are set as follows: More...
 
void setGridSize (int rowCount, int columnCount)
 Sets the number of columns and rows of the grid. More...
 
void switchOn (int x, int y, const QColor &color)
 Saves the given color and position in the vector that represents the painted cells of the grid. More...
 
QColor getCellColor (int x, int y)
 Returns the color of the cell in position (x,y) More...
 
void switchOff (int x, int y)
 Removes the given position from the vector that represents the painted cells of the grid. More...
 
int getGridColumns ()
 Returns the number of columns in the grid. More...
 
int getGridRows ()
 Returns the number of rows in the grid. More...
 
void clear ()
 Clears the grid and sets it to its initial state.
 
void setCellSize (int size)
 Sets the size of the cells in the grid. More...
 
void setTool (QString tool)
 Sets the tool. More...
 
void setFront (QString front)
 Sets the color of the brush. More...
 
void setBack (QString back)
 Sets the color of the background. More...
 
void setToolSize (int size)
 Sets the size of the tool. More...
 
void identifyTool (QString tool, int x, int y)
 This function is called on each mousePressEvent inside the grid. It identifies the way the grid will be painted calling the function of the tool received in the parameters (dot, rowfill, column fill, diagonal, square, triangles and circles). More...
 
void Dot (int x, int y, QColor colorSelected)
 Receives the coordinates of the grid where the user clicked and paints that cell with the color of the tool. More...
 
void RowMajorFill (int x, int y, QColor colorClicked, QColor toolColor)
 Receives the coordinates of the grid where the user clicked and paints (from that point left and right) the longest row of the same color of the cell that was clicked with the color of the tool. More...
 
void ColMajorFill (int x, int y, QColor colorClicked, QColor toolColor)
 Receives the coordinates of the grid where the user clicked and paints (from that point up and down) the longest column of the same color of the cell that was clicked with the color of the tool. More...
 
void DiagonalLeft (int x, int y, QColor colorClicked, QColor toolColor)
 Recieves the coordinates of the grid where the user clicked and paints (from that point) the longest left-diagonal of the color of the cell that was clicked with the color of the tool. More...
 
void DiagonalRight (int x, int y, QColor colorClicked, QColor toolColor)
 Recieves the coordinates of the grid where the user clicked and paints (from that point) the longest right-diagonal of the color of the cell that was clicked with the color of the tool. More...
 
void square (int x, int y, QColor toolColor, int toolSize)
 Receives the coordinates of the grid where the user clicked and paints a square of the size and with the color of the tool. More...
 
void triangle (int x, int y, QColor toolColor, int toolSize)
 Receives the coordinates of the grid where the user clicked and paints a triangle of the size and with the color of the tool. More...
 
void circle (int x, int y, QColor toolColor, int toolSize)
 Receives the coordinates of the grid where the user clicked and paints a circle of the size and with the color of the tool. More...
 
void undo ()
 When the undo button is pressed the current state is pushed into the redo vector(newStates) and the last state in the undo vector(oldStates) is painted on the grid.
 
void redo ()
 When the redo button is pressed the current state is pushed into the undo vector(oldStates) and the last state in the redo vector(newStates) is painted on the grid.
 

Protected Member Functions

void drawGrid (QPaintDevice *device)
 Function that first sets the size of the GridWidget, then paints the cells with the color selected for the background and finally paints the lines to form the grid. More...
 
virtual void paintEvent (QPaintEvent *)
 This function is automatically invoked each time the widget or its parent receives a repaint signal. More...
 
virtual void mousePressEvent (QMouseEvent *)
 When the mouse is clicked on a cell of the grid it gets the x,y coordinates of the mouse and uses them to paint the tool at that location. More...
 

Private Attributes

int mCellSize
 
int mRowCount
 
int mColumnCount
 
QPixmap mGridPix
 
QHash< int, QColor > mColors
 
QString Tool
 
int ToolSize
 
QColor frontColor
 
QColor backColor
 
QColor background
 
QVector< QHash< int, QColor > > oldStates
 
QVector< QHash< int, QColor > > newStates
 

Detailed Description

GridWidget: Shows a GridView without scrolling. If you want to have Scroll option, use GridView instead. GridWidget also supports mouse selection, sends the signal cellClicked with the associated grid coordinates.

Constructor & Destructor Documentation

GridWidget::GridWidget ( int  rowCount = 100,
int  columnCount = 100,
QWidget *  parent = 0 
)
explicit

Constructor which receives the number of rows and columns in the grid.

Parameters
rowCountnumber of rows in the grid
columnCountnumber of columns in the grid
parentparent window

Constructor que recibe el numero de filas y columnas en la cuadricula

Parameters
rowCountnumero de filas en la cuadricula
columnCountnumero de columnas en la cuadricula
parentventana padre
GridWidget::GridWidget ( QWidget *  parent)

Default constructor. The properties of the grid are set as follows:

  • mCellSize: Sets the size of the cell to 10px
  • mRowCount: Sets the number of rows in the grid to 39
  • mColumnCount: Sets the number of columns in the grid to 27
  • Tool and ToolSize: Sets the Tool which is going to be used to draw the grid
  • frontColor: The color which will be used to paint to black
  • backColor: Current clicked square
  • background: Sets the background color to white

Constructor por defecto. Las propiedades de el grid se ajustan como sigue:

  • mCellSize: Ajusta el tamano de la celda a 10px
  • mRowCount: Ajusta el numero de filas en la cuadricula a 39
  • ColumnCount: Ajusta el numero de columnas en el grid a 27
  • Tool and ToolSize: Ajusta la herramiento que se va a utilizar para dibujar el grid.
  • frontColor: El color que se utilizara para pintar a negro
  • backColor: Cuadrado marcado actualmente
  • background: El color del fondo en blanco

Member Function Documentation

void GridWidget::circle ( int  x,
int  y,
QColor  toolColor,
int  toolSize 
)

Receives the coordinates of the grid where the user clicked and paints a circle of the size and with the color of the tool.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
toolColorcolor of the cells painted by the tool
toolSizesize of the tool to be painted
void GridWidget::ColMajorFill ( int  x,
int  y,
QColor  colorClicked,
QColor  toolColor 
)

Receives the coordinates of the grid where the user clicked and paints (from that point up and down) the longest column of the same color of the cell that was clicked with the color of the tool.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
colorClickedcurrent color of the clicked cell
toolColorcolor of the cells painted by the tool
void GridWidget::DiagonalLeft ( int  x,
int  y,
QColor  colorClicked,
QColor  toolColor 
)

Recieves the coordinates of the grid where the user clicked and paints (from that point) the longest left-diagonal of the color of the cell that was clicked with the color of the tool.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
colorClickedcurrent color of the clicked cell
toolColorcolor of the cells painted by the tool
void GridWidget::DiagonalRight ( int  x,
int  y,
QColor  colorClicked,
QColor  toolColor 
)

Recieves the coordinates of the grid where the user clicked and paints (from that point) the longest right-diagonal of the color of the cell that was clicked with the color of the tool.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
colorClickedcurrent color of the clicked cell
toolColorcolor of the cells painted by the tool
void GridWidget::Dot ( int  x,
int  y,
QColor  toolColor 
)

Receives the coordinates of the grid where the user clicked and paints that cell with the color of the tool.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
toolColorcolor of the cells painted by the tool
void GridWidget::drawGrid ( QPaintDevice *  device)
protected

Function that first sets the size of the GridWidget, then paints the cells with the color selected for the background and finally paints the lines to form the grid.

Parameters
devicethe panel to paint the grid
QColor GridWidget::getCellColor ( int  x,
int  y 
)

Returns the color of the cell in position (x,y)

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
Returns
the color of the cell
int GridWidget::getGridColumns ( )

Returns the number of columns in the grid.

Returns
number of columns in the grid
int GridWidget::getGridRows ( )

Returns the number of rows in the grid.

Returns
number of rows in the grid
void GridWidget::identifyTool ( QString  tool,
int  x,
int  y 
)

This function is called on each mousePressEvent inside the grid. It identifies the way the grid will be painted calling the function of the tool received in the parameters (dot, rowfill, column fill, diagonal, square, triangles and circles).

Parameters
toolthe tool to be called by the funtion
xcoordinate x of the cell in the grid.
ycoordinate y of the cell in the grid.
void GridWidget::mousePressEvent ( QMouseEvent *  event)
protectedvirtual

When the mouse is clicked on a cell of the grid it gets the x,y coordinates of the mouse and uses them to paint the tool at that location.

Parameters
eventreceived event reference
void GridWidget::paintEvent ( QPaintEvent *  event)
protectedvirtual

This function is automatically invoked each time the widget or its parent receives a repaint signal.

Parameters
eventreceived event reference
void GridWidget::RowMajorFill ( int  x,
int  y,
QColor  colorClicked,
QColor  toolColor 
)

Receives the coordinates of the grid where the user clicked and paints (from that point left and right) the longest row of the same color of the cell that was clicked with the color of the tool.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
colorClickedcurrent color of the clicked cell
toolColorcolor of the cells painted by the tool
void GridWidget::setBack ( QString  back)

Sets the color of the background.

Parameters
backbackground color
void GridWidget::setCellSize ( int  size)

Sets the size of the cells in the grid.

Parameters
sizecell size
void GridWidget::setFront ( QString  front)

Sets the color of the brush.

Parameters
frontbrush color
void GridWidget::setGridSize ( int  rowCount,
int  columnCount 
)

Sets the number of columns and rows of the grid.

Parameters
rowCountnumber of rows
columnCountnumber of columns
void GridWidget::setTool ( QString  tool)

Sets the tool.

Parameters
toolchoosen tool
toolherramienta escogida
void GridWidget::setToolSize ( int  size)

Sets the size of the tool.

Parameters
sizetool size
void GridWidget::square ( int  x,
int  y,
QColor  toolColor,
int  toolSize 
)

Receives the coordinates of the grid where the user clicked and paints a square of the size and with the color of the tool.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
toolColorcolor of the cells painted by the tool
toolSizesize of the tool to be painted
void GridWidget::switchOff ( int  x,
int  y 
)

Removes the given position from the vector that represents the painted cells of the grid.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
void GridWidget::switchOn ( int  x,
int  y,
const QColor &  color 
)

Saves the given color and position in the vector that represents the painted cells of the grid.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
colorcolor to paint cell
void GridWidget::triangle ( int  x,
int  y,
QColor  toolColor,
int  toolSize 
)

Receives the coordinates of the grid where the user clicked and paints a triangle of the size and with the color of the tool.

Parameters
xcoordinate x of the cell in the grid
ycoordinate y of the cell in the grid
toolColorcolor of the cells painted by the tool
toolSizesize of the tool to be painted

Member Data Documentation

QColor GridWidget::backColor
private

background color of the cell / color del fondo de la celda

QColor GridWidget::background
private

cell size / tamano del la celda

QColor GridWidget::frontColor
private

color of the front cell / color de la celda de frente

int GridWidget::mCellSize
private

cell size / tamano del la celda

QHash<int, QColor > GridWidget::mColors
private

Hash of colors with the painted cells and their colors / Hash de colores con las celdas pintadas y sus colores

int GridWidget::mColumnCount
private

column number / numero de columnas

QPixmap GridWidget::mGridPix
private

to paint the grid / para pintar la cuadricula

int GridWidget::mRowCount
private

row number / numero de filas

QVector< QHash<int, QColor > > GridWidget::newStates
private

vector to implement undo/redo

QVector< QHash<int, QColor > > GridWidget::oldStates
private

vetor to implement undo/redo

QString GridWidget::Tool
private

name of the tool selected / nombre de la herramienta seleccionada

int GridWidget::ToolSize
private

tool size / tamano del a herramienta


The documentation for this class was generated from the following files: