My Project
|
#include <grid.h>
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 |
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.
|
explicit |
Constructor which receives the number of rows and columns in the grid.
rowCount | number of rows in the grid |
columnCount | number of columns in the grid |
parent | parent window |
Constructor que recibe el numero de filas y columnas en la cuadricula
rowCount | numero de filas en la cuadricula |
columnCount | numero de columnas en la cuadricula |
parent | ventana padre |
GridWidget::GridWidget | ( | QWidget * | parent | ) |
Default constructor. The properties of the grid are set as follows:
Constructor por defecto. Las propiedades de el grid se ajustan como sigue:
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.
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
toolColor | color of the cells painted by the tool |
toolSize | size 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.
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
colorClicked | current color of the clicked cell |
toolColor | color 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.
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
colorClicked | current color of the clicked cell |
toolColor | color 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.
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
colorClicked | current color of the clicked cell |
toolColor | color 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.
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
toolColor | color of the cells painted by the tool |
|
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.
device | the panel to paint the grid |
QColor GridWidget::getCellColor | ( | int | x, |
int | y | ||
) |
Returns the color of the cell in position (x,y)
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
int GridWidget::getGridColumns | ( | ) |
Returns the number of columns in the grid.
int GridWidget::getGridRows | ( | ) |
Returns the 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).
tool | the tool to be called by the funtion |
x | coordinate x of the cell in the grid. |
y | coordinate y of the cell in the grid. |
|
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.
event | received event reference |
|
protectedvirtual |
This function is automatically invoked each time the widget or its parent receives a repaint signal.
event | received 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.
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
colorClicked | current color of the clicked cell |
toolColor | color of the cells painted by the tool |
void GridWidget::setBack | ( | QString | back | ) |
Sets the color of the background.
back | background color |
void GridWidget::setCellSize | ( | int | size | ) |
Sets the size of the cells in the grid.
size | cell size |
void GridWidget::setFront | ( | QString | front | ) |
Sets the color of the brush.
front | brush color |
void GridWidget::setGridSize | ( | int | rowCount, |
int | columnCount | ||
) |
Sets the number of columns and rows of the grid.
rowCount | number of rows |
columnCount | number of columns |
void GridWidget::setTool | ( | QString | tool | ) |
Sets the tool.
tool | choosen tool |
tool | herramienta escogida |
void GridWidget::setToolSize | ( | int | size | ) |
Sets the size of the tool.
size | tool 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.
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
toolColor | color of the cells painted by the tool |
toolSize | size 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.
x | coordinate x of the cell in the grid |
y | coordinate 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.
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
color | color 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.
x | coordinate x of the cell in the grid |
y | coordinate y of the cell in the grid |
toolColor | color of the cells painted by the tool |
toolSize | size of the tool to be painted |
|
private |
background color of the cell / color del fondo de la celda
|
private |
cell size / tamano del la celda
|
private |
color of the front cell / color de la celda de frente
|
private |
cell size / tamano del la celda
|
private |
Hash of colors with the painted cells and their colors / Hash de colores con las celdas pintadas y sus colores
|
private |
column number / numero de columnas
|
private |
to paint the grid / para pintar la cuadricula
|
private |
row number / numero de filas
|
private |
vector to implement undo/redo
|
private |
vetor to implement undo/redo
|
private |
name of the tool selected / nombre de la herramienta seleccionada
|
private |
tool size / tamano del a herramienta