43 if(gradientBackground) {
44 return Type::Gradient;
47 if (patternBackground) {
51 if (colorBackground) {
55 if (meshgradientBackground) {
56 return Type::MeshGradient;
64 return colorBackground ? colorBackground->color() : QColor();
69 return gradientBackground ? gradientBackground->gradient() : 0;
74 return gradientBackground ? gradientBackground->transform() : QTransform();
79 return meshgradientBackground ? meshgradientBackground->gradient() :
nullptr;
84 return meshgradientBackground ? meshgradientBackground->transform() : QTransform();
88 return p1->compareTo(
p2.data());
102 if (!stroke)
return Type::None;
105 if (stroke->lineBrush().gradient()) {
106 return Type::Gradient;
110 if (stroke->color().isValid() && stroke->lineWidth() != 0.0) {
120 return stroke ? stroke->color() : QColor();
125 return stroke ? stroke->lineBrush().gradient() : 0;
130 return stroke ? stroke->lineBrush().transform() : QTransform();
134 return p1->compareFillTo(
p2.data());
139template <
class Policy>
142 if (shapes.size() == 1)
return true;
144 typename Policy::PointerType bg =
145 Policy::getBackground(shapes.first());
147 Q_FOREACH (
KoShape *shape, shapes) {
150 (!bg && !Policy::getBackground(shape)) ||
151 (bg && Policy::compareTo(bg, Policy::getBackground(shape)))
176 QGradientStops stops = stopGradient->stops();
178 if (!shape || !stops.count()) {
192 QScopedPointer<QLinearGradient> fakeShapeGradient(
new QLinearGradient(QPointF(0, 0), QPointF(1, 1)));
193 fakeShapeGradient->setCoordinateMode(QGradient::ObjectBoundingMode);
203 QGradientStops stops = stopGradient->stops();
204 if (!stops.count())
return;
206 QLinearGradient fakeShapeGradient(QPointF(0, 0), QPointF(1, 1));
207 fakeShapeGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
209 const QGradient *shapeGradient = 0;
212 QBrush brush = shapeStroke->lineBrush();
214 shapeGradient = brush.gradient() ? brush.gradient() : &fakeShapeGradient;
219 QBrush newBrush = *g;
221 shapeStroke->setLineBrush(newBrush);
233 m_d->shapes << shape;
234 m_d->fillVariant= fillVariant;
242 m_d->shapes = shapes;
243 m_d->fillVariant= fillVariant;
252 if (
m_d->shapes.isEmpty())
return false;
255 !compareBackgrounds<ShapeBackgroundFetchPolicy>(
m_d->shapes) :
256 !compareBackgrounds<ShapeStrokeFillFetchPolicy>(
m_d->shapes);
339 if (
color.isValid()) {
348 stroke->setLineBrush(Qt::NoBrush);
349 stroke->setColor(color);
362 stroke->setColor(Qt::transparent);
363 stroke->setLineWidth(lineWidth);
374 if (!shape)
return false;
379 if (!stroke)
return false;
381 if ( stroke->lineWidth() == 0.0) {
401 newBackgrounds <<
toQShared(newGradient);
409 QBrush newBrush = *gradient;
410 newBrush.setTransform(transform);
412 stroke->setLineBrush(newBrush);
413 stroke->setColor(Qt::transparent);
433 newBackgrounds <<
m_d->applyFillGradientStops(shape,
gradient);
441 m_d->applyFillGradientStops(stroke, gradient);
449 const QTransform &transform)
455 for (
const auto &shape:
m_d->shapes) {
460 newBackgrounds <<
toQShared(newBackground);
bool compareBackgrounds(const QList< KoShape * > shapes)
A simple solid color shape background.
A gradient shape background.
void setTransform(const QTransform &matrix)
Sets the transform matrix.
The undo / redo command for setting the shape background.
KoShapeFillWrapper(KoShape *shape, KoFlake::FillVariant fillVariant)
const QScopedPointer< Private > m_d
KoFlake::FillType type() const
KUndo2Command * applyGradientStopsOnly(const QGradient *gradient)
QTransform gradientTransform() const
const SvgMeshGradient * meshgradient() const
KUndo2Command * setMeshGradient(const SvgMeshGradient *gradient, const QTransform &transform)
const QGradient * gradient() const
bool hasZeroLineWidth() const
KUndo2Command * setLineWidth(const float &lineWidth)
KUndo2Command * setGradient(const QGradient *gradient, const QTransform &transform)
KUndo2Command * applyGradient(const QGradient *gradient)
KUndo2Command * setColor(const QColor &color)
virtual KoShapeStrokeModelSP stroke() const
virtual QSharedPointer< KoShapeBackground > background() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
QSharedPointer< T > toQShared(T *ptr)
KRITAFLAKE_EXPORT QGradient * cloneGradient(const QGradient *gradient)
clones the given gradient
KRITAFLAKE_EXPORT QGradient * mergeGradient(const QGradient *coordsSource, const QGradient *fillSource)
auto modifyShapesStrokes(QList< KoShape * > shapes, ModifyFunction modifyFunction) -> decltype(modifyFunction(KoShapeStrokeSP()),(KUndo2Command *)(0))
QList< KoShape * > shapes
KoFlake::FillVariant fillVariant
QSharedPointer< KoShapeBackground > applyFillGradientStops(KoShape *shape, const QGradient *srcQGradient)
static const QGradient * gradient(KoShape *shape)
static QTransform meshgradientTransform(KoShape *shape)
static QColor color(KoShape *shape)
static PointerType getBackground(KoShape *shape)
static const SvgMeshGradient * meshgradient(KoShape *shape)
static bool compareTo(PointerType p1, PointerType p2)
static QTransform gradientTransform(KoShape *shape)
QSharedPointer< KoShapeBackground > PointerType
static Type type(KoShape *shape)
static bool compareTo(PointerType p1, PointerType p2)
static PointerType getBackground(KoShape *shape)
static QTransform gradientTransform(KoShape *shape)
static Type type(KoShape *shape)
static QColor color(KoShape *shape)
static const QGradient * gradient(KoShape *shape)
KoShapeStrokeModelSP PointerType