Commit 24c47d36 authored by Yue Liu's avatar Yue Liu

make center glue point a default glue point

parent f407ce91
......@@ -109,6 +109,7 @@ KoShapePrivate::KoShapePrivate(KoShape *shape)
connectors[KoConnectionPoint::RightConnectionPoint] = KoConnectionPoint::defaultConnectionPoint(KoConnectionPoint::RightConnectionPoint);
connectors[KoConnectionPoint::BottomConnectionPoint] = KoConnectionPoint::defaultConnectionPoint(KoConnectionPoint::BottomConnectionPoint);
connectors[KoConnectionPoint::LeftConnectionPoint] = KoConnectionPoint::defaultConnectionPoint(KoConnectionPoint::LeftConnectionPoint);
connectors[KoConnectionPoint::FirstCustomConnectionPoint] = KoConnectionPoint(QPointF(0.5, 0.5), KoConnectionPoint::AllDirections, KoConnectionPoint::AlignCenter);
}
KoShapePrivate::~KoShapePrivate()
......@@ -1680,6 +1681,7 @@ void KoShape::loadOdfGluePoints(const KoXmlElement &element, KoShapeLoadingConte
Q_D(KoShape);
KoXmlElement child;
bool hasCenterGluePoint = false;
forEachElement(child, element) {
if (child.namespaceURI() != KoXmlNS::draw)
continue;
......@@ -1691,7 +1693,11 @@ void KoShape::loadOdfGluePoints(const KoXmlElement &element, KoShapeLoadingConte
// doesn't support xml:id (and so, maybe, shouldn't use KoElementReference.
const QString id = child.attributeNS(KoXmlNS::draw, "id", QString());
const int index = id.toInt();
if(id.isEmpty() || index < 4 || d->connectors.contains(index)) {
// connection point in center should be default but odf doesn't support,
// in new shape, first custom point is in center, it's okay to replace that point
// with point from xml now, we'll add it back later
if(id.isEmpty() || index < KoConnectionPoint::FirstCustomConnectionPoint ||
(index != KoConnectionPoint::FirstCustomConnectionPoint && d->connectors.contains(index))) {
kWarning(30006) << "glue-point with no or invalid id";
continue;
}
......@@ -1765,6 +1771,15 @@ void KoShape::loadOdfGluePoints(const KoXmlElement &element, KoShapeLoadingConte
}
d->connectors[index] = connector;
kDebug(30006) << "loaded glue-point" << index << "at position" << connector.position;
if (d->connectors[index].position == QPointF(0.5, 0.5)) {
hasCenterGluePoint = true;
kDebug(30006) << "center glue-point found at id " << index;
}
}
if (!hasCenterGluePoint) {
d->connectors[d->connectors.count()] = KoConnectionPoint(QPointF(0.5, 0.5),
KoConnectionPoint::AllDirections, KoConnectionPoint::AlignCenter);
kDebug(30006) << "center glue-point added at id " << index;
}
kDebug(30006) << "shape has now" << d->connectors.count() << "glue-points";
}
......
......@@ -472,7 +472,19 @@ void ConnectionTool::mouseDoubleClickEvent(KoPointerEvent *event)
QPointF point = m_currentShape->documentToShape(mousePos);
canvas()->addCommand(new AddConnectionPointCommand(m_currentShape, point));
} else {
canvas()->addCommand(new RemoveConnectionPointCommand(m_currentShape, handleId));
// don't remove last center glue point since we want it to be "default"
bool dontRemove = m_currentShape->connectionPoint(handleId).position == QPointF(0.5, 0.5);
int centerGluePointCount = 0;
KoConnectionPoints::const_iterator i;
for (i=m_currentShape->connectionPoints().constBegin();
i!=m_currentShape->connectionPoints().constEnd(); ++i) {
if (i.value().position == QPointF(0.5, 0.5)) {
centerGluePointCount++;
}
}
if (!dontRemove || (dontRemove && centerGluePointCount > 1)) {
canvas()->addCommand(new RemoveConnectionPointCommand(m_currentShape, handleId));
}
}
setEditMode(m_editMode, m_currentShape, -1);
} else {
......@@ -923,8 +935,20 @@ void ConnectionTool::deleteSelection()
{
if (m_editMode == EditConnectionPoint && m_currentShape && m_activeHandle >= 0) {
repaintDecorations();
canvas()->addCommand(new RemoveConnectionPointCommand(m_currentShape, m_activeHandle));
setEditMode(m_editMode, m_currentShape, -1);
// don't remove last center glue point since we want it to be "default"
bool dontRemove = m_currentShape->connectionPoint(m_activeHandle).position == QPointF(0.5, 0.5);
int centerGluePointCount = 0;
KoConnectionPoints::const_iterator i;
for (i=m_currentShape->connectionPoints().constBegin();
i!=m_currentShape->connectionPoints().constEnd(); ++i) {
if (i.value().position == QPointF(0.5, 0.5)) {
centerGluePointCount++;
}
}
if (!dontRemove || (dontRemove && centerGluePointCount > 1)) {
canvas()->addCommand(new RemoveConnectionPointCommand(m_currentShape, m_activeHandle));
setEditMode(m_editMode, m_currentShape, -1);
}
} else if (m_editMode == EditConnection && m_currentShape) {
repaintDecorations();
canvas()->addCommand(canvas()->shapeController()->removeShape(m_currentShape));
......
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