Updated the painting algorithm for the cache

preferencesAboutTextFull
shibakaneki 13 years ago
parent f7a2d469d3
commit 545e19fa20
  1. 36
      src/tools/UBGraphicsCache.cpp
  2. 3
      src/tools/UBGraphicsCache.h

@ -87,7 +87,7 @@ void UBGraphicsCache::init()
void UBGraphicsCache::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void UBGraphicsCache::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
Q_UNUSED(option); //Q_UNUSED(option);
Q_UNUSED(widget); Q_UNUSED(widget);
setZValue(CACHE_ZVALUE); setZValue(CACHE_ZVALUE);
@ -95,6 +95,7 @@ void UBGraphicsCache::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
painter->setBrush(mMaskColor); painter->setBrush(mMaskColor);
painter->setPen(mMaskColor); painter->setPen(mMaskColor);
// Draw the hole
QPainterPath path; QPainterPath path;
path.addRect(rect()); path.addRect(rect());
@ -119,20 +120,32 @@ void UBGraphicsCache::mousePressEvent(QGraphicsSceneMouseEvent *event)
Q_UNUSED(event); Q_UNUSED(event);
mShapePos = event->pos(); mShapePos = event->pos();
mDrawMask = true; mDrawMask = true;
update();
// Note: if refresh issues occure, replace the following 3 lines by: update();
update(updateRect(event->pos()));
mOldShapeWidth = mShapeWidth;
mOldShapePos = event->pos();
} }
void UBGraphicsCache::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsCache::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
mShapePos = event->pos(); mShapePos = event->pos();
update();
// Note: if refresh issues occure, replace the following 3 lines by: update();
update(updateRect(event->pos()));
mOldShapeWidth = mShapeWidth;
mOldShapePos = event->pos();
} }
void UBGraphicsCache::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsCache::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
mDrawMask = false; mDrawMask = false;
update();
// Note: if refresh issues occure, replace the following 3 lines by: update();
update(updateRect(event->pos()));
mOldShapeWidth = mShapeWidth;
mOldShapePos = event->pos();
} }
int UBGraphicsCache::shapeWidth() int UBGraphicsCache::shapeWidth()
@ -145,3 +158,18 @@ void UBGraphicsCache::setShapeWidth(int width)
mShapeWidth = width; mShapeWidth = width;
update(); update();
} }
QRectF UBGraphicsCache::updateRect(QPointF currentPoint)
{
QRectF r;
int x;
int y;
x = qMin(currentPoint.x() - mShapeWidth, mOldShapePos.x() - mOldShapeWidth);
y = qMin(currentPoint.y() - mShapeWidth, mOldShapePos.y() - mOldShapeWidth);
r = QRect( x,
y,
qAbs(currentPoint.x() - mOldShapePos.x()) + 2*mShapeWidth,
qAbs(currentPoint.y() - mOldShapePos.y()) + 2*mShapeWidth);
return r;
}

@ -56,12 +56,15 @@ protected:
private: private:
void init(); void init();
QRectF updateRect(QPointF currentPoint);
QColor mMaskColor; QColor mMaskColor;
eMaskShape mMaskShape; eMaskShape mMaskShape;
int mShapeWidth; int mShapeWidth;
bool mDrawMask; bool mDrawMask;
QPointF mShapePos; QPointF mShapePos;
int mOldShapeWidth;
QPointF mOldShapePos;
}; };
#endif // UBGRAPHICSCACHE_H #endif // UBGRAPHICSCACHE_H

Loading…
Cancel
Save