#include <QtGui>
#include "characterwidget.h"
#include "mainwindow.h"
bool flag=false;
static int irow =16;
static int icol = 0 ;
CharacterWidget
::CharacterWidget(QWidget *parent
){
squareSize = 16;
columns = 16;
setMouseTracking(true);
}
QSize CharacterWidget
::sizeHint() const {
return QSize(columns
*squareSize, columns
*squareSize
);
}
void CharacterWidget
::mouseMoveEvent(QMouseEvent *event
) {
QPoint widgetPosition
= mapFromGlobal
(event
->globalPos
());
uint key = (widgetPosition.y()/squareSize)*columns + widgetPosition.x()/squareSize;
QToolTip::showText(event
->globalPos
(), text,
this);
}
void CharacterWidget::FillColor()
{
flag=true;
update();
}
{
painter.
fillRect(event
->rect
(),
QBrush(Qt
::white));
QRect redrawRect
= event
->rect
();
int beginRow = redrawRect.top()/squareSize;
int endRow = redrawRect.bottom()/squareSize;
int beginColumn = redrawRect.left()/squareSize;
int endColumn = redrawRect.right()/squareSize;
painter.
setPen(QPen(Qt
::gray));
for (int row = beginRow; row<=endRow;++row)
{
for (int column = beginColumn; column <= endColumn; ++column)
{
painter.drawRect(column*squareSize, row*squareSize, squareSize, squareSize);
}
}
painter.
setPen(QPen(Qt
::black));
if(flag == true)
{
for (int row =beginRow; row<=icol;++row)
{
for (int column = beginColumn; column<=irow;++column)
{
painter.setClipRect(column*squareSize, row*squareSize, squareSize, squareSize);
painter.
fillRect(column
*squareSize
+1, row
*squareSize
+1, squareSize, squareSize,
QBrush(Qt
::blue));
}
}
icol++;
}
}
#include <QtGui>
#include "characterwidget.h"
#include "mainwindow.h"
bool flag=false;
static int irow =16;
static int icol = 0 ;
CharacterWidget::CharacterWidget(QWidget *parent)
: QWidget(parent)
{
squareSize = 16;
columns = 16;
setMouseTracking(true);
}
QSize CharacterWidget::sizeHint() const
{
return QSize(columns*squareSize, columns*squareSize);
}
void CharacterWidget::mouseMoveEvent(QMouseEvent *event)
{
QPoint widgetPosition = mapFromGlobal(event->globalPos());
uint key = (widgetPosition.y()/squareSize)*columns + widgetPosition.x()/squareSize;
QString text = QString::number(key,10);
QToolTip::showText(event->globalPos(), text, this);
}
void CharacterWidget::FillColor()
{
flag=true;
update();
}
void CharacterWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPainterPath myPath;
painter.fillRect(event->rect(), QBrush(Qt::white));
QRect redrawRect = event->rect();
int beginRow = redrawRect.top()/squareSize;
int endRow = redrawRect.bottom()/squareSize;
int beginColumn = redrawRect.left()/squareSize;
int endColumn = redrawRect.right()/squareSize;
painter.setPen(QPen(Qt::gray));
for (int row = beginRow; row<=endRow;++row)
{
for (int column = beginColumn; column <= endColumn; ++column)
{
painter.drawRect(column*squareSize, row*squareSize, squareSize, squareSize);
}
}
painter.setPen(QPen(Qt::black));
if(flag == true)
{
for (int row =beginRow; row<=icol;++row)
{
for (int column = beginColumn; column<=irow;++column)
{
painter.setClipRect(column*squareSize, row*squareSize, squareSize, squareSize);
painter.fillRect(column*squareSize+1, row*squareSize+1, squareSize, squareSize, QBrush(Qt::blue));
}
}
icol++;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks