Commit d619b713 authored by Dmitry Kazakov's avatar Dmitry Kazakov

FEATURE: Add backgroung color as an option for newly created shapes

In vector tools, we use bg-color as stroke and fg-color as fill. This
patch makes it possible to have the same configuration in the shape
creation tools.

BUG:381922
parent 7254c8d1
......@@ -1400,13 +1400,6 @@ void KisPainter::Private::fillPainterPathImpl(const QPainterPath& path, const QR
switch (fillStyle) {
default:
Q_FALLTHROUGH();
case FillStyleGradient:
// Currently unsupported
Q_FALLTHROUGH();
case FillStyleStrokes:
// Currently unsupported
warnImage << "Unknown or unsupported fill style in fillPolygon\n";
Q_FALLTHROUGH();
case FillStyleForegroundColor:
fillPainter->fillRect(fillRect, q->paintColor(), OPACITY_OPAQUE_U8);
break;
......
......@@ -722,9 +722,7 @@ public:
FillStyleForegroundColor,
FillStyleBackgroundColor,
FillStylePattern,
FillStyleGradient,
FillStyleStrokes,
FillStyleGenerator,
FillStyleGenerator
};
/// Set the current style with which to fill
......
......@@ -544,8 +544,8 @@ void KisStrokeSelectionActionFactory::run(KisViewManager *view, StrokeSelectionO
KisNodeSP currentNode = view->canvasResourceProvider()->resourceManager()->resource(KisCanvasResourceProvider::CurrentKritaNode).value<KisNodeWSP>();
if (!currentNode->inherits("KisShapeLayer") && currentNode->paintDevice()) {
KoCanvasResourceProvider * rManager = view->canvasResourceProvider()->resourceManager();
KisPainter::StrokeStyle strokeStyle = KisPainter::StrokeStyleBrush;
KisPainter::FillStyle fillStyle = params.fillStyle();
KisToolShapeUtils::StrokeStyle strokeStyle = KisToolShapeUtils::StrokeStyleForeground;
KisToolShapeUtils::FillStyle fillStyle = params.fillStyle();
KisFigurePaintingToolHelper helper(kundo2_i18n("Draw Polyline"),
image,
......@@ -603,8 +603,8 @@ void KisStrokeBrushSelectionActionFactory::run(KisViewManager *view, StrokeSelec
{
KoCanvasResourceProvider * rManager = view->canvasResourceProvider()->resourceManager();
QPainterPath outline = pixelSelection->outlineCache();
KisPainter::StrokeStyle strokeStyle = KisPainter::StrokeStyleBrush;
KisPainter::FillStyle fillStyle = KisPainter::FillStyleNone;
KisToolShapeUtils::StrokeStyle strokeStyle = KisToolShapeUtils::StrokeStyleForeground;
KisToolShapeUtils::FillStyle fillStyle = KisToolShapeUtils::FillStyleNone;
KoColor color = params.color;
KisFigurePaintingToolHelper helper(kundo2_i18n("Draw Polyline"),
......
......@@ -365,29 +365,29 @@ StrokeSelectionOptions ::StrokeSelectionOptions():
customColor.fromQColor(Qt::black);
}
KisPainter::FillStyle StrokeSelectionOptions::fillStyle() const
KisToolShapeUtils::FillStyle StrokeSelectionOptions::fillStyle() const
{
using namespace KisToolShapeUtils;
colorFillSource tempColor = static_cast<colorFillSource>(_colorFillSource);
KisPainter::FillStyle style;
FillStyle style;
switch (tempColor) {
case colorFillSource::PaintColor:
style = KisPainter::FillStyleForegroundColor;
style = FillStyleForegroundColor;
break;
case colorFillSource::BGColor:
style = KisPainter::FillStyleBackgroundColor;
style = FillStyleBackgroundColor;
break;
case colorFillSource::CustomColor:
style = KisPainter::FillStyleBackgroundColor;
style = FillStyleBackgroundColor;
break;
case colorFillSource::None:
style = KisPainter::FillStyleNone;
style = FillStyleNone;
break;
case colorFillSource::FGColor:
style = KisPainter::FillStyleBackgroundColor;
style = FillStyleBackgroundColor;
break;
default:
style = KisPainter::FillStyleBackgroundColor;
}
return style;
}
......
......@@ -24,8 +24,8 @@
#include "KisViewManager.h"
#include "KoStrokeConfigWidget.h"
#include "ui_wdgstrokeselectionproperties.h"
#include <kis_painter.h>
#include <kis_canvas2.h>
#include <KisToolShapeUtils.h>
class KoColorSpace;
class KoColorPopupAction;
......@@ -52,7 +52,7 @@ struct StrokeSelectionOptions {
KoColor color;
KoColor fillColor;
KoColor customColor;
KisPainter::FillStyle fillStyle() const;
KisToolShapeUtils::FillStyle fillStyle() const;
void lock();
};
......
......@@ -2,6 +2,14 @@
<ui version="4.0">
<class>WdgGeometryOptions</class>
<widget class="QWidget" name="WdgGeometryOptions">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>185</width>
<height>46</height>
</rect>
</property>
<property name="windowTitle">
<string>Geometry Options</string>
</property>
......@@ -52,6 +60,11 @@
<string>Brush</string>
</property>
</item>
<item>
<property name="text">
<string>Brush (Background Color)</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
......
......@@ -620,8 +620,8 @@ void KisSelectionManager::paintSelectedShapes()
image,
paintLayer.data(),
m_view->canvasResourceProvider()->resourceManager(),
KisPainter::StrokeStyleBrush,
KisPainter::FillStyleNone);
KisToolShapeUtils::StrokeStyleForeground,
KisToolShapeUtils::FillStyleNone);
Q_FOREACH (KoShape* shape, shapes) {
QTransform matrix = shape->absoluteTransformation(0) * QTransform::fromScale(image->xRes(), image->yRes());
......
/*
* Copyright (c) 2019 Dmitry Kazakov <dimula73@gmail.com>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* Copyright (c) 2019 Dmitry Kazakov <dimula73@gmail.com>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISTOOLSHAPEUTILS_H
#define KISTOOLSHAPEUTILS_H
namespace KisToolShapeUtils
{
enum FillStyle {
FillStyleNone,
FillStyleForegroundColor,
FillStyleBackgroundColor,
FillStylePattern,
};
enum StrokeStyle {
StrokeStyleNone,
StrokeStyleForeground,
StrokeStyleBackground
};
}
#endif // KISTOOLSHAPEUTILS_H
......@@ -32,8 +32,8 @@ KisFigurePaintingToolHelper::KisFigurePaintingToolHelper(const KUndo2MagicString
KisImageWSP image,
KisNodeSP currentNode,
KoCanvasResourceProvider *resourceManager,
KisPainter::StrokeStyle strokeStyle,
KisPainter::FillStyle fillStyle)
KisToolShapeUtils::StrokeStyle strokeStyle,
KisToolShapeUtils::FillStyle fillStyle)
{
m_strokesFacade = image.data();
......@@ -42,8 +42,7 @@ KisFigurePaintingToolHelper::KisFigurePaintingToolHelper(const KUndo2MagicString
currentNode,
resourceManager);
m_resources->setStrokeStyle(strokeStyle);
m_resources->setFillStyle(fillStyle);
setupPaintStyles(m_resources, strokeStyle, fillStyle);
KisFreehandStrokeInfo *strokeInfo = new KisFreehandStrokeInfo();
......@@ -53,6 +52,53 @@ KisFigurePaintingToolHelper::KisFigurePaintingToolHelper(const KUndo2MagicString
m_strokeId = m_strokesFacade->startStroke(stroke);
}
void KisFigurePaintingToolHelper::setupPaintStyles(KisResourcesSnapshotSP resources,
KisToolShapeUtils::StrokeStyle strokeStyle,
KisToolShapeUtils::FillStyle fillStyle)
{
using namespace KisToolShapeUtils;
const KoColor fgColor = resources->currentFgColor();
const KoColor bgColor = resources->currentBgColor();
switch (strokeStyle) {
case StrokeStyleNone:
resources->setStrokeStyle(KisPainter::StrokeStyleNone);
break;
case StrokeStyleForeground:
resources->setStrokeStyle(KisPainter::StrokeStyleBrush);
break;
case StrokeStyleBackground:
resources->setStrokeStyle(KisPainter::StrokeStyleBrush);
resources->setFGColorOverride(bgColor);
resources->setBGColorOverride(fgColor);
if (fillStyle == FillStyleForegroundColor) {
fillStyle = FillStyleBackgroundColor;
} else if (fillStyle == FillStyleBackgroundColor) {
fillStyle = FillStyleForegroundColor;
}
break;
};
switch (fillStyle) {
case FillStyleForegroundColor:
resources->setFillStyle(KisPainter::FillStyleForegroundColor);
break;
case FillStyleBackgroundColor:
resources->setFillStyle(KisPainter::FillStyleBackgroundColor);
break;
case FillStylePattern:
resources->setFillStyle(KisPainter::FillStylePattern);
break;
case FillStyleNone:
resources->setFillStyle(KisPainter::FillStyleNone);
break;
}
}
KisFigurePaintingToolHelper::~KisFigurePaintingToolHelper()
{
m_strokesFacade->addJob(m_strokeId,
......
......@@ -23,6 +23,7 @@
#include "kritaui_export.h"
#include <brushengine/kis_paint_information.h>
#include "strokes/freehand_stroke.h"
#include "KisToolShapeUtils.h"
class KoCanvasResourceProvider;
class KisStrokesFacade;
......@@ -34,8 +35,8 @@ public:
KisImageWSP image,
KisNodeSP currentNode,
KoCanvasResourceProvider *resourceManager,
KisPainter::StrokeStyle strokeStyle,
KisPainter::FillStyle fillStyle);
KisToolShapeUtils::StrokeStyle strokeStyle,
KisToolShapeUtils::FillStyle fillStyle);
~KisFigurePaintingToolHelper();
void paintLine(const KisPaintInformation &pi0,
......@@ -52,6 +53,11 @@ public:
void paintPainterPathQPen(const QPainterPath, const QPen &pen, const KoColor &color);
void paintPainterPathQPenFill(const QPainterPath, const QPen &pen, const KoColor &color);
private:
void setupPaintStyles(KisResourcesSnapshotSP resources,
KisToolShapeUtils::StrokeStyle strokeStyle,
KisToolShapeUtils::FillStyle fillStyle);
private:
KisStrokeId m_strokeId;
KisResourcesSnapshotSP m_resources;
......
......@@ -114,21 +114,21 @@ void KisToolShape::fillSettingChanged(int value)
m_configGroup.writeEntry("fillType", value);
}
KisPainter::FillStyle KisToolShape::fillStyle(void)
KisToolShapeUtils::FillStyle KisToolShape::fillStyle()
{
if (m_shapeOptionsWidget) {
return static_cast<KisPainter::FillStyle>(m_shapeOptionsWidget->cmbFill->currentIndex());
return static_cast<KisToolShapeUtils::FillStyle>(m_shapeOptionsWidget->cmbFill->currentIndex());
} else {
return KisPainter::FillStyleNone;
return KisToolShapeUtils::FillStyleNone;
}
}
KisPainter::StrokeStyle KisToolShape::strokeStyle(void)
KisToolShapeUtils::StrokeStyle KisToolShape::strokeStyle()
{
if (m_shapeOptionsWidget) {
return static_cast<KisPainter::StrokeStyle>(m_shapeOptionsWidget->cmbOutline->currentIndex());
return static_cast<KisToolShapeUtils::StrokeStyle>(m_shapeOptionsWidget->cmbOutline->currentIndex());
} else {
return KisPainter::StrokeStyleNone;
return KisToolShapeUtils::StrokeStyleNone;
}
}
......@@ -165,15 +165,17 @@ void KisToolShape::ShapeAddInfo::markAsSelectionShapeIfNeeded(KoShape *shape) co
void KisToolShape::addShape(KoShape* shape)
{
using namespace KisToolShapeUtils;
KoImageCollection* imageCollection = canvas()->shapeController()->resourceManager()->imageCollection();
switch(fillStyle()) {
case KisPainter::FillStyleForegroundColor:
case FillStyleForegroundColor:
shape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(currentFgColor().toQColor())));
break;
case KisPainter::FillStyleBackgroundColor:
case FillStyleBackgroundColor:
shape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(currentBgColor().toQColor())));
break;
case KisPainter::FillStylePattern:
case FillStylePattern:
if (imageCollection) {
QSharedPointer<KoPatternBackground> fill(new KoPatternBackground(imageCollection));
if (currentPattern()) {
......@@ -184,29 +186,23 @@ void KisToolShape::addShape(KoShape* shape)
shape->setBackground(QSharedPointer<KoShapeBackground>(0));
}
break;
case KisPainter::FillStyleGradient:
{
QLinearGradient *gradient = new QLinearGradient(QPointF(0, 0), QPointF(1, 1));
gradient->setCoordinateMode(QGradient::ObjectBoundingMode);
gradient->setStops(currentGradient()->toQGradient()->stops());
QSharedPointer<KoGradientBackground> gradientFill(new KoGradientBackground(gradient));
shape->setBackground(gradientFill);
}
break;
case KisPainter::FillStyleNone:
default:
case FillStyleNone:
shape->setBackground(QSharedPointer<KoShapeBackground>(0));
break;
}
switch (strokeStyle()) {
case KisPainter::StrokeStyleNone:
case KisToolShapeUtils::StrokeStyleNone:
shape->setStroke(KoShapeStrokeModelSP());
break;
case KisPainter::StrokeStyleBrush: {
case KisToolShapeUtils::StrokeStyleForeground:
case KisToolShapeUtils::StrokeStyleBackground: {
KoShapeStrokeSP stroke(new KoShapeStroke());
stroke->setLineWidth(currentStrokeWidth());
stroke->setColor(canvas()->resourceManager()->foregroundColor().toQColor());
const QColor color = strokeStyle() == KisToolShapeUtils::StrokeStyleForeground ?
canvas()->resourceManager()->foregroundColor().toQColor() :
canvas()->resourceManager()->backgroundColor().toQColor();
stroke->setColor(color);
shape->setStroke(stroke);
break;
}
......
......@@ -28,6 +28,7 @@
#include "kis_tool_paint.h"
#include "KisSelectionToolFactoryBase.h"
#include "KisToolShapeUtils.h"
#include "ui_wdggeometryoptions.h"
......@@ -67,8 +68,8 @@ public Q_SLOTS:
protected:
QWidget* createOptionWidget() override;
virtual KisPainter::FillStyle fillStyle();
KisPainter::StrokeStyle strokeStyle();
KisToolShapeUtils::FillStyle fillStyle();
KisToolShapeUtils::StrokeStyle strokeStyle();
qreal currentStrokeWidth() const;
......
......@@ -68,7 +68,7 @@ __KisToolPencilLocalTool::__KisToolPencilLocalTool(KoCanvasBase * canvas, KisToo
void __KisToolPencilLocalTool::paint(QPainter &painter, const KoViewConverter &converter)
{
if (m_parentTool->strokeStyle() == KisPainter::StrokeStyleNone) {
if (m_parentTool->strokeStyle() == KisToolShapeUtils::StrokeStyleNone) {
paintPath(path(), painter, converter);
} else {
KoPencilTool::paint(painter, converter);
......
......@@ -85,8 +85,12 @@ void KisToolRectangle::finishRect(const QRectF &rect, qreal roundCornersX, qreal
KoShape* shape = KisShapeToolHelper::createRectangleShape(r, docRoundCornersX, docRoundCornersY);
KoShapeStrokeSP border;
if (strokeStyle() == KisPainter::StrokeStyleBrush) {
border = toQShared(new KoShapeStroke(currentStrokeWidth(), currentFgColor().toQColor()));
if (strokeStyle() != KisToolShapeUtils::StrokeStyleNone) {
const QColor color = strokeStyle() == KisToolShapeUtils::StrokeStyleForeground ?
canvas()->resourceManager()->foregroundColor().toQColor() :
canvas()->resourceManager()->backgroundColor().toQColor();
border = toQShared(new KoShapeStroke(currentStrokeWidth(), color));
}
shape->setStroke(border);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment