Permalink
Browse files

removed feather cursor visual when useFeather is not activated

also, I forgot that we can’t make Properties static as it would share
all properties across the tools…

also refactored penciltool a bit to work with the cursor changes.
  • Loading branch information...
CandyFace committed Dec 5, 2017
1 parent b896e95 commit 8ccbaebc46952977123f320d3380d3e2fbf0cee6
@@ -864,13 +864,16 @@ 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(scalingFac);
mCursorImg = currentTool()->quickSizeCursor(brushWidth, brushFeather, scalingFac);
}
else if (mEditor->preference()->isOn(SETTING::DOTTED_CURSOR))
{
mCursorImg = currentTool()->canvasCursor(scalingFac, width());
bool useFeather = currentTool()->properties.useFeather;
mCursorImg = currentTool()->canvasCursor(brushWidth, brushFeather, useFeather, scalingFac, width());
}
else
{
@@ -1124,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
@@ -28,7 +28,6 @@ GNU General Public License for more details.
ToolPropertyType BaseTool::assistedSettingType; // setting beeing changed
qreal BaseTool::OriginalSettingValue; // start value (width, feather ..)
bool BaseTool::isAdjusting = false;
Properties BaseTool::properties;
QString BaseTool::TypeName( ToolType type )
@@ -105,24 +104,40 @@ void BaseTool::mouseDoubleClickEvent( QMouseEvent* event )
* @brief precision circular cursor: used for drawing a cursor within scribble area.
* @return QPixmap
*/
QPixmap BaseTool::canvasCursor(float scalingFac, int windowWidth)
QPixmap BaseTool::canvasCursor(float width, float feather, bool useFeather, float scalingFac, int windowWidth)
{
float propWidth = properties.width * scalingFac;
float propFeather = properties.feather * scalingFac;
float 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 (useFeather) {
cursorWidth = propWidth + 0.5 * propFeather;
xyA = 1 + propFeather / 2;
xyB = 1 + propFeather / 8;
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; }
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() )
{
@@ -139,14 +154,16 @@ QPixmap BaseTool::canvasCursor(float scalingFac, int windowWidth)
cursorPainter.drawLine( QPointF( radius, radius - 2 ), QPointF( radius, radius + 2 ) );
// Draw outer circle
cursorPen.setStyle( Qt::DotLine );
cursorPen.setColor( QColor( 0, 0, 0, 255 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawEllipse( QRectF( xyB, xyB, whB, whB ) );
cursorPen.setDashOffset( 4 );
cursorPen.setColor( QColor( 255, 255, 255, 255 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawEllipse( QRectF( xyB, xyB, whB, whB ) );
if (useFeather) {
cursorPen.setStyle( Qt::DotLine );
cursorPen.setColor( QColor( 0, 0, 0, 255 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawEllipse( QRectF( xyB, xyB, whB, whB ) );
cursorPen.setDashOffset( 4 );
cursorPen.setColor( QColor( 255, 255, 255, 255 ) );
cursorPainter.setPen(cursorPen);
cursorPainter.drawEllipse( QRectF( xyB, xyB, whB, whB ) );
}
// Draw inner circle
cursorPen.setStyle( Qt::DotLine );
@@ -167,10 +184,10 @@ QPixmap BaseTool::canvasCursor(float scalingFac, int windowWidth)
* @brief precision circular cursor: used for drawing stroke size while adjusting
* @return QPixmap
*/
QPixmap BaseTool::quickSizeCursor(float scalingFac)
QPixmap BaseTool::quickSizeCursor(float brushWidth, float brushFeather, float scalingFac)
{
float propWidth = properties.width * scalingFac;
float propFeather = properties.feather * scalingFac;
float propWidth = brushWidth * scalingFac;
float propFeather = brushFeather * scalingFac;
float cursorWidth = propWidth + 0.5 * propFeather;
if ( cursorWidth < 1 ) { cursorWidth = 1; }
View
@@ -91,8 +91,8 @@ class BaseTool : public QObject
virtual void clear() {}
static bool isAdjusting;
static QPixmap canvasCursor(float scalingFac, int windowWidth);
static QPixmap quickSizeCursor(float scalingFac);
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 );
@@ -110,7 +110,7 @@ class BaseTool : public QObject
virtual void leavingThisTool(){}
virtual void switchingLayers(){}
static Properties properties;
Properties properties;
QPointF getCurrentPixel();
QPointF getCurrentPoint();
@@ -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 8ccbaeb

Please sign in to comment.