Commit aabdbedd authored by Inge Wallin's avatar Inge Wallin

Merge the branch flake-shapeborders-ingwa

This branch contains:
 - Borders for shapes
 - Painting of borders in KoBorder instead of other places
 - Handling of padding inside borders

Code by me (ingwa) and Camilla Boemann

REVIEW: 111044

FEATURE: Shape borders
FEATURE: Padding inside borders

Squashed commit of the following:

commit ffab6ec0f8c3d41b881eaaffc6abba7245a703bf
Merge: 33e3bc8 5ff12bb
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Thu Aug 1 19:26:12 2013 +0200

    Merge branch 'master' into flake-shapeborders-ingwa

    Conflicts:
    	libs/flake/KoShape.h

commit 33e3bc8f902175c728b06ddbc804a0558aadac29
Merge: 5429aa2 6648461
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Tue Jul 30 17:27:47 2013 +0200

    Merge remote-tracking branch 'origin/flake-shapeborders-ingwa' into flake-shapeborders-ingwa

    Conflicts:
    	libs/flake/KoShape.h

commit 6648461572ca845fe0372780ddc8545363dc5521
Author: C. Boemann <cbo@boemann.dk>
Date:   Tue Jul 30 16:16:27 2013 +0200

    Only paint when there really is a border - or we would end up painting a cosmetic line

    also loading a file with all individually specified borders would still report it hadn't any borders

commit 300a98b9b45c77df1ae1fd55ba367e484b074f3d
Merge: a32fd98 3b4d668
Author: C. Boemann <cbo@boemann.dk>
Date:   Mon Jul 29 11:19:00 2013 +0200

    Merge branch 'master' into flake-shapeborders-ingwa

commit 5429aa2f4f40e750459dd08c1bac3d9d8919cb6d
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sun Jul 28 09:32:11 2013 +0200

    Add a missing method to KoBorder.

commit 78dc4d134e3581bc6abecc8061898e9e1ee99a46
Merge: a32fd98 3350bba
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jul 27 15:28:19 2013 +0200

    Merge branch 'master' into flake-shapeborders-ingwa

    Conflicts:
    	libs/flake/KoShape.h

commit a32fd9886c719a9d019c7d13925a862801ad675d
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Thu Jul 18 23:38:54 2013 +0200

    Fix the build.

    Seems that boemann is not building the tests.  Booo!

    The test now builds but I don't know if the suggested rects make sense.

commit 7335fcf876a19c4e636a2b44a333099b532ecef1
Merge: 92c5bce 35ca4ac
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Thu Jul 18 23:04:02 2013 +0200

    Merge branch 'master' into flake-shapeborders-ingwa

commit 92c5bcef0961405765d8faae787cf68580be60d4
Author: C. Boemann <cbo@boemann.dk>
Date:   Thu Jun 20 22:17:00 2013 +0200

    Take padding and border into account when doing anchor placement

    Also We need to give the page for page-anchored shapes, otherwise sub objects will not be placed

    Also don't scale the border twice

commit 8b674a8e2b5e500040695fff93d76ea43ae4e520
Merge: cb26e25 05b3301
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 22 13:17:40 2013 +0700

    Merge branch 'flake-shapeborders-ingwa' of ssh://git.kde.org/calligra into flake-shapeborders-ingwa

    Conflicts:
    	libs/flake/KoShape.cpp

commit cb26e2567be0a84649d1457d9d3fc45c84fa7b8a
Merge: 21e69bf 04a624e
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 22 13:09:55 2013 +0700

    Merge branch 'master' into flake-shapeborders-ingwa

commit 21e69bf563a7d58535f6c339270b5ce3cdbfd180
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 22 12:43:32 2013 +0700

    Fix border width bug for page borders.

    KoShape::paintBorder() now assumes that all view tranformations are
    already applied to the painter.

commit a5a566c3ce168d71c46afa48aae73f14229500f2
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 22 12:04:27 2013 +0700

    Fix faulty indentation.

commit 05b330131120e419fd24e9529e15d4b74f8f619d
Author: C. Boemann <cbo@boemann.dk>
Date:   Thu Jun 20 22:10:55 2013 +0200

    fix scaling being applied twice for the text

commit 83bcd122d2610a48cf27b0bf4f257dd67c43b71d
Merge: e921d88 5a4fdc6
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Thu Jun 20 23:58:21 2013 +0700

    Merge branch 'master' into flake-shapeborders-ingwa

commit e921d887275347cbb94f76b876e413be5c1611e0
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Thu Jun 20 11:45:16 2013 +0700

    A better way to set the dash style of the QPainter.

commit ec0bf5760a1cb4939874d8473e84a1ff93347668
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Thu Jun 20 04:26:39 2013 +0700

    Treat border="none" the same as no mention of border at all.

commit 7fd9926672f32431f63b5b016a2995e43f086db7
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Mon Jun 17 21:15:13 2013 +0200

    Remove unuzed parameters.

commit 4a24367c17b35e26556706de59cc86a688fbbec7
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Mon Jun 17 21:07:10 2013 +0200

    Improve the old loading code for borders.

    The old code didn't check for individual edges (-top, -bottom, -left,
    -right) when there was a common border definition.

commit f5c0652d8f877905bd5252f3b2f92a87d6259950
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Mon Jun 17 20:30:15 2013 +0200

    Use painter scaling instead of explicit zoom parameters.

commit 637d674acb3c9ae6940a0f70e3fd9dab70ecbb7c
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 15 20:06:10 2013 +0200

    Fix a bug visible only with thick inner borders.

    Also remove some remaining kdebugs.

commit e0d9c69478262151199f6e6f516a02d0134f3383
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 15 18:03:16 2013 +0200

    Fix another small pasto bug

commit 2d09674fcbf613ecfaeae430fe9132caae090c1d
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 15 17:25:50 2013 +0200

    Fix a small bug

commit b105ffcfdcffcbe7a906dbb7104bd1782d1cc470
Merge: cf97de5 4021e36
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 15 17:07:24 2013 +0200

    Merge branch 'master' into flake-shapeborders-ingwa

commit cf97de5aeca89e6da10e296d164eb2c60fe7854e
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 15 17:04:38 2013 +0200

    Simplify the painting of borders significantly.

commit 71be183148c87ebc46b825bf1256aa130ef44816
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sat Jun 15 10:28:37 2013 +0200

    Make double borders work in the corners.

    Unfortunately I had to refactor the drawing a bit to make this work.
    But I know how to simplify it back so I'll do that next.

commit b306709efe4a2aefe8a6d0ccb519f6f448e17948
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Fri Jun 14 10:04:42 2013 +0200

    Make KoBorder able to paint on the designated rect or inside it.

commit c2de625bc4696ca5b1372070349c454180164b4f
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Thu Jun 13 20:56:31 2013 +0200

    Remove an unneded parameter.

commit 1293e44e60e97ebba01f2d7d6fcc7f97e4b4880f
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Thu Jun 13 07:30:32 2013 +0200

    Remove old border painting code in KWCanvasBase.

commit 8c56fd221cc706028e00667599b7ac6ac8430eee
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Thu Jun 13 06:37:17 2013 +0200

    Fix all scaling problems.

    The borders are now drawn in all the correct places.
    Still some things to do to get the corners right.

commit 2fcb972323852aa993779675f7fea6b4991b2904
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Wed Jun 12 14:12:38 2013 +0200

    Put the border inside the available area instead of having the center line at the boundary of the area.

commit a0213a361b28dbe1a74e4a9abb5f081c64bd1fc0
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Wed Jun 12 05:23:08 2013 +0200

    Implement painting of borders in KoShape and call this from the pictureshape and the textshape.

    Still some kdebugs that we need to remove later.

commit d455047e34a9351a558656c7e6fd3b5501d9ad9b
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Tue Jun 11 18:17:17 2013 +0200

    Implement painting in KoBorder and call it from KWCanvasBase.

commit c6e73db52ead4aab98469b9bc969a9b0c2e0caae
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sun Jun 9 23:23:08 2013 +0200

    Initialize the border field of the private class.

commit 04d431b0bc08c81bb857a938a61ee7b68876fb40
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sun Jun 9 18:58:47 2013 +0200

    Implement saving of borders in KoShape

    This was easier than I expected...

commit cd0268f499aca9ede9f38be82dc04917cfeeab02
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sun Jun 9 18:44:40 2013 +0200

    Implement loading of borders in KoShape

commit 9ff1e5e91f439a738894abf573bcdc7e8d9bf91e
Author: Inge Wallin <inge@lysator.liu.se>
Date:   Sun Jun 9 17:51:18 2013 +0200

    Add ODF loading from KoStyleStack too.
parent 83e49bdc
......@@ -62,6 +62,7 @@
#include <KoOdfStylesReader.h>
#include <KoOdfGraphicStyles.h>
#include <KoOdfLoadingContext.h>
#include <KoBorder.h>
#include <QPainter>
#include <QVariant>
......@@ -84,6 +85,7 @@ KoShapePrivate::KoShapePrivate(KoShape *shape)
appData(0),
stroke(0),
shadow(0),
border(0),
clipPath(0),
filterEffectStack(0),
transparency(0.0),
......@@ -1196,6 +1198,24 @@ KoShapeShadow *KoShape::shadow() const
return d->shadow;
}
void KoShape::setBorder(KoBorder *border)
{
Q_D(KoShape);
if (d->border) {
// The shape owns the border.
delete d->border;
}
d->border = border;
d->shapeChanged(BorderChanged);
notifyChanged();
}
KoBorder *KoShape::border() const
{
Q_D(const KoShape);
return d->border;
}
void KoShape::setClipPath(KoClipPath *clipPath)
{
Q_D(KoShape);
......@@ -1255,14 +1275,28 @@ bool KoShape::isEditable() const
return true;
}
// painting
void KoShape::paintBorder(QPainter &painter, const KoViewConverter &converter)
{
KoBorder *bd = border();
if (!bd) {
return;
}
QRectF borderRect = QRectF(QPointF(0, 0), size());
// Paint the border.
bd->paint(painter, borderRect, KoBorder::PaintInsideLine);
}
// loading & saving methods
QString KoShape::saveStyle(KoGenStyle &style, KoShapeSavingContext &context) const
{
Q_D(const KoShape);
// and fill the style
KoShapeStrokeModel *b = stroke();
if (b) {
b->fillStyle(style, context);
KoShapeStrokeModel *sm = stroke();
if (sm) {
sm->fillStyle(style, context);
}
else {
style.addProperty("draw:stroke", "none", KoGenStyle::GraphicType);
......@@ -1279,6 +1313,11 @@ QString KoShape::saveStyle(KoGenStyle &style, KoShapeSavingContext &context) con
style.addProperty("draw:fill", "none", KoGenStyle::GraphicType);
}
KoBorder *b = border();
if (b) {
b->saveOdf(style);
}
if (context.isSet(KoShapeSavingContext::AutoStyleInStyleXml)) {
style.setAutoStyleInStylesDotXml(true);
}
......@@ -1390,6 +1429,7 @@ void KoShape::loadStyle(const KoXmlElement &element, KoShapeLoadingContext &cont
setBackground(loadOdfFill(context));
setStroke(loadOdfStroke(element, context));
setShadow(d->loadOdfShadow(context));
setBorder(d->loadOdfBorder(context));
QString protect(styleStack.property(KoXmlNS::style, "protect"));
setGeometryProtected(protect.contains("position") || protect.contains("size"));
......@@ -1678,6 +1718,19 @@ KoShapeShadow *KoShapePrivate::loadOdfShadow(KoShapeLoadingContext &context) con
return 0;
}
KoBorder *KoShapePrivate::loadOdfBorder(KoShapeLoadingContext &context) const
{
KoStyleStack &styleStack = context.odfLoadingContext().styleStack();
KoBorder *border = new KoBorder();
if (border->loadOdf(styleStack)) {
return border;
}
delete border;
return 0;
}
void KoShape::loadOdfGluePoints(const KoXmlElement &element, KoShapeLoadingContext &context)
{
Q_D(KoShape);
......
......@@ -66,6 +66,8 @@ class KoSnapData;
class KoClipPath;
class KoShapePaintingContext;
class KoShapeAnchor;
class KoBorder;
/**
*
......@@ -127,6 +129,7 @@ public:
StrokeChanged, ///< the shapes stroke has changed
BackgroundChanged, ///< the shapes background has changed
ShadowChanged, ///< the shapes shadow has changed
BorderChanged, ///< the shapes border has changed
ParameterChanged, ///< the shapes parameter has changed (KoParameterShape only)
ContentChanged, ///< the content of the shape changed e.g. a new image inside a pixmap/text change inside a textshape
TextRunAroundChanged, ///< used after a setTextRunAroundSide()
......@@ -189,6 +192,15 @@ public:
*/
virtual void paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) = 0;
/**
* @brief Paint the shape's border
* This is a helper function that could be called from the paint() method of all shapes.
* @param painter used for painting the shape
* @param converter to convert between internal and view coordinates.
* @see applyConversion()
*/
virtual void paintBorder(QPainter &painter, const KoViewConverter &converter);
/**
* Load a shape from odf
*
......@@ -750,6 +762,12 @@ public:
/// Returns the currently set shadow or 0 if there is no shadow set
KoShapeShadow *shadow() const;
/// Sets the new border, removing the old one.
void setBorder(KoBorder *border);
/// Returns the currently set border or 0 if there is no border set
KoBorder *border() const;
/// Sets a new clip path, removing the old one
void setClipPath(KoClipPath *clipPath);
......@@ -1163,7 +1181,7 @@ protected:
/// Loads the stroke style
KoShapeStrokeModel *loadOdfStroke(const KoXmlElement &element, KoShapeLoadingContext &context) const;
/// Loads the shadow style
/// Loads the fill style
QSharedPointer<KoShapeBackground> loadOdfFill(KoShapeLoadingContext &context) const;
/// Loads the connection points
......
......@@ -21,11 +21,15 @@
#define KOSHAPEPRIVATE_H
#include "KoShape.h"
#include <QPoint>
#include <QPaintDevice>
#include <KoCanvasBase.h>
class KoBorder;
class KoShapePrivate
{
public:
......@@ -48,6 +52,9 @@ public:
/// Loads the shadow style
KoShapeShadow *loadOdfShadow(KoShapeLoadingContext &context) const;
// Loads the border style.
KoBorder *loadOdfBorder(KoShapeLoadingContext &context) const;
/// calls update on the shape where the stroke is.
void updateStroke();
......@@ -72,6 +79,7 @@ public:
QSharedPointer<KoShapeBackground> fill; ///< Stands for the background color / fill etc.
QList<KoShape*> dependees; ///< list of shape dependent on this shape
KoShapeShadow * shadow; ///< the current shape shadow
KoBorder *border; ///< the current shape border
KoClipPath * clipPath; ///< the current clip path
QMap<QString, QString> additionalAttributes;
QMap<QByteArray, QString> additionalStyleAttributes;
......
This diff is collapsed.
......@@ -34,7 +34,8 @@
#include "KoXmlReaderForward.h"
#include "KoGenStyle.h"
class KoGenStyle;
class QPainter;
class KoStyleStack;
class KoBorderPrivate;
......@@ -94,14 +95,14 @@ public:
/// Holds data about one border line.
struct KOODF_EXPORT BorderData {
BorderData();
BorderStyle style; ///< The border style. (see KoBorder::BorderStyle)
qreal spacing;
QPen innerPen;
QPen outerPen;
/// Compare the border data with another one
bool operator==(const BorderData &other) const;
BorderStyle style; ///< The border style. (see KoBorder::BorderStyle)
QPen outerPen; ///< Holds the outer line when borderstyle is double and the whole line otherwise
QPen innerPen; ///< Holds the inner line when borderstyle is double
qreal spacing; ///< Holds the spacing between the outer and inner lines.
};
......@@ -114,7 +115,8 @@ public:
/// Assignment
KoBorder &operator=(const KoBorder &other);
/// Compare the border with the other one
/// Compare the border with another one
bool operator==(const KoBorder &other) const;
bool operator!=(const KoBorder &other) const { return !operator==(other); }
......@@ -124,6 +126,8 @@ public:
QColor borderColor(BorderSide side) const;
void setBorderWidth(BorderSide side, qreal width);
qreal borderWidth(BorderSide side) const;
void setOuterBorderWidth(BorderSide side, qreal width);
qreal outerBorderWidth(BorderSide side) const;
void setInnerBorderWidth(BorderSide side, qreal width);
qreal innerBorderWidth(BorderSide side) const;
void setBorderSpacing(BorderSide side, qreal width);
......@@ -135,6 +139,13 @@ public:
bool hasBorder() const;
bool hasBorder(BorderSide side) const;
enum BorderPaintArea {
PaintOnLine,
PaintInsideLine
};
void paint(QPainter &painter, const QRectF &borderRect,
BorderPaintArea whereToPaint = PaintInsideLine) const;
/**
* Load the style from the element
*
......@@ -142,6 +153,7 @@ public:
* @return true when border attributes were found
*/
bool loadOdf(const KoXmlElement &style);
bool loadOdf(const KoStyleStack &styleStack);
void saveOdf(KoGenStyle &style, KoGenStyle::PropertyType type = KoGenStyle::DefaultType) const;
......@@ -152,6 +164,17 @@ public:
static QString odfBorderStyleString(BorderStyle borderstyle);
static QString msoBorderStyleString(BorderStyle borderstyle);
private:
void paintBorderSide(QPainter &painter, QPointF lineStart, QPointF lineEnd,
BorderData *borderData, bool isVertical,
BorderData *neighbour1, BorderData *neighbor2,
int inwardsAcross) const;
void parseAndSetBorder(const QString &border,
bool hasSpecialBorder, const QString &specialBorderString);
void parseAndSetBorder(const BorderSide borderSide, const QString &border,
bool hasSpecialBorder, const QString &specialBorderString);
private:
QSharedDataPointer<KoBorderPrivate> d;
};
......
......@@ -108,20 +108,23 @@ bool FloatingAnchorStrategy::moveSubject()
}
// Set shape horizontal alignment inside anchor bounding rectangle
countHorizontalPos(newPosition, anchorBoundingRect, containerBoundingRect);
countHorizontalPos(newPosition, anchorBoundingRect);
// Set shape vertical alignment inside anchor bounding rectangle
countVerticalPos(newPosition, anchorBoundingRect, containerBoundingRect);
countVerticalPos(newPosition, anchorBoundingRect);
newPosition = newPosition + offset;
newPosition += offset;
//check the border of page and move the shape back to have it visible
checkPageBorder(newPosition);
newPosition -= containerBoundingRect.topLeft();
//check the border of layout environment and move the shape back to have it within
if (m_anchor->flowWithText()) {
checkLayoutEnvironment(newPosition, data);
}
//check the border of page and move the shape back to have it visible
checkPageBorder(newPosition, containerBoundingRect);
checkStacking(newPosition);
......@@ -246,45 +249,43 @@ bool FloatingAnchorStrategy::countHorizontalRel(QRectF &anchorBoundingRect, QRec
return true;
}
void FloatingAnchorStrategy::countHorizontalPos(QPointF &newPosition, QRectF anchorBoundingRect, QRectF containerBoundingRect)
void FloatingAnchorStrategy::countHorizontalPos(QPointF &newPosition, QRectF anchorBoundingRect)
{
switch (m_anchor->horizontalPos()) {
case KoShapeAnchor::HCenter:
newPosition.setX(anchorBoundingRect.x() + anchorBoundingRect.width()/2
- m_anchor->shape()->size().width()/2 - containerBoundingRect.x());
newPosition.setX(anchorBoundingRect.x() + anchorBoundingRect.width()/2
- m_anchor->shape()->size().width()/2);
break;
case KoShapeAnchor::HFromInside:
case KoShapeAnchor::HInside:
{
if (pageNumber()%2 == 1) {
newPosition.setX(anchorBoundingRect.x() - containerBoundingRect.x());
newPosition.setX(anchorBoundingRect.x());
} else {
newPosition.setX(anchorBoundingRect.right() - containerBoundingRect.x() -
newPosition.setX(anchorBoundingRect.right() -
m_anchor->shape()->size().width() - 2*m_anchor->offset().x() );
}
break;
}
case KoShapeAnchor::HLeft:
case KoShapeAnchor::HFromLeft:
newPosition.setX(anchorBoundingRect.x() - containerBoundingRect.x());
newPosition.setX(anchorBoundingRect.x());
break;
case KoShapeAnchor::HOutside:
{
if (pageNumber()%2 == 1) {
newPosition.setX(anchorBoundingRect.right() - containerBoundingRect.x());
newPosition.setX(anchorBoundingRect.right());
} else {
QSizeF size = m_anchor->shape()->boundingRect().size();
newPosition.setX(anchorBoundingRect.x() - containerBoundingRect.x() -
size.width() - m_anchor->offset().x());
newPosition.setX(anchorBoundingRect.x() - size.width() - m_anchor->offset().x());
}
break;
}
case KoShapeAnchor::HRight: {
QSizeF size = m_anchor->shape()->boundingRect().size();
newPosition.setX(anchorBoundingRect.right() - containerBoundingRect.x()
- size.width());
newPosition.setX(anchorBoundingRect.right() - size.width());
break;
}
default :
......@@ -362,24 +363,23 @@ bool FloatingAnchorStrategy::countVerticalRel(QRectF &anchorBoundingRect, QRectF
return true;
}
void FloatingAnchorStrategy::countVerticalPos(QPointF &newPosition, QRectF anchorBoundingRect, QRectF containerBoundingRect)
void FloatingAnchorStrategy::countVerticalPos(QPointF &newPosition, QRectF anchorBoundingRect)
{
switch (m_anchor->verticalPos()) {
case KoShapeAnchor::VBottom:
newPosition.setY(anchorBoundingRect.bottom() - containerBoundingRect.y()
- m_anchor->shape()->size().height());
newPosition.setY(anchorBoundingRect.bottom() - m_anchor->shape()->size().height());
break;
case KoShapeAnchor::VBelow:
newPosition.setY(anchorBoundingRect.bottom() - containerBoundingRect.y());
newPosition.setY(anchorBoundingRect.bottom());
break;
case KoShapeAnchor::VMiddle:
newPosition.setY(anchorBoundingRect.y() + anchorBoundingRect.height()/2 - m_anchor->shape()->size().height()/2 - containerBoundingRect.y());
newPosition.setY(anchorBoundingRect.y() + anchorBoundingRect.height()/2 - m_anchor->shape()->size().height()/2);
break;
case KoShapeAnchor::VFromTop:
case KoShapeAnchor::VTop:
newPosition.setY(anchorBoundingRect.y() - containerBoundingRect.y());
newPosition.setY(anchorBoundingRect.y());
break;
default :
......@@ -413,28 +413,28 @@ void FloatingAnchorStrategy::checkLayoutEnvironment(QPointF &newPosition, KoText
}
}
void FloatingAnchorStrategy::checkPageBorder(QPointF &newPosition, const QRectF &containerBoundingRect)
void FloatingAnchorStrategy::checkPageBorder(QPointF &newPosition)
{
QSizeF size = m_anchor->shape()->boundingRect().size();
//check left border and move the shape back to have the whole shape visible
if (newPosition.x() < pageRect().x() - containerBoundingRect.x()) {
newPosition.setX(pageRect().x() - containerBoundingRect.x());
if (newPosition.x() < pageRect().x()) {
newPosition.setX(pageRect().x());
}
//check right border and move the shape back to have the whole shape visible
if ((newPosition.x() + size.width()) > (pageRect().x() + pageRect().width() - containerBoundingRect.x())) {
newPosition.setX(pageRect().x() + pageRect().width() - size.width() - containerBoundingRect.x());
if (newPosition.x() + size.width() > pageRect().x() + pageRect().width()) {
newPosition.setX(pageRect().x() + pageRect().width() - size.width());
}
//check top border and move the shape back to have the whole shape visible
if (newPosition.y() < (pageRect().y() - containerBoundingRect.y())) {
newPosition.setY(pageRect().y() - containerBoundingRect.y());
if (newPosition.y() < pageRect().y()) {
newPosition.setY(pageRect().y());
}
//check bottom border and move the shape back to have the whole shape visible
if ((newPosition.y() + size.height()) > (pageRect().y() + pageRect().height() - containerBoundingRect.y())) {
newPosition.setY(pageRect().y() + pageRect().height() - size.height() - containerBoundingRect.y());
if (newPosition.y() + size.height() > pageRect().y() + pageRect().height()) {
newPosition.setY(pageRect().y() + pageRect().height() - size.height());
}
}
......
......@@ -49,15 +49,15 @@ private:
inline bool countHorizontalRel(QRectF &anchorBoundingRect, QRectF containerBoundingRect,
QTextBlock &block, QTextLayout *layout);
inline void countHorizontalPos(QPointF &newPosition, QRectF anchorBoundingRect, QRectF containerBoundingRect);
inline void countHorizontalPos(QPointF &newPosition, QRectF anchorBoundingRect);
inline bool countVerticalRel(QRectF &anchorBoundingRect, QRectF containerBoundingRect,
KoTextShapeData *data, QTextBlock &block, QTextLayout *layout);
inline void countVerticalPos(QPointF &newPosition, QRectF anchorBoundingRect, QRectF containerBoundingRect);
inline void countVerticalPos(QPointF &newPosition, QRectF anchorBoundingRect);
//check the layout evironment and move the shape back to have it within
inline void checkLayoutEnvironment(QPointF &newPosition, KoTextShapeData *data);
//check the border of page and move the shape back to have it visible
inline void checkPageBorder(QPointF &newPosition, const QRectF &containerBoundingRect);
inline void checkPageBorder(QPointF &newPosition);
//check stacking and reorder to proper position objects according to there z-index
inline void checkStacking(QPointF &newPosition);
......
......@@ -709,10 +709,10 @@ bool KoTextDocumentLayout::doLayout()
}
if (shouldLayout) {
QSizeF size = d->provider->suggestSize(rootArea);
QRectF rect = d->provider->suggestRect(rootArea);
d->freeObstructions = d->provider->relevantObstructions(rootArea);
rootArea->setReferenceRect(0, size.width(), d->y, d->y + size.height());
rootArea->setReferenceRect(rect.left(), rect.right(), d->y + rect.top(), d->y + rect.bottom());
beginAnchorCollecting(rootArea);
......@@ -797,10 +797,10 @@ bool KoTextDocumentLayout::doLayout()
if (rootArea) {
d->rootAreaList.append(rootArea);
QSizeF size = d->provider->suggestSize(rootArea);
QRectF rect = d->provider->suggestRect(rootArea);
d->freeObstructions = d->provider->relevantObstructions(rootArea);
rootArea->setReferenceRect(0, size.width(), d->y, d->y + size.height());
rootArea->setReferenceRect(rect.left(), rect.right(), d->y + rect.top(), d->y + rect.bottom());
beginAnchorCollecting(rootArea);
......
......@@ -58,8 +58,8 @@ public:
/// use with care - it eats a lot of processing for no real gain
virtual void updateAll() = 0;
/// Returns a suggested a size for the root area
virtual QSizeF suggestSize(KoTextLayoutRootArea *rootArea) = 0;
/// Returns a suggested offset and size for the root area
virtual QRectF suggestRect(KoTextLayoutRootArea *rootArea) = 0;
/// Return a list of obstructions intersecting root area
virtual QList<KoTextLayoutObstruction *> relevantObstructions(KoTextLayoutRootArea *rootArea) = 0;
......
......@@ -147,7 +147,16 @@ void KoTextShapeData::setDocument(QTextDocument *document, bool transferOwnershi
qreal KoTextShapeData::documentOffset() const
{
Q_D(const KoTextShapeData);
return d->rootArea ? d->rootArea->top() : 0.0;
if (d->rootArea) {
KoBorder *border = d->rootArea->associatedShape()->border();
if (border) {
return d->rootArea->top() - topPadding() - border->borderWidth(KoBorder::TopBorder);
} else {
return d->rootArea->top() - topPadding();
}
} else {
return 0.0;
}
}
void KoTextShapeData::setDirty()
......
......@@ -23,7 +23,7 @@
MockRootAreaProvider::MockRootAreaProvider()
: m_area(0),
m_suggestedSize(QSizeF(200,1000)),
m_suggestedRect(QRectF(100, 100, 200,1000)),
m_askedForMoreThenOneArea(false)
{
}
......@@ -53,15 +53,15 @@ void MockRootAreaProvider::releaseAllAfter(KoTextLayoutRootArea *afterThis)
Q_UNUSED(afterThis);
}
QSizeF MockRootAreaProvider::suggestSize(KoTextLayoutRootArea *rootArea)
QRectF MockRootAreaProvider::suggestRect(KoTextLayoutRootArea *rootArea)
{
Q_UNUSED(rootArea);
return m_suggestedSize;
return m_suggestedRect;
}
void MockRootAreaProvider::setSuggestedSize(QSizeF size)
void MockRootAreaProvider::setSuggestedRect(QRectF rect)
{
m_suggestedSize = size;
m_suggestedRect = rect;
}
QList<KoTextLayoutObstruction *> MockRootAreaProvider::relevantObstructions(KoTextLayoutRootArea *rootArea)
......
......@@ -31,14 +31,14 @@ public:
virtual KoTextLayoutRootArea *provide(KoTextDocumentLayout *documentLayout);
virtual void releaseAllAfter(KoTextLayoutRootArea *afterThis);
virtual void doPostLayout(KoTextLayoutRootArea *rootArea, bool isNewRootArea);
virtual QSizeF suggestSize(KoTextLayoutRootArea *rootArea);
virtual QRectF suggestRect(KoTextLayoutRootArea *rootArea);
virtual QList<KoTextLayoutObstruction *> relevantObstructions(KoTextLayoutRootArea *rootArea);
virtual void updateAll();
void setSuggestedSize(QSizeF size);
void setSuggestedRect(QRectF rect);
KoTextLayoutRootArea *m_area;
QSizeF m_suggestedSize;
QRectF m_suggestedRect;
bool m_askedForMoreThenOneArea;
};
......
......@@ -136,7 +136,7 @@ void TestDocumentLayout::testRootAreaZeroWidth()
setupTest("a");
MockRootAreaProvider *provider = dynamic_cast<MockRootAreaProvider*>(m_layout->provider());
provider->setSuggestedSize(QSizeF(0.,200.));
provider->setSuggestedRect(QRectF(10., 10., 0., 200.));
m_layout->layout();
......@@ -157,7 +157,7 @@ void TestDocumentLayout::testRootAreaZeroHeight()
setupTest("a");
MockRootAreaProvider *provider = dynamic_cast<MockRootAreaProvider*>(m_layout->provider());
provider->setSuggestedSize(QSizeF(200.,0.));
provider->setSuggestedRect(QRectF(10., 10., 200.,0.));
m_layout->layout();
......@@ -176,7 +176,7 @@ void TestDocumentLayout::testRootAreaZeroWidthAndHeight()
setupTest("a");
MockRootAreaProvider *provider = dynamic_cast<MockRootAreaProvider*>(m_layout->provider());
provider->setSuggestedSize(QSizeF(0.,0.));
provider->setSuggestedRect(QRectF(10., 10., 0., 0.));
m_layout->layout();
......
......@@ -265,15 +265,20 @@ QPainterPath PictureShape::shadowOutline() const
return outline();
}
void PictureShape::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &)
void PictureShape::paint(QPainter &painter, const KoViewConverter &converter,
KoShapePaintingContext &paintContext)
{
QRectF viewRect = converter.documentToView(QRectF(QPointF(0,0), size()));
if (imageData() == 0) {
painter.fillRect(viewRect, QColor(Qt::gray));
return;
}
painter.save();
applyConversion(painter, converter);
paintBorder(painter, converter);
painter.restore();
QSize pixmapSize = calcOptimalPixmapSize(viewRect.size(), imageData()->image().size());
// Normalize the clipping rect if it isn't already done.
......
......@@ -54,13 +54,19 @@ void SimpleRootAreaProvider::doPostLayout(KoTextLayoutRootArea *rootArea, bool i
{
Q_UNUSED(isNewRootArea);
QRectF updateRect = rootArea->associatedShape()->outlineRect();