mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
The primitive decorator now handles keyboard-driven movements.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2028 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -181,7 +181,6 @@ void ElementPrimitiveDecorator::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||
@param event Object describing the mouse event
|
||||
*/
|
||||
void ElementPrimitiveDecorator::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
qDebug() << Q_FUNC_INFO << event << zValue();
|
||||
QList<QRectF> rects = getResizingSquares();
|
||||
QPointF pos = event -> pos();
|
||||
|
||||
@@ -336,6 +335,52 @@ void ElementPrimitiveDecorator::mouseReleaseEvent(QGraphicsSceneMouseEvent *even
|
||||
current_operation_square_ = QET::NoOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
@reimp QGraphicsItem::keyPressEvent
|
||||
*/
|
||||
void ElementPrimitiveDecorator::keyPressEvent(QKeyEvent *e) {
|
||||
const qreal movement_length = 1.0;
|
||||
QPointF movement;
|
||||
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()) {
|
||||
if (!moving_by_keys_) {
|
||||
moving_by_keys_ = true;
|
||||
keys_movement_ = movement;
|
||||
} else {
|
||||
keys_movement_ += movement;
|
||||
}
|
||||
foreach(QGraphicsItem *qgi, graphicsItems()) {
|
||||
qgi -> setPos(qgi -> pos() + movement);
|
||||
adjust();
|
||||
}
|
||||
}
|
||||
|
||||
QGraphicsObject::keyPressEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
@reimp QGraphicsItem::keyReleaseEvent
|
||||
*/
|
||||
void ElementPrimitiveDecorator::keyReleaseEvent(QKeyEvent *e) {
|
||||
// detecte le relachement d'une touche de direction ( = deplacement de parties)
|
||||
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()
|
||||
) {
|
||||
// cree un objet d'annulation pour le mouvement qui vient de se finir
|
||||
emit(actionFinished(new MovePartsCommand(keys_movement_, 0, graphicsItems())));
|
||||
keys_movement_ = QPointF();
|
||||
moving_by_keys_ = false;
|
||||
}
|
||||
QGraphicsObject::keyPressEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
Initialize an ElementPrimitiveDecorator
|
||||
*/
|
||||
|
||||
@@ -47,6 +47,8 @@ class ElementPrimitiveDecorator : public QGraphicsObject {
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||
void keyPressEvent(QKeyEvent *);
|
||||
void keyReleaseEvent(QKeyEvent *);
|
||||
QPointF snapConstPointToGrid(const QPointF &) const;
|
||||
void snapPointToGrid(QPointF &) const;
|
||||
bool mustSnapToGrid(QGraphicsSceneMouseEvent *);
|
||||
@@ -85,6 +87,8 @@ class ElementPrimitiveDecorator : public QGraphicsObject {
|
||||
QPointF first_pos_; ///< First point involved within the current resizing operation
|
||||
QPointF latest_pos_; ///< Latest point involved within the current resizing operation
|
||||
QPointF mouse_offset_; ///< Offset between the mouse position and the point to be snapped to grid when moving selection
|
||||
bool moving_by_keys_; ///< Whether we are currently moving our decorated items using the arrow keys
|
||||
QPointF keys_movement_; ///< Movement applied to our decorated items using the arrow keys
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -349,58 +349,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
} else QGraphicsScene::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les enfoncements de touches du clavier
|
||||
@param e QKeyEvent decrivant l'evenement clavier
|
||||
*/
|
||||
void ElementScene::keyPressEvent(QKeyEvent *e) {
|
||||
bool is_read_only = element_editor && element_editor -> isReadOnly();
|
||||
if (!is_read_only) {
|
||||
const qreal movement_length = 1.0;
|
||||
QPointF movement;
|
||||
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()) {
|
||||
if (!moving_parts_) {
|
||||
moving_parts_ = true;
|
||||
fsi_pos = movement;
|
||||
} else {
|
||||
fsi_pos += movement;
|
||||
}
|
||||
foreach(QGraphicsItem *qgi, selectedItems()) {
|
||||
qgi -> setPos(qgi -> pos() + movement);
|
||||
}
|
||||
}
|
||||
}
|
||||
QGraphicsScene::keyPressEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les relachements de touches du clavier
|
||||
@param e QKeyEvent decrivant l'evenement clavier
|
||||
*/
|
||||
void ElementScene::keyReleaseEvent(QKeyEvent *e) {
|
||||
bool is_read_only = element_editor && element_editor -> isReadOnly();
|
||||
if (!is_read_only) {
|
||||
// detecte le relachement d'une touche de direction ( = deplacement de parties)
|
||||
if (
|
||||
(e -> key() == Qt::Key_Left || e -> key() == Qt::Key_Right ||\
|
||||
e -> key() == Qt::Key_Up || e -> key() == Qt::Key_Down) &&\
|
||||
moving_parts_ && !e -> isAutoRepeat()
|
||||
) {
|
||||
// cree un objet d'annulation pour le mouvement qui vient de se finir
|
||||
undo_stack.push(new MovePartsCommand(fsi_pos, this, selectedItems()));
|
||||
fsi_pos = QPointF();
|
||||
moving_parts_ = false;
|
||||
}
|
||||
}
|
||||
QGraphicsScene::keyReleaseEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
Dessine l'arriere-plan de l'editeur, cad la grille.
|
||||
@param p Le QPainter a utiliser pour dessiner
|
||||
|
||||
@@ -149,8 +149,6 @@ class ElementScene : public QGraphicsScene {
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||
virtual void keyPressEvent(QKeyEvent *);
|
||||
virtual void keyReleaseEvent(QKeyEvent *);
|
||||
virtual void drawBackground(QPainter *, const QRectF &);
|
||||
virtual void drawForeground(QPainter *, const QRectF &);
|
||||
virtual void endCurrentBehavior(const QGraphicsSceneMouseEvent *);
|
||||
|
||||
@@ -403,7 +403,7 @@ bool PartText::sceneEventFilter(QGraphicsItem *watched, QEvent *event) {
|
||||
else if (event -> type() == QEvent::KeyRelease || event -> type() == QEvent::KeyPress) {
|
||||
// Intercept F2 and escape keystrokes to focus in and out
|
||||
QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
|
||||
if (key_event -> key() == Qt::Key_F2) {
|
||||
if (!hasFocus() && key_event -> key() == Qt::Key_F2) {
|
||||
setEditable(true);
|
||||
QTextCursor qtc = textCursor();
|
||||
qtc.setPosition(qMax(0, document()->characterCount() - 1));
|
||||
@@ -411,8 +411,10 @@ bool PartText::sceneEventFilter(QGraphicsItem *watched, QEvent *event) {
|
||||
} else if (hasFocus() && key_event -> key() == Qt::Key_Escape) {
|
||||
endEdition();
|
||||
}
|
||||
sceneEvent(event); // manually deliver the event to this item
|
||||
return(true); // prevent this event from being delivered to any item
|
||||
if (hasFocus()) {
|
||||
sceneEvent(event); // manually deliver the event to this item
|
||||
return(true); // prevent this event from being delivered to any item
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ bool PartTextField::sceneEventFilter(QGraphicsItem *watched, QEvent *event) {
|
||||
else if (event -> type() == QEvent::KeyRelease || event -> type() == QEvent::KeyPress) {
|
||||
// Intercept F2 and escape keystrokes to focus in and out
|
||||
QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
|
||||
if (key_event -> key() == Qt::Key_F2) {
|
||||
if (!hasFocus() && key_event -> key() == Qt::Key_F2) {
|
||||
setEditable(true);
|
||||
QTextCursor qtc = textCursor();
|
||||
qtc.setPosition(qMax(0, document()->characterCount() - 1));
|
||||
@@ -193,8 +193,10 @@ bool PartTextField::sceneEventFilter(QGraphicsItem *watched, QEvent *event) {
|
||||
} else if (hasFocus() && key_event -> key() == Qt::Key_Escape) {
|
||||
endEdition();
|
||||
}
|
||||
sceneEvent(event); // manually deliver the event to this item
|
||||
return(true); // prevent this event from being delivered to any item
|
||||
if (hasFocus()) {
|
||||
sceneEvent(event); // manually deliver the event to this item
|
||||
return(true); // prevent this event from being delivered to any item
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user