Commit 55f283b7 authored by Thorsten Zachmann's avatar Thorsten Zachmann

o The patch changes gradients to use the BoundingBoxMode. This change

  makes it possible to remove some special code that is needed at the
  moment when resizing a shape. It adds support for loading gradients
  that are saved in percent values. When saving always objectBoundingBox
  is used. Svg gradients that use userSpaceOnUse gradients are converted
  to use the BoundingBoxMode on loading.


svn path=/trunk/koffice/; revision=1074434
parent 8db9de54
......@@ -2,6 +2,7 @@
* Copyright (C) 2009 Jos van den Oever <jos@vandenoever.info>
* Copyright (C) 2009 Thomas Zander <zander@kde.org>
* Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net>
* Copyright (C) 2010 Thorsten Zachmann <zachmann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -56,9 +57,20 @@ QGradient *KoFlake::cloneGradient(const QGradient *gradient)
return 0;
}
clone->setCoordinateMode(gradient->coordinateMode());
clone->setSpread(gradient->spread());
clone->setStops(gradient->stops());
return clone;
}
QPointF KoFlake::toRelative(const QPointF &absolute, const QSizeF &size)
{
return QPointF(size.width() == 0 ? 0: absolute.x() / size.width(),
size.height() == 0 ? 0: absolute.y() / size.height());
}
QPointF KoFlake::toAbsolute(const QPointF &relative, const QSizeF &size)
{
return QPointF(relative.x() * size.width(), relative.y() * size.height());
}
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <zander@kde.org>
* Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net>
* Copyright (C) 2010 Thorsten Zachmann <zachmann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -82,6 +83,26 @@ namespace KoFlake
/// clones the given gradient
FLAKE_EXPORT QGradient *cloneGradient(const QGradient *gradient);
/**
* Convert absolute to relative position
*
* @param absolute absolute position
* @param size for which the relative position needs to be calculated
*
* @return relative position
*/
FLAKE_EXPORT QPointF toRelative(const QPointF &absolute, const QSizeF &size);
/**
* Convert relative size to absolute size
*
* @param relative relative position
* @param size for which the absolute position needs to be calculated
*
* @return absolute position
*/
FLAKE_EXPORT QPointF toAbsolute(const QPointF &relative, const QSizeF &size);
}
#endif
......@@ -50,6 +50,7 @@ KoGradientBackground::KoGradientBackground(QGradient * gradient, const QMatrix &
d->gradient = gradient;
d->matrix = matrix;
Q_ASSERT(d->gradient);
Q_ASSERT(d->gradient->coordinateMode() == QGradient::ObjectBoundingMode);
}
KoGradientBackground::KoGradientBackground(const QGradient & gradient, const QMatrix &matrix)
......@@ -59,6 +60,7 @@ KoGradientBackground::KoGradientBackground(const QGradient & gradient, const QMa
d->gradient = KoFlake::cloneGradient(&gradient);
d->matrix = matrix;
Q_ASSERT(d->gradient);
Q_ASSERT(d->gradient->coordinateMode() == QGradient::ObjectBoundingMode);
}
KoGradientBackground::~KoGradientBackground()
......@@ -80,21 +82,21 @@ QMatrix KoGradientBackground::matrix() const
void KoGradientBackground::setGradient(QGradient * gradient)
{
Q_D(KoGradientBackground);
if (d->gradient)
delete d->gradient;
delete d->gradient;
d->gradient = gradient;
Q_ASSERT(d->gradient);
Q_ASSERT(d->gradient->coordinateMode() == QGradient::ObjectBoundingMode);
}
void KoGradientBackground::setGradient(const QGradient &gradient)
{
Q_D(KoGradientBackground);
if (d->gradient)
delete d->gradient;
delete d->gradient;
d->gradient = KoFlake::cloneGradient(&gradient);
Q_ASSERT(d->gradient);
Q_ASSERT(d->gradient->coordinateMode() == QGradient::ObjectBoundingMode);
}
const QGradient * KoGradientBackground::gradient() const
......@@ -115,6 +117,7 @@ KoGradientBackground &KoGradientBackground::operator = (const KoGradientBackgrou
delete d->gradient;
d->gradient = KoFlake::cloneGradient(other->gradient);
Q_ASSERT(d->gradient);
Q_ASSERT(d->gradient->coordinateMode() == QGradient::ObjectBoundingMode);
return *this;
}
......
/* This file is part of the KDE project
Copyright (C) 2006 Casper Boemann Rasmussen <cbr@boemann.dk>
Copyright (C) 2006-2009 Thomas Zander <zander@kde.org>
Copyright (C) 2006-2008 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2006-2010 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2007-2009 Jan Hambrecht <jaham@gmx.net>
This library is free software; you can redistribute it and/or
......@@ -250,22 +250,6 @@ void KoShape::setSize(const QSizeF &newSize)
if (oldSize == newSize)
return;
QMatrix matrix;
oldSize.setHeight(qMax((qreal) 1E-4, oldSize.height())); // avoids devision by zero below
oldSize.setWidth(qMax((qreal) 1E-4, oldSize.width()));
matrix.scale(newSize.width()/oldSize.width(), newSize.height()/oldSize.height());
KoGradientBackground * g = dynamic_cast<KoGradientBackground*>(d->fill);
if (g) {
g->setMatrix(g->matrix() * matrix);
}
KoLineBorder *l = dynamic_cast<KoLineBorder*>(d->border);
if (l && l->lineBrush().gradient()) {
QBrush brush = l->lineBrush();
brush.setMatrix(brush.matrix() * matrix);
l->setLineBrush(brush);
}
d->size = newSize;
notifyChanged();
......@@ -1093,8 +1077,11 @@ KoShapeBackground * KoShape::loadOdfFill(const KoXmlElement & element, KoShapeLo
KoShapeBackground * bg = 0;
if (fill == "solid" || fill == "hatch")
bg = new KoColorBackground();
else if (fill == "gradient")
bg = new KoGradientBackground(new QLinearGradient());
else if (fill == "gradient") {
QGradient * gradient = new QLinearGradient();
gradient->setCoordinateMode(QGradient::ObjectBoundingMode);
bg = new KoGradientBackground(gradient);
}
else if (fill == "bitmap")
bg = new KoPatternBackground(context.imageCollection());
......
This diff is collapsed.
/* This file is part of the KDE project
* Copyright (C) 2007-2009 Jan Hambrecht <jaham@gmx.net>
* Copyright (C) 2008-2009 Thorsten Zachmann <zachmann@kde.org>
* Copyright (C) 2008-2010 Thorsten Zachmann <zachmann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -420,7 +420,7 @@ void StyleDocker::updateGradient(KoResource * item)
QList<KoShape*> selectedShapes = m_canvas->shapeManager()->selection()->selectedShapes();
if (selectedShapes.isEmpty()) {
KoShape* page = m_canvas->resourceProvider()->koShapeResource(KoPageApp::CurrentPage);
if ( page) {
if (page) {
selectedShapes.append(page);
}
else {
......@@ -609,10 +609,8 @@ KoShapeBackground *StyleDocker::applyFillGradientStops(KoShape *shape, const QGr
}
else {
// no gradient yet, so create a new one
QSizeF size = shape->size();
QLinearGradient *g = new QLinearGradient();
g->setStart(QPointF(0, 0));
g->setFinalStop(QPointF(size.width(), size.height()));
QLinearGradient *g = new QLinearGradient(QPointF(0, 0), QPointF(1, 1));
g->setCoordinateMode(QGradient::ObjectBoundingMode);
g->setStops(stops);
newGradient = new KoGradientBackground(g);
}
......@@ -638,10 +636,8 @@ QBrush StyleDocker::applyStrokeGradientStops(KoShape *shape, const QGradientStop
}
else {
// no gradient yet, so create a new one
QSizeF size = shape->size();
QLinearGradient *g = new QLinearGradient();
g->setStart(QPointF(0, 0));
g->setFinalStop(QPointF(size.width(), size.height()));
QLinearGradient *g = new QLinearGradient(QPointF(0, 0), QPointF(1, 1));
g->setCoordinateMode(QGradient::ObjectBoundingMode);
g->setStops(stops);
newGradient = g;
}
......
......@@ -47,7 +47,8 @@ KoShape *EllipseShapeFactory::createDefaultShape() const
ellipse->setBorder(new KoLineBorder(1.0));
ellipse->setShapeId(KoPathShapeId);
QRadialGradient *gradient = new QRadialGradient(QPointF(50,50), 50.0, QPointF(25,25));
QRadialGradient *gradient = new QRadialGradient(QPointF(0.5,0.5), 0.5, QPointF(0.25,0.25));
gradient->setCoordinateMode(QGradient::ObjectBoundingMode);
gradient->setColorAt(0.0, Qt::white);
gradient->setColorAt(1.0, Qt::green);
ellipse->setBackground(new KoGradientBackground(gradient));
......
......@@ -44,7 +44,9 @@ KoShape *RectangleShapeFactory::createDefaultShape() const
rect->setBorder(new KoLineBorder(1.0));
rect->setShapeId(KoPathShapeId);
QLinearGradient *gradient = new QLinearGradient(QPointF(0,0), QPointF(100,100));
QLinearGradient *gradient = new QLinearGradient(QPointF(0,0), QPointF(1,1));
gradient->setCoordinateMode(QGradient::ObjectBoundingMode);
gradient->setColorAt(0.0, Qt::white);
gradient->setColorAt(1.0, Qt::green);
rect->setBackground(new KoGradientBackground(gradient));
......
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