mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Element editor : improve the behavior with the arrow keys (depending to the current selection : nothing / one / several)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5272 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -246,26 +246,38 @@ void ElementPrimitiveDecorator::mouseReleaseEvent(QGraphicsSceneMouseEvent *even
|
||||
/**
|
||||
@reimp QGraphicsItem::keyPressEvent
|
||||
*/
|
||||
void ElementPrimitiveDecorator::keyPressEvent(QKeyEvent *e) {
|
||||
void ElementPrimitiveDecorator::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
const qreal movement_length = 1.0;
|
||||
QPointF movement;
|
||||
switch(e -> key()) {
|
||||
|
||||
switch(e -> key())
|
||||
{
|
||||
case Qt::Key_Left: movement = QPointF(-movement_length, 0.0); break;
|
||||
case Qt::Key_Right: movement = QPointF(+movement_length, 0.0); break;
|
||||
case Qt::Key_Up: movement = QPointF(0.0, -movement_length); break;
|
||||
case Qt::Key_Down: movement = QPointF(0.0, +movement_length); break;
|
||||
}
|
||||
if (!movement.isNull() && focusItem() == this) {
|
||||
if (!moving_by_keys_) {
|
||||
if (!movement.isNull() && focusItem() == this)
|
||||
{
|
||||
if (!moving_by_keys_)
|
||||
{
|
||||
moving_by_keys_ = true;
|
||||
keys_movement_ = movement;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
keys_movement_ += movement;
|
||||
}
|
||||
foreach(QGraphicsItem *qgi, graphicsItems()) {
|
||||
|
||||
for(QGraphicsItem *qgi : graphicsItems())
|
||||
{
|
||||
qgi -> setPos(qgi -> pos() + movement);
|
||||
adjust();
|
||||
}
|
||||
|
||||
e->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsObject::keyPressEvent(e);
|
||||
@@ -276,7 +288,7 @@ void ElementPrimitiveDecorator::keyPressEvent(QKeyEvent *e) {
|
||||
*/
|
||||
void ElementPrimitiveDecorator::keyReleaseEvent(QKeyEvent *e) {
|
||||
// detecte le relachement d'une touche de direction ( = deplacement de parties)
|
||||
if (
|
||||
if(
|
||||
(e -> key() == Qt::Key_Left || e -> key() == Qt::Key_Right ||\
|
||||
e -> key() == Qt::Key_Up || e -> key() == Qt::Key_Down) &&\
|
||||
moving_by_keys_ && !e -> isAutoRepeat()
|
||||
@@ -285,6 +297,8 @@ void ElementPrimitiveDecorator::keyReleaseEvent(QKeyEvent *e) {
|
||||
emit(actionFinished(new MovePartsCommand(keys_movement_, nullptr, graphicsItems())));
|
||||
keys_movement_ = QPointF();
|
||||
moving_by_keys_ = false;
|
||||
e->accept();
|
||||
return;
|
||||
}
|
||||
QGraphicsObject::keyPressEvent(e);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "eseventinterface.h"
|
||||
#include "QetGraphicsItemModeler/qetgraphicshandleritem.h"
|
||||
#include "partdynamictextfield.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <QKeyEvent>
|
||||
@@ -177,16 +178,48 @@ void ElementScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
||||
* manage key press event
|
||||
* @param event
|
||||
*/
|
||||
void ElementScene::keyPressEvent(QKeyEvent *event) {
|
||||
if (m_event_interface) {
|
||||
if (m_event_interface -> keyPressEvent(event)) {
|
||||
if (m_event_interface->isFinish()) {
|
||||
void ElementScene::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (m_event_interface)
|
||||
{
|
||||
if (m_event_interface -> keyPressEvent(event))
|
||||
{
|
||||
if (m_event_interface->isFinish())
|
||||
{
|
||||
delete m_event_interface; m_event_interface = nullptr;
|
||||
emit(partsAdded());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(selectedItems().size() == 1)
|
||||
{
|
||||
QGraphicsObject *qgo = selectedItems().first()->toGraphicsObject();
|
||||
if(qgo)
|
||||
{
|
||||
QPointF original_pos = qgo->pos();
|
||||
QPointF p = qgo->pos();
|
||||
int k = event->key();
|
||||
if(k == Qt::Key_Right)
|
||||
p.rx() += 1;
|
||||
else if (k == Qt::Key_Left)
|
||||
p.rx() -= 1;
|
||||
else if (k == Qt::Key_Up)
|
||||
p.ry() -= 1;
|
||||
else if (k == Qt::Key_Down)
|
||||
p.ry() += 1;
|
||||
|
||||
qgo->setPos(p);
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(qgo, "pos", QVariant(original_pos), QVariant(p));
|
||||
undo->setText(tr("Déplacer une primitive"));
|
||||
undo->enableAnimation();
|
||||
undoStack().push(undo);
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QGraphicsScene::keyPressEvent(event);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user