Commit 8bd52912 authored by C. Boemann's avatar C. Boemann

Shape moving restrictions based on anchor properties.

This is the page anchors equivalent of the char and paragraph anchors code we
already have.

This makes a difference both on initial layout (nice improvements)
and on interactive moving of page anchored shapes.

This commit also fixes the default anchoring properties to be the same as in LO.

This commit also fixes it so the page anchored iages doesn't leave empty rects on
page 1 after reload

BUG: 312193
BUG: 310715
BUG: 312982
REVIEW: 108358
parent 1f1f8508
......@@ -540,6 +540,11 @@ bool KoTextAnchor::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &c
d->anchorType = AnchorParagraph;
} else if (anchorType == "page") {
d->anchorType = AnchorPage;
// it has different defaults at least LO thinks so - ODF doesn't define defaults for this
d->horizontalPos = HFromLeft;
d->verticalPos = VFromTop;
d->horizontalRel = HPage;
d->verticalRel = VPage;
}
if (anchorType == "page" && shape()->hasAdditionalAttribute("text:anchor-page-number")) {
......@@ -548,8 +553,12 @@ bool KoTextAnchor::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &c
// invalid if the page-number is invalid (OO.org does the same)
// see http://bugs.kde.org/show_bug.cgi?id=281869
d->pageNumber = -1;
shape()->setVisible(false);
}
// always make it invisible or it will create empty rects on the first page
// during initial layout. This is because only when we layout it's final page is
// the shape moved away from page 1
// in KWRootAreaProvider of textlayout it's set back to visible
shape()->setVisible(false);
} else {
d->pageNumber = -1;
}
......
......@@ -33,10 +33,11 @@
#include <KLocale>
ShapeMoveStrategy::ShapeMoveStrategy(KoToolBase *tool, const QPointF &clicked)
: KoInteractionStrategy(tool),
m_start(clicked)
: KoInteractionStrategy(tool)
, m_start(clicked)
, m_canvas(tool->canvas())
{
QList<KoShape*> selectedShapes = tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection);
QList<KoShape*> selectedShapes = m_canvas->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection);
QRectF boundingRect;
foreach(KoShape *shape, selectedShapes) {
if (! shape->isEditable())
......@@ -46,10 +47,10 @@ ShapeMoveStrategy::ShapeMoveStrategy(KoToolBase *tool, const QPointF &clicked)
m_newPositions << shape->position();
boundingRect = boundingRect.unite( shape->boundingRect() );
}
KoSelection * selection = tool->canvas()->shapeManager()->selection();
KoSelection * selection = m_canvas->shapeManager()->selection();
m_initialOffset = selection->absolutePosition( SelectionDecorator::hotPosition() ) - m_start;
m_initialSelectionPosition = selection->position();
tool->canvas()->snapGuide()->setIgnoredShapes( selection->selectedShapes( KoFlake::FullSelection ) );
m_canvas->snapGuide()->setIgnoredShapes( selection->selectedShapes( KoFlake::FullSelection ) );
tool->setStatusText(i18n("Press ALT to hold x- or y-position."));
}
......@@ -103,8 +104,11 @@ void ShapeMoveStrategy::moveSelection()
int i=0;
foreach(KoShape *shape, m_selectedShapes) {
QPointF delta = m_previousPositions.at(i) + m_diff - shape->position();
if(shape->parent())
if (shape->parent()) {
shape->parent()->model()->proposeMove(shape, delta);
} else {
m_canvas->clipToDocument(shape, delta);
}
tool()->canvas()->clipToDocument(shape, delta);
QPointF newPos (shape->position() + delta);
m_newPositions[i] = newPos;
......
......@@ -57,6 +57,7 @@ private:
QList<QPointF> m_newPositions;
QPointF m_start, m_diff, m_initialSelectionPosition, m_initialOffset;
QList<KoShape*> m_selectedShapes;
KoCanvasBase *m_canvas;
};
#endif
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