24 #include <QGraphicsSceneHoverEvent> 25 #include <QStyleOptionGraphicsItem> 26 #include <QGraphicsScene> 34 QGraphicsObject(parent)
57 if (!horto.width() || !horto.height()) {
63 rect = rect.united(item -> sceneGeometricRect());
91 QPen pen(Qt::DashLine);
92 pen.setCosmetic(
true);
93 painter -> setPen(pen);
111 if (focusItem() !=
this) {
122 QList<CustomElementPart *> primitives;
123 for(QGraphicsItem *item :
items)
127 primitives << part_item;
144 QList<QGraphicsItem *> list;
146 if (QGraphicsItem *item = dynamic_cast<QGraphicsItem *>(part_item)) {
191 QPointF scene_pos =
event -> scenePos();
199 movement = rounded_current_position -
decorated_items_.at(0) -> toItem() -> scenePos();
230 if (!movement.isNull())
233 command = move_command;
251 const qreal movement_length = 1.0;
256 case Qt::Key_Left: movement = QPointF(-movement_length, 0.0);
break;
257 case Qt::Key_Right: movement = QPointF(+movement_length, 0.0);
break;
258 case Qt::Key_Up: movement = QPointF(0.0, -movement_length);
break;
259 case Qt::Key_Down: movement = QPointF(0.0, +movement_length);
break;
261 if (!movement.isNull() && focusItem() ==
this)
275 qgi -> setPos(qgi -> pos() + movement);
283 QGraphicsObject::keyPressEvent(e);
292 (e -> key() == Qt::Key_Left || e -> key() == Qt::Key_Right ||\
293 e -> key() == Qt::Key_Up || e -> key() == Qt::Key_Down) &&\
303 QGraphicsObject::keyPressEvent(e);
311 setFlag(QGraphicsItem::ItemIsFocusable,
true);
313 setAcceptHoverEvents(
true);
328 prepareGeometryChange();
352 switch (movement_type) {
354 rect.translate(movement.x(), movement.y());
357 new_point = rect.topLeft() + movement;
358 rect.setTopLeft(new_point);
361 new_value = rect.top() + movement.y();
362 rect.setTop(new_value);
365 new_point = rect.topRight() + movement;
366 rect.setTopRight(new_point);
369 new_value = rect.left() + movement.x();
370 rect.setLeft(new_value);
373 new_value = rect.right() + movement.x();
374 rect.setRight(new_value);
377 new_point = rect.bottomLeft() + movement;
378 rect.setBottomLeft(new_point);
381 new_value = rect.bottom() + movement.y();
382 rect.setBottom(new_value);
385 new_point = rect.bottomRight() + movement;
386 rect.setBottomRight(new_point);
407 qgi -> moveBy(movement.x(), movement.y());
418 if (original_rect == new_rect)
return;
419 if (!original_rect.width() || !original_rect.height())
return;
421 QRectF scene_original_rect = mapToScene(original_rect).boundingRect();
422 QRectF scene_new_rect = mapToScene(new_rect).boundingRect();
425 item -> handleUserTransformation(scene_original_rect, scene_new_rect);
433 if (!item)
return(QRectF());
440 QVector <QPointF> vector;
443 vector << primitive_rect.topLeft();
444 half = primitive_rect.center();
445 half.setY(primitive_rect.top());
447 vector << primitive_rect.topRight();
448 half = primitive_rect.center();
449 half.setX(primitive_rect.left());
451 half = primitive_rect.center();
452 half.setX(primitive_rect.right());
454 vector << primitive_rect.bottomLeft();
455 half = primitive_rect.center();
456 half.setY(primitive_rect.bottom());
458 vector << primitive_rect.bottomRight();
469 for (
int i = 0 ; i < points_vector.size() ; ++i)
499 QPointF scene_pos =
event -> scenePos();
507 QPointF global_movement = scene_pos -
first_pos_;
509 QPointF rounded_global_movement;
520 const qreal scale_epsilon = 20.0;
524 rounded_global_movement = global_movement + delta;
528 QPointF rounded_scene_pos =
first_pos_ + rounded_global_movement;
533 movement = rounded_scene_pos - current_position;
559 scale_command -> setScaledPrimitives(
items());
560 scale_command -> setTransformation(
564 command = scale_command;
588 scene()->addItem(handler);
589 handler->setColor(Qt::darkGreen);
590 handler->installSceneEventFilter(
this);
591 handler->setZValue(this->zValue()+1);
620 qreal sx = current.width() / original.width();
621 qreal sy = current.height() / original.height();
627 original.width() * (sx_rounded - sx),
628 original.height() * (sy_rounded - sy)
660 return(!(event -> modifiers() & Qt::ControlModifier));
674 return single_item -> preferredScalingMethod();
687 if (change == ItemSceneHasChanged)
694 else if (change == ItemVisibleHasChanged)
696 bool visible = value.toBool();
698 qghi->setVisible(visible);
703 qghi->setZValue(this->zValue()+1);
706 return QGraphicsObject::itemChange(change, value);
727 if(event->type() == QEvent::GraphicsSceneMousePress)
732 else if(event->type() == QEvent::GraphicsSceneMouseMove)
737 else if (event->type() == QEvent::GraphicsSceneMouseRelease)
QPointF deltaForRoundScaling(const QRectF &, const QRectF &, qreal)
void keyPressEvent(QKeyEvent *) override
void saveOriginalBoundingRect()
QRectF modified_bounding_rect_
new bounding rect, after the user moved or resized items
snap the point used to define the new bounding rectangle to the grid
void addHandler()
ElementPrimitiveDecorator::addHandler Add handlers for this item.
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
QVector< QPointF > getResizingsPoints() const
QPointF snapConstPointToGrid(const QPointF &) const
bool moving_by_keys_
Whether we are currently moving our decorated items using the arrow keys.
~ElementPrimitiveDecorator() override
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
ElementPrimitiveDecorator::handlerMouseReleaseEvent.
QList< CustomElementPart * > items() const
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
QPointF keys_movement_
Movement applied to our decorated items using the arrow keys.
void actionFinished(ElementEditionCommand *)
QList< QGraphicsItem * > graphicsItems() const
QET::ScalingMethod scalingMethod(QGraphicsSceneMouseEvent *)
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
QPointF mouse_offset_
Offset between the mouse position and the point to be snapped to grid when moving selection...
QList< CustomElementPart * > decorated_items_
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
ElementPrimitiveDecorator::handlerMousePressEvent.
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
ElementPrimitiveDecorator::itemChange.
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
ElementPrimitiveDecorator::handlerMouseMoveEvent.
The ElementEditionCommand class ElementEditionCommand is the base class for all commands classes invo...
QPointF latest_pos_
Latest point involved within the current resizing operation.
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
ElementPrimitiveDecorator::sceneEventFilter.
qreal round(qreal, qreal)
int current_operation_square_
adjust the scaling movement so that the induced scaling ratios are rounded
QRectF effective_bounding_rect_
actual, effective bounding rect – never shrinks
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
void snapPointToGrid(QPointF &) const
void applyMovementToRect(int, const QPointF &, QRectF &)
int grid_step_x_
Grid horizontal step.
void keyReleaseEvent(QKeyEvent *) override
QRectF original_bounding_rect_
original bounding rect
QRectF internalBoundingRect() const
ScalingMethod
Supported types of interactive scaling, typically for a single element primitive. ...
do not interfer with the default scaling process
void adjusteHandlerPos()
ElementPrimitiveDecorator::adjusteHandlerPos.
QRectF boundingRect() const override
QPointF first_pos_
First point involved within the current resizing operation.
void removeHandler()
ElementPrimitiveDecorator::removeHandler Remove the handlers of this item.
ElementPrimitiveDecorator(QGraphicsItem *=nullptr)
void mousePressEvent(QGraphicsSceneMouseEvent *) override
int grid_step_y_
Grid horizontal step.
void setItems(const QList< QGraphicsItem *> &)
bool mustSnapToGrid(QGraphicsSceneMouseEvent *)
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.
void translateItems(const QPointF &)
QRectF getSceneBoundingRect(QGraphicsItem *) const
CustomElementPart * singleItem() const
void scaleItems(const QRectF &, const QRectF &)
void adjustEffectiveBoundingRect()
QVector< QetGraphicsHandlerItem * > m_handler_vector