Commit 670c9903 authored by Alex Diev's avatar Alex Diev
Browse files

Merge branch 'dengof_#126' into 'master'

1px-fine items positioning with arrow keys

Closes #126

See merge request esa/taste3!188
parents eadeae33 e4e1fc82
Pipeline #1542 failed with stage
......@@ -20,6 +20,7 @@
#include "baseitems/common/utils.h"
#include "baseitems/interactiveobject.h"
#include "tab_aadl/aadlobject.h"
#include "tab_interface/aadlrectgraphicsitem.h"
#include <QGraphicsItem>
#include <QMouseEvent>
......@@ -137,9 +138,34 @@ void GraphicsView::keyPressEvent(QKeyEvent *event)
if (event->modifiers() & Qt::ControlModifier && (event->key() == Qt::Key_Plus || event->key() == Qt::Key_Minus)) {
setZoom(m_zoomPercent + (event->key() == Qt::Key_Plus ? zoomStepPercent() : -zoomStepPercent()));
Q_EMIT zoomChanged(m_zoomPercent);
} else {
QGraphicsView::keyPressEvent(event);
event->accept();
return;
}
bool keyHandled(false);
switch (event->key()) {
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Up:
case Qt::Key_Down: {
for (QGraphicsItem *item : scene()->selectedItems()) {
if (aadl::AADLRectGraphicsItem *rectItem =
// Not the qgraphicsitem_cast due its "successfull" cast of AADLFunctionName/Text Graphics Items
qobject_cast<aadl::AADLRectGraphicsItem *>(item->toGraphicsObject())) {
rectItem->singleStepMove(aadl::AADLRectGraphicsItem::MoveStep(event->key()));
keyHandled = true;
}
}
break;
}
default:
break;
}
if (keyHandled)
event->accept();
else
QGraphicsView::keyPressEvent(event);
}
void GraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
......
......@@ -22,7 +22,9 @@
#include "baseitems/grippointshandler.h"
#include "tab_aadl/aadlobject.h"
#include <QKeyEvent>
#include <QtDebug>
namespace taste3 {
namespace aadl {
......@@ -234,5 +236,48 @@ void AADLRectGraphicsItem::onManualMoveFinish(GripPoint *grip, const QPointF &pr
updateFromEntity();
}
void AADLRectGraphicsItem::singleStepMove(MoveStep direction)
{
static constexpr qreal delta = 1.;
QPointF shift;
switch (direction) {
case MoveStep::Left: {
shift.setX(-delta);
break;
}
case Right: {
shift.setX(delta);
break;
}
case MoveStep::Up: {
shift.setY(-delta);
break;
}
case MoveStep::Down: {
shift.setY(delta);
break;
}
default: {
return;
}
}
shiftBy(shift);
}
void AADLRectGraphicsItem::shiftBy(const QPointF &shift)
{
if (shift.isNull())
return;
const QPointF pressedAt = sceneBoundingRect().center();
const QPointF releasedAt = pressedAt + shift;
onManualMoveStart(nullptr, pressedAt);
onManualMoveProgress(nullptr, pressedAt, releasedAt);
onManualMoveFinish(nullptr, pressedAt, releasedAt);
}
} // namespace aadl
} // namespace taste3
......@@ -33,6 +33,15 @@ public:
void updateFromEntity() override;
QList<QVariantList> prepareChangeCoordinatesCommandParams() const override;
enum MoveStep
{
Left = Qt::Key_Left,
Right = Qt::Key_Right,
Up = Qt::Key_Up,
Down = Qt::Key_Down
};
void singleStepMove(MoveStep direction);
protected:
void rebuildLayout() override;
void initGripPoints() override;
......@@ -43,6 +52,7 @@ protected:
QRectF adjustRectToParent(GripPoint *grip, const QPointF &from, const QPointF &to);
bool allowGeometryChange(const QPointF &from, const QPointF &to);
void shiftBy(const QPointF &shift);
};
} // namespace aadl
......
......@@ -26,7 +26,7 @@ class AADLObjectImp : public taste3::aadl::AADLObject
Q_OBJECT
public:
explicit AADLObjectImp(const QString &title = QString(), QObject *parent = nullptr)
: AADLObject(AADLObject::Type::Unknown, title, parent)
: AADLObject(AADLObject::Type::Function, title, parent)
{
}
};
......
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