called when any property changes (like position)
| 1003 | |
| 1004 | // called when any property changes (like position) |
| 1005 | QVariant WorksheetElementPrivate::itemChange(GraphicsItemChange change, const QVariant& value) { |
| 1006 | if (suppressItemChangeEvent || !(this->flags() & QGraphicsItem::ItemIsMovable)) |
| 1007 | return value; |
| 1008 | |
| 1009 | if (change == QGraphicsItem::ItemPositionChange) { |
| 1010 | auto currPos = pos(); |
| 1011 | auto newPos = value.toPointF(); |
| 1012 | switch (position.positionLimit) { |
| 1013 | case WorksheetElement::PositionLimit::X: |
| 1014 | newPos.setY(currPos.y()); |
| 1015 | break; |
| 1016 | case WorksheetElement::PositionLimit::Y: |
| 1017 | newPos.setX(currPos.x()); |
| 1018 | break; |
| 1019 | case WorksheetElement::PositionLimit::None: |
| 1020 | default: |
| 1021 | break; |
| 1022 | } |
| 1023 | |
| 1024 | // don't use setPosition here, because then all small changes are on the undo stack |
| 1025 | // setPosition is used then in mouseReleaseEvent |
| 1026 | if (coordinateBindingEnabled) { |
| 1027 | DEBUG(Q_FUNC_INFO << ", coordinate binding enabled") |
| 1028 | if (!q->cSystem->isValid()) |
| 1029 | return QGraphicsItem::itemChange(change, value); |
| 1030 | auto pos = q->align(newPos, m_boundingRectangle, horizontalAlignment, verticalAlignment, false); |
| 1031 | |
| 1032 | positionLogical = q->cSystem->mapSceneToLogical(mapParentToPlotArea(pos), AbstractCoordinateSystem::MappingFlag::SuppressPageClipping); |
| 1033 | Q_EMIT q->positionLogicalChanged(positionLogical); |
| 1034 | Q_EMIT q->objectPositionChanged(); |
| 1035 | } else { |
| 1036 | DEBUG(Q_FUNC_INFO << ", coordinate binding disabled") |
| 1037 | auto tempPosition = position; |
| 1038 | tempPosition.point = q->align(newPos, boundingRect(), horizontalAlignment, verticalAlignment, false); |
| 1039 | // in percentage |
| 1040 | auto parentRect = q->parentRect(); |
| 1041 | tempPosition.point.setX((tempPosition.point.x() - parentRect.x()) / parentRect.width()); |
| 1042 | tempPosition.point.setY((tempPosition.point.y() - parentRect.y()) / parentRect.height()); |
| 1043 | |
| 1044 | // Q_EMIT the signals in order to notify the UI. |
| 1045 | Q_EMIT q->positionChanged(tempPosition); |
| 1046 | Q_EMIT q->objectPositionChanged(); |
| 1047 | } |
| 1048 | return QGraphicsItem::itemChange(change, newPos); |
| 1049 | } |
| 1050 | |
| 1051 | return QGraphicsItem::itemChange(change, value); |
| 1052 | } |
| 1053 | |
| 1054 | /*! |
| 1055 | * \brief WorksheetElementPrivate::mapParentToPlotArea |