Permalink
Browse files

Merge pull request #828 from CandyFace/dottedCursor_improvement

dotted cursor improvement and fixes
  • Loading branch information...
chchwy committed Dec 6, 2017
2 parents 2adad08 + 8ccbaeb commit 9ebc52df622a3544e22ea41fe3b8bf2117d770d3
@@ -863,13 +863,17 @@ void ScribbleArea::paintCanvasCursor(QPainter& painter)
void ScribbleArea::updateCanvasCursor()
{
float scalingFac = mEditor->view()->scaling();
qreal brushWidth = currentTool()->properties.width;
qreal brushFeather = currentTool()->properties.feather;
if (currentTool()->isAdjusting)
{
mCursorImg = currentTool()->quickSizeCursor();
mCursorImg = currentTool()->quickSizeCursor(brushWidth, brushFeather, scalingFac);
}
else if (mEditor->preference()->isOn(SETTING::DOTTED_CURSOR))
{
mCursorImg = currentTool()->canvasCursor();
bool useFeather = currentTool()->properties.useFeather;
mCursorImg = currentTool()->canvasCursor(brushWidth, brushFeather, useFeather, scalingFac, width());
}
else
{
@@ -1123,9 +1127,9 @@ void ScribbleArea::drawPen(QPointF thePoint, qreal brushWidth, QColor fillColour
QPainter::CompositionMode_Source, useAA);
}
void ScribbleArea::drawPencil(QPointF thePoint, qreal brushWidth, QColor fillColour, qreal opacity)
void ScribbleArea::drawPencil(QPointF thePoint, qreal brushWidth, qreal fixedBrushFeather, QColor fillColour, qreal opacity)
{
drawBrush(thePoint, brushWidth, 50, fillColour, opacity, true);
drawBrush(thePoint, brushWidth, fixedBrushFeather, fillColour, opacity, true);
}
void ScribbleArea::drawBrush(QPointF thePoint, qreal brushWidth, qreal mOffset, QColor fillColour, qreal opacity, bool usingFeather, int useAA)
@@ -167,7 +167,7 @@ public slots:
void drawLine( QPointF P1, QPointF P2, QPen pen, QPainter::CompositionMode cm );
void drawPath( QPainterPath path, QPen pen, QBrush brush, QPainter::CompositionMode cm );
void drawPen( QPointF thePoint, qreal brushWidth, QColor fillColour, bool useAA = true );
void drawPencil( QPointF thePoint, qreal brushWidth, QColor fillColour, qreal opacity );
void drawPencil( QPointF thePoint, qreal brushWidth, qreal fixedBrushFeather, QColor fillColour, qreal opacity );
void drawBrush( QPointF thePoint, qreal brushWidth, qreal offset, QColor fillColour, qreal opacity, bool usingFeather = true, int useAA = 0 );
void blurBrush( BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_ );
void liquifyBrush( BitmapImage *bmiSource_, QPointF srcPoint_, QPointF thePoint_, qreal brushWidth_, qreal offset_, qreal opacity_ );
View
@@ -104,37 +104,57 @@ void BaseTool::mouseDoubleClickEvent( QMouseEvent* event )
* @brief precision circular cursor: used for drawing a cursor within scribble area.
* @return QPixmap
*/
QPixmap BaseTool::canvasCursor() // Todo: only one instance required: make fn static?
QPixmap BaseTool::canvasCursor(float width, float feather, bool useFeather, float scalingFac, int windowWidth)
{
Q_ASSERT( mEditor->getScribbleArea() );
float scalingFac = mEditor->view()->scaling();
propWidth = properties.width * scalingFac;
propFeather = properties.feather * scalingFac;
cursorWidth = propWidth + 0.5 * propFeather;
float propWidth = width * scalingFac;
float propFeather = feather * scalingFac;
float cursorWidth = 0.0f;
float xyA = 0.0f;
float xyB = 0.0f;
float whA = 0.0f;
float whB = 0.0f;
if ( cursorWidth < 1 ) { cursorWidth = 1; }
radius = cursorWidth / 2;
if (useFeather) {
cursorWidth = propWidth + 0.5 * propFeather;
xyA = 1 + propFeather / 2;
xyB = 1 + propFeather / 8;
whA = qMax( 0, propWidth - xyA - 1 );
whB = qMax( 0, cursorWidth - propFeather / 4 - 2 );
cursorPixmap = QPixmap( cursorWidth, cursorWidth );
if ( !cursorPixmap.isNull() )
{
cursorPixmap.fill( QColor( 255, 255, 255, 0 ) );
QPainter cursorPainter( &cursorPixmap );
cursorPen = cursorPainter.pen();
cursorPainter.setRenderHint(QPainter::HighQualityAntialiasing);
// Draw cross in center
cursorPen.setStyle( Qt::SolidLine );
cursorPen.setColor( QColor( 0, 0, 0, 127 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawLine( QPointF( radius - 2, radius ), QPointF( radius + 2, radius ) );
cursorPainter.drawLine( QPointF( radius, radius - 2 ), QPointF( radius, radius + 2 ) );
whA = qMax<float>( 0, propWidth - xyA - 1 );
whB = qMax<float>( 0, cursorWidth - propFeather / 4 - 2 );
} else {
cursorWidth = (propWidth + 0.5);
whA = qMax<float>( 0, propWidth - 1 );
whB = qMax<float>( 0, cursorWidth / 4 - 2 );
}
float radius = cursorWidth / 2;
// delocate when cursor width gets some value larger than the widget
if (cursorWidth > windowWidth * 2) {
return QPixmap(0,0);
}
if ( cursorWidth < 1 ) { cursorWidth = 1; }
QPixmap cursorPixmap = QPixmap( cursorWidth, cursorWidth );
if ( !cursorPixmap.isNull() )
{
cursorPixmap.fill( QColor( 255, 255, 255, 0 ) );
QPainter cursorPainter( &cursorPixmap );
QPen cursorPen = cursorPainter.pen();
cursorPainter.setRenderHint(QPainter::HighQualityAntialiasing);
// Draw outer circle
// Draw cross in center
cursorPen.setStyle( Qt::SolidLine );
cursorPen.setColor( QColor( 0, 0, 0, 127 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawLine( QPointF( radius - 2, radius ), QPointF( radius + 2, radius ) );
cursorPainter.drawLine( QPointF( radius, radius - 2 ), QPointF( radius, radius + 2 ) );
// Draw outer circle
if (useFeather) {
cursorPen.setStyle( Qt::DotLine );
cursorPen.setColor( QColor( 0, 0, 0, 255 ) );
cursorPainter.setPen(cursorPen);
@@ -143,42 +163,40 @@ QPixmap BaseTool::canvasCursor() // Todo: only one instance required: make fn st
cursorPen.setColor( QColor( 255, 255, 255, 255 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawEllipse( QRectF( xyB, xyB, whB, whB ) );
}
// Draw inner circle
cursorPen.setStyle( Qt::DotLine );
cursorPen.setColor( QColor( 0, 0, 0, 255 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawEllipse( QRectF( xyA, xyA, whA, whA ) );
cursorPen.setDashOffset( 4 );
cursorPen.setColor( QColor( 255, 255, 255, 255 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawEllipse( QRectF( xyA, xyA, whA, whA ) );
// Draw inner circle
cursorPen.setStyle( Qt::DotLine );
cursorPen.setColor( QColor( 0, 0, 0, 255 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawEllipse( QRectF( xyA, xyA, whA, whA ) );
cursorPen.setDashOffset( 4 );
cursorPen.setColor( QColor( 255, 255, 255, 255 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawEllipse( QRectF( xyA, xyA, whA, whA ) );
cursorPainter.end();
}
return cursorPixmap;
cursorPainter.end();
}
return cursorPixmap;
}
/**
* @brief precision circular cursor: used for drawing stroke size while adjusting
* @return QPixmap
*/
QPixmap BaseTool::quickSizeCursor() // Todo: only one instance required: make fn static?
QPixmap BaseTool::quickSizeCursor(float brushWidth, float brushFeather, float scalingFac)
{
Q_ASSERT( mEditor->getScribbleArea() );
float scalingFac = mEditor->view()->scaling();
propWidth = properties.width * scalingFac;
propFeather = properties.feather * scalingFac;
cursorWidth = propWidth + 0.5 * propFeather;
float propWidth = brushWidth * scalingFac;
float propFeather = brushFeather * scalingFac;
float cursorWidth = propWidth + 0.5 * propFeather;
if ( cursorWidth < 1 ) { cursorWidth = 1; }
radius = cursorWidth / 2;
xyA = 1 + propFeather / 2;
xyB = 1 + propFeather / 8;
whA = qMax( 0, propWidth - xyA - 1 );
whB = qMax( 0, cursorWidth - propFeather / 4 - 2 );
cursorPixmap = QPixmap( cursorWidth, cursorWidth );
float radius = cursorWidth / 2;
float xyA = 1 + propFeather / 2;
float xyB = 1 + propFeather / 8;
float whA = qMax<float>( 0, propWidth - xyA - 1 );
float whB = qMax<float>( 0, cursorWidth - propFeather / 4 - 2 );
QPixmap cursorPixmap = QPixmap( cursorWidth, cursorWidth );
if ( !cursorPixmap.isNull() )
{
cursorPixmap.fill( QColor( 255, 255, 255, 0 ) );
View
@@ -91,8 +91,8 @@ class BaseTool : public QObject
virtual void clear() {}
static bool isAdjusting;
QPixmap canvasCursor();
QPixmap quickSizeCursor();
static QPixmap canvasCursor(float brushWidth, float brushFeather, bool useFeather, float scalingFac, int windowWidth);
static QPixmap quickSizeCursor(float brushWidth, float brushFeather, float scalingFac);
virtual void setWidth( const qreal width );
virtual void setFeather( const qreal feather );
@@ -131,18 +131,6 @@ class BaseTool : public QObject
qreal mAdjustmentStep = 0.0f;
private:
int propWidth;
int propFeather;
int width;
int cursorWidth;
int radius;
int xyA;
int xyB;
int whA;
int whB;
QPixmap cursorPixmap;
QPen cursorPen;
};
#endif // BASETOOL_H
@@ -46,10 +46,11 @@ void PencilTool::loadSettings()
QSettings settings( PENCIL2D, PENCIL2D );
properties.width = settings.value( "pencilWidth" ).toDouble();
properties.feather = 1;
properties.feather = 50;
properties.pressure = settings.value( "pencilPressure" ).toBool();
properties.inpolLevel = 0;
properties.useAA = -1;
properties.useFeather = true;
properties.useFillContour = false;
// properties.invisibility = 1;
@@ -81,6 +82,18 @@ void PencilTool::setFeather( const qreal feather )
properties.feather = feather;
}
void PencilTool::setUseFeather( const bool usingFeather )
{
// Set current property
properties.useFeather = usingFeather;
// Update settings
QSettings settings( PENCIL2D, PENCIL2D );
settings.setValue("brushUseFeather", usingFeather);
settings.sync();
}
void PencilTool::setInvisibility( const bool )
{
// force value
@@ -230,12 +243,14 @@ void PencilTool::paintAt( QPointF point )
mCurrentWidth *= mCurrentPressure;
}
qreal brushWidth = mCurrentWidth;
qreal fixedBrushFeather = properties.feather;
BlitRect rect;
rect.extend( point.toPoint() );
mScribbleArea->drawPencil(point,
brushWidth,
fixedBrushFeather,
mEditor->color()->frontColor(),
opacity);
@@ -261,6 +276,7 @@ void PencilTool::drawStroke()
mCurrentWidth = properties.width * mCurrentPressure;
}
qreal brushWidth = mCurrentWidth;
qreal fixedBrushFeather = properties.feather;
qreal brushStep = (0.5 * brushWidth);
brushStep = qMax( 1.0, brushStep );
@@ -279,6 +295,7 @@ void PencilTool::drawStroke()
rect.extend( point.toPoint() );
mScribbleArea->drawPencil(point,
brushWidth,
fixedBrushFeather,
mEditor->color()->frontColor(),
opacity );
@@ -296,6 +313,8 @@ void PencilTool::drawStroke()
}
else if ( layer->type() == Layer::VECTOR )
{
properties.useFeather = false;
properties.width = 0;
QPen pen( mEditor->color()->frontColor(),
1,
Qt::DotLine,
@@ -45,6 +45,7 @@ class PencilTool : public StrokeTool
void setWidth( const qreal width ) override;
void setFeather( const qreal feather ) override;
void setUseFeather( const bool useFeather ) override;
void setInvisibility( const bool invisibility ) override;
void setPressure( const bool pressure ) override;
void setPreserveAlpha( const bool preserveAlpha ) override;

0 comments on commit 9ebc52d

Please sign in to comment.