Commit db699b95 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implement inheriting of the background of the text shapes

(hint: it is neither available for normal shapes nor in GUI yet)
parent 2088a420
......@@ -30,7 +30,7 @@ public:
KoColorBackgroundPrivate()
: color(Qt::black)
, style(Qt::SolidPattern)
{};
{}
QColor color;
Qt::BrushStyle style;
......
......@@ -123,6 +123,7 @@ KoShapePrivate::KoShapePrivate(const KoShapePrivate &rhs, KoShape *q)
userData(rhs.userData ? rhs.userData->clone() : 0),
stroke(rhs.stroke),
fill(rhs.fill),
inheritBackground(rhs.inheritBackground),
dependees(), // FIXME: how to initialize them?
shadow(0), // WARNING: not implemented in Krita
border(0), // WARNING: not implemented in Krita
......@@ -749,7 +750,7 @@ QRectF KoShape::outlineRect() const
QPainterPath KoShape::shadowOutline() const
{
Q_D(const KoShape);
if (d->fill) {
if (background()) {
return outline();
}
......@@ -829,10 +830,9 @@ KoShapeUserData *KoShape::userData() const
bool KoShape::hasTransparency() const
{
Q_D(const KoShape);
if (! d->fill)
return true;
else
return d->fill->hasTransparency() || d->transparency > 0.0;
QSharedPointer<KoShapeBackground> bg = background();
return !bg || bg->hasTransparency() || d->transparency > 0.0;
}
void KoShape::setTransparency(qreal transparency)
......@@ -1095,6 +1095,7 @@ void KoShape::setTextRunAroundContour(KoShape::TextRunAroundContour contour)
void KoShape::setBackground(QSharedPointer<KoShapeBackground> fill)
{
Q_D(KoShape);
d->inheritBackground = false;
d->fill = fill;
d->shapeChanged(BackgroundChanged);
notifyChanged();
......@@ -1103,7 +1104,32 @@ void KoShape::setBackground(QSharedPointer<KoShapeBackground> fill)
QSharedPointer<KoShapeBackground> KoShape::background() const
{
Q_D(const KoShape);
return d->fill;
QSharedPointer<KoShapeBackground> bg;
if (!d->inheritBackground) {
bg = d->fill;
} else if (parent()) {
bg = parent()->background();
}
return bg;
}
void KoShape::setInheritBackground(bool value)
{
Q_D(KoShape);
d->inheritBackground = value;
if (d->inheritBackground) {
d->fill.clear();
}
}
bool KoShape::inheritBackground() const
{
Q_D(const KoShape);
return d->inheritBackground;
}
void KoShape::setZIndex(int zIndex)
......
......@@ -524,6 +524,10 @@ public:
* or have a complex fill.
* Setting such a background will allow the shape to be filled and will be able to tell
* if it is transparent or not.
*
* If the shape inherited the background from its parent, its stops inheriting it, that
* is inheritBackground property resets to false.
*
* @param background the new shape background.
*/
void setBackground(QSharedPointer<KoShapeBackground> background);
......@@ -537,6 +541,19 @@ public:
*/
QSharedPointer<KoShapeBackground> background() const;
/**
* @brief setInheritBackground marks a shape as inhiriting the background
* from the parent shape. NOTE: The currently selected background is destroyed.
* @param value true if the shape should inherit the filling background
*/
void setInheritBackground(bool value);
/**
* @brief inheritBackground shows if the shape inherits background from its parent
* @return true if the shape inherits the fill
*/
bool inheritBackground() const;
/**
* Returns true if there is some transparency, false if the shape is fully opaque.
* The default implementation will just return if the background has some transparency,
......
......@@ -83,6 +83,7 @@ public:
QScopedPointer<KoShapeUserData> userData;
QSharedPointer<KoShapeStrokeModel> stroke; ///< points to a stroke, or 0 if there is no stroke
QSharedPointer<KoShapeBackground> fill; ///< Stands for the background color / fill etc.
bool inheritBackground = false;
QList<KoShape*> dependees; ///< list of shape dependent on this shape
QList<KoShape::ShapeChangeListener*> listeners;
KoShapeShadow * shadow; ///< the current shape shadow
......
......@@ -1322,6 +1322,8 @@ KoShape *SvgParser::parseTextElement(const KoXmlElement &e, KoSvgTextShape *merg
textChunk->normalizeCharTransformations();
if (rootTextShape) {
textChunk->simplifyFillStrokeInheritance();
m_isInsideTextSubtree = false;
rootTextShape->relayout();
}
......
......@@ -606,6 +606,34 @@ void KoSvgTextChunkShape::normalizeCharTransformations()
d->applyParentCharTransformations(d->localTransformations);
}
void KoSvgTextChunkShape::simplifyFillStrokeInheritance()
{
Q_D(KoSvgTextChunkShape);
if (!isRootTextNode()) {
KoShape *parentShape = parent();
KIS_SAFE_ASSERT_RECOVER_RETURN(parentShape);
QSharedPointer<KoShapeBackground> bg = background();
if (bg &&
parentShape->background() &&
!inheritBackground() &&
bg->compareTo(parentShape->background().data())) {
setInheritBackground(true);
}
}
Q_FOREACH (KoShape *shape, shapes()) {
KoSvgTextChunkShape *chunkShape = dynamic_cast<KoSvgTextChunkShape*>(shape);
KIS_SAFE_ASSERT_RECOVER_RETURN(chunkShape);
chunkShape->simplifyFillStrokeInheritance();
}
}
KoSvgTextProperties KoSvgTextChunkShape::textProperties() const
{
Q_D(const KoSvgTextChunkShape);
......@@ -724,7 +752,9 @@ KoSvgText::KoSvgCharChunkFormat KoSvgTextChunkShapePrivate::fetchCharFormat() co
textBrush = Qt::red;
}
textBrush = colorBackground->brush();
if (colorBackground) {
textBrush = colorBackground->brush();
}
}
format.setForeground(textBrush);
......
......@@ -52,6 +52,7 @@ public:
bool loadSvg(const KoXmlElement &element, SvgLoadingContext &context) override;
bool loadSvgTextNode(const KoXmlText &text, SvgLoadingContext &context);
void normalizeCharTransformations();
void simplifyFillStrokeInheritance();
KoSvgTextProperties textProperties() const;
bool isTextNode() const;
......
......@@ -85,6 +85,15 @@ KoShape *KoSvgTextShape::cloneShape() const
return new KoSvgTextShape(*this);
}
void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)
{
KoSvgTextChunkShape::shapeChanged(type, shape);
if (type == StrokeChanged || type == BackgroundChanged || type == ContentChanged) {
relayout();
}
}
void KoSvgTextShape::paintComponent(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintContext)
{
Q_D(KoSvgTextShape);
......
......@@ -46,6 +46,8 @@ public:
protected:
bool isRootTextNode() const override;
void shapeChanged(ChangeType type, KoShape *shape) override;
private:
Q_DECLARE_PRIVATE(KoSvgTextShape)
};
......
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