Commit d4ec785e authored by Jan Hambrecht's avatar Jan Hambrecht

added support for inserting a connection point with a specific id, needed for undo commands

parent a610390d
......@@ -754,21 +754,38 @@ int KoShape::addConnectionPoint(const QPointF &point)
if (d->connectors.size())
nextConnectionPointId = qMax(nextConnectionPointId, (--d->connectors.end()).key()+1);
// allow adding default connection point
if (connectionPoint == d->defaultConnectionPoint(KoFlake::TopConnectionPoint))
nextConnectionPointId = KoFlake::TopConnectionPoint;
else if (connectionPoint == d->defaultConnectionPoint(KoFlake::RightConnectionPoint))
nextConnectionPointId = KoFlake::RightConnectionPoint;
else if (connectionPoint == d->defaultConnectionPoint(KoFlake::BottomConnectionPoint))
nextConnectionPointId = KoFlake::BottomConnectionPoint;
else if (connectionPoint == d->defaultConnectionPoint(KoFlake::LeftConnectionPoint))
nextConnectionPointId = KoFlake::LeftConnectionPoint;
d->connectors[nextConnectionPointId] = connectionPoint;
return nextConnectionPointId;
}
bool KoShape::insertConnectionPoint(const QPointF &point, int connectionPointId)
{
Q_D(KoShape);
if (connectionPointId < 0 || d->connectors.contains(connectionPointId))
return false;
QSizeF s = size();
// convert glue point from shape coordinates to factors of size
QPointF connectionPoint(point.x() / s.width(), point.y() / s.height());
switch(connectionPointId) {
case KoFlake::TopConnectionPoint:
case KoFlake::RightConnectionPoint:
case KoFlake::BottomConnectionPoint:
case KoFlake::LeftConnectionPoint:
connectionPoint = d->defaultConnectionPoint(static_cast<KoFlake::ConnectionPointId>(connectionPointId));
break;
default:
// do nothing for all other cases
break;
}
d->connectors[connectionPointId] = connectionPoint;
return true;
}
bool KoShape::hasConnectionPoint(int connectionPointId) const
{
Q_D(const KoShape);
......
......@@ -326,6 +326,15 @@ public:
*/
int addConnectionPoint(const QPointF &point);
/**
* Tries to insert connection point with specified id.
* @param point the position of the connector in shape coordinates
* @param connectionPointId the id of the connection point to insert
* @return true if inserting connection point was successful;
* false if connection point did already exists or id is invalid
*/
bool insertConnectionPoint(const QPointF &point, int connectionPointId);
/// Checks if a connection point with the specified id exists
bool hasConnectionPoint(int connectionPointId) const;
......
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