| 907 | } |
| 908 | |
| 909 | void WorksheetElementPrivate::keyPressEvent(QKeyEvent* event) { |
| 910 | const bool keyVertical = event->key() == Qt::Key_Up || event->key() == Qt::Key_Down; |
| 911 | const bool keyHorizontal = event->key() == Qt::Key_Left || event->key() == Qt::Key_Right; |
| 912 | if ((keyHorizontal && position.positionLimit != WorksheetElement::PositionLimit::Y) |
| 913 | || (keyVertical && position.positionLimit != WorksheetElement::PositionLimit::X)) { |
| 914 | const int delta = 5; // always in scene coordinates |
| 915 | |
| 916 | WorksheetElement::PositionWrapper tempPosition = position; |
| 917 | if (coordinateBindingEnabled && q->cSystem) { |
| 918 | if (!q->cSystem->isValid()) |
| 919 | return; |
| 920 | // the position in logical coordinates was changed, calculate the position in scene coordinates |
| 921 | bool visible; |
| 922 | QPointF p = q->cSystem->mapLogicalToScene(positionLogical, visible, AbstractCoordinateSystem::MappingFlag::SuppressPageClipping); |
| 923 | if (event->key() == Qt::Key_Left) { |
| 924 | p.setX(p.x() - delta); |
| 925 | } else if (event->key() == Qt::Key_Right) { |
| 926 | p.setX(p.x() + delta); |
| 927 | } else if (event->key() == Qt::Key_Up) { |
| 928 | p.setY(p.y() - delta); // y-axis is reversed, change the sign here |
| 929 | } else if (event->key() == Qt::Key_Down) { |
| 930 | p.setY(p.y() + delta); |
| 931 | } |
| 932 | auto pLogic = q->cSystem->mapSceneToLogical(p, AbstractCoordinateSystem::MappingFlag::SuppressPageClipping); |
| 933 | q->setPositionLogical(pLogic); // So it is undoable |
| 934 | } else { |
| 935 | QPointF point = q->parentPosToRelativePos(pos(), position); |
| 936 | point = q->align(point, m_boundingRectangle, horizontalAlignment, verticalAlignment, false); |
| 937 | |
| 938 | if (event->key() == Qt::Key_Left) { |
| 939 | point.setX(point.x() - delta); |
| 940 | } else if (event->key() == Qt::Key_Right) { |
| 941 | point.setX(point.x() + delta); |
| 942 | } else if (event->key() == Qt::Key_Up) { |
| 943 | point.setY(point.y() + delta); |
| 944 | } else if (event->key() == Qt::Key_Down) { |
| 945 | point.setY(point.y() - delta); |
| 946 | } |
| 947 | tempPosition.point = point; |
| 948 | q->setPosition(tempPosition); // So it is undoable |
| 949 | } |
| 950 | event->accept(); |
| 951 | } else |
| 952 | QGraphicsItem::keyPressEvent(event); |
| 953 | } |
| 954 | |
| 955 | void WorksheetElementPrivate::mousePressEvent(QGraphicsSceneMouseEvent* event) { |
| 956 | // when moving the element with the mouse (left button pressed), the move event doesn't have |
nothing calls this directly
no test coverage detected