grid.h
/***************************************************************************
** **
** GridView, a simple GridView made with Qt4 **
** Copyright (C) 2013 Sacha Schutz **
** **
** This program is free software: you can redistribute it and/or modify **
** it under the terms of the GNU General Public License as published by **
** the Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see http://www.gnu.org/licenses/. **
** **
****************************************************************************
** Author : Sacha Schutz **
** Website: http://www.labsquare.org **
** Email : sacha@labsquare.org **
** Date : 12.03.12 **
****************************************************************************/
#ifndef GRIDVIEW_H
#define GRIDVIEW_H
#include <QtGui>
#include <QWidget>
#include <QScrollArea>
#include <QVector>
class GridWidget;
class GridWidget : public QWidget
{
Q_OBJECT
public:
explicit GridWidget(int rowCount = 100, int columnCount =100,QWidget *parent = 0);
GridWidget(QWidget *parent);
void setGridSize(int rowCount, int columnCount);
void switchOn(int x,int y, const QColor& color);
QColor getCellColor(int x, int y) ;
void switchOff(int x, int y);
int getGridColumns() ;
int getGridRows() ;
void clear();
void setCellSize(int size);
void setTool(QString tool);
void setFront(QString front);
void setBack(QString back);
void setToolSize(int size);
void identifyTool(QString tool, int x, int y);
void Dot(int x, int y, QColor colorSelected);
void RowMajorFill(int x, int y, QColor colorClicked, QColor toolColor);
void ColMajorFill(int x, int y, QColor colorClicked, QColor toolColor);
void DiagonalLeft(int x, int y, QColor colorClicked, QColor toolColor);
void DiagonalRight(int x, int y, QColor colorClicked, QColor toolColor);
void square(int x, int y, QColor toolColor, int toolSize);
void triangle(int x, int y, QColor toolColor, int toolSize);
void circle(int x, int y, QColor toolColor, int toolSize);
void undo();
void redo();
protected:
void drawGrid(QPaintDevice * device);
virtual void paintEvent(QPaintEvent *);
virtual void mousePressEvent(QMouseEvent *);
signals:
void cellClicked(QPoint pos);
void canUndo(bool can);
void canRedo(bool can);
private:
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;
};
#endif // GRIDVIEW_H
GridWidget::frontColor
QColor frontColor
Definition: grid.h:452
GridWidget::Dot
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 th...
Definition: tools.cpp:17
GridWidget::mCellSize
int mCellSize
Definition: grid.h:437
GridWidget::circle
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 ...
Definition: tools.cpp:243
GridWidget::mColumnCount
int mColumnCount
Definition: grid.h:441
GridWidget::getGridColumns
int getGridColumns()
Returns the number of columns in the grid.
Definition: grid.cpp:302
GridWidget::mColors
QHash< int, QColor > mColors
Definition: grid.h:445
GridWidget::setGridSize
void setGridSize(int rowCount, int columnCount)
Sets the number of columns and rows of the grid.
Definition: grid.cpp:155
GridWidget::ToolSize
int ToolSize
Definition: grid.h:450
GridWidget::DiagonalLeft
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 ...
Definition: tools.cpp:111
GridWidget::triangle
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 wit...
Definition: tools.cpp:213
GridWidget::getGridRows
int getGridRows()
Returns the number of rows in the grid.
Definition: grid.cpp:313
GridWidget::DiagonalRight
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 ...
Definition: tools.cpp:147
GridWidget::oldStates
QVector< QHash< int, QColor > > oldStates
Definition: grid.h:458
GridWidget::mRowCount
int mRowCount
Definition: grid.h:439
GridWidget::mGridPix
QPixmap mGridPix
Definition: grid.h:443
GridWidget::switchOn
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...
Definition: grid.cpp:271
GridWidget::ColMajorFill
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) ...
Definition: tools.cpp:75
GridWidget::drawGrid
void drawGrid(QPaintDevice *device)
Function that first sets the size of the GridWidget, then paints the cells with the color selected fo...
Definition: grid.cpp:370
GridWidget::backColor
QColor backColor
Definition: grid.h:454
GridWidget::switchOff
void switchOff(int x, int y)
Removes the given position from the vector that represents the painted cells of the grid...
Definition: grid.cpp:328
GridWidget::redo
void redo()
When the redo button is pressed the current state is pushed into the undo vector(oldStates) and the l...
Definition: grid.cpp:245
GridWidget::getCellColor
QColor getCellColor(int x, int y)
Returns the color of the cell in position (x,y)
Definition: grid.cpp:289
GridWidget::Tool
QString Tool
Definition: grid.h:448
GridWidget::setTool
void setTool(QString tool)
Sets the tool.
Definition: grid.cpp:109
GridWidget::clear
void clear()
Clears the grid and sets it to its initial state.
Definition: grid.cpp:339
GridWidget::mousePressEvent
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 the...
Definition: grid.cpp:186
GridWidget::newStates
QVector< QHash< int, QColor > > newStates
Definition: grid.h:460
GridWidget::setFront
void setFront(QString front)
Sets the color of the brush.
Definition: grid.cpp:120
GridWidget::square
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 ...
Definition: tools.cpp:181
GridWidget::setToolSize
void setToolSize(int size)
Sets the size of the tool.
Definition: grid.cpp:142
GridWidget::setBack
void setBack(QString back)
Sets the color of the background.
Definition: grid.cpp:131
GridWidget::GridWidget
GridWidget(int rowCount=100, int columnCount=100, QWidget *parent=0)
Constructor which receives the number of rows and columns in the grid.
Definition: grid.cpp:85
GridWidget::setCellSize
void setCellSize(int size)
Sets the size of the cells in the grid.
Definition: grid.cpp:354
GridWidget::RowMajorFill
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 righ...
Definition: tools.cpp:40
GridWidget
Definition: grid.h:42
GridWidget::background
QColor background
Definition: grid.h:456
GridWidget::identifyTool
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 ...
Definition: grid.cpp:424
GridWidget::undo
void undo()
When the undo button is pressed the current state is pushed into the redo vector(newStates) and the l...
Definition: grid.cpp:214
GridWidget::paintEvent
virtual void paintEvent(QPaintEvent *)
This function is automatically invoked each time the widget or its parent receives a repaint signal...
Definition: grid.cpp:170