From 47f9c5ebe6fef59d303c56da3de0910b600b1a05 Mon Sep 17 00:00:00 2001 From: xavier Date: Fri, 8 Feb 2013 22:05:22 +0000 Subject: [PATCH] ElementEditor: decorator: got rid of calls to grabKeyboard() git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2030 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/editor/elementprimitivedecorator.cpp | 11 +++++------ sources/editor/parttext.cpp | 14 ++++++++++++++ sources/editor/parttext.h | 1 + sources/editor/parttextfield.cpp | 14 ++++++++++++++ sources/editor/parttextfield.h | 1 + 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/sources/editor/elementprimitivedecorator.cpp b/sources/editor/elementprimitivedecorator.cpp index 4a9967c69..18a53e47f 100644 --- a/sources/editor/elementprimitivedecorator.cpp +++ b/sources/editor/elementprimitivedecorator.cpp @@ -107,7 +107,9 @@ void ElementPrimitiveDecorator::setItems(const QList &items end_setItems: adjust(); show(); - grabKeyboard(); + if (focusItem() != this) { + setFocus(); + } } /** @@ -347,7 +349,7 @@ void ElementPrimitiveDecorator::keyPressEvent(QKeyEvent *e) { 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 (!movement.isNull() && focusItem() == this) { if (!moving_by_keys_) { moving_by_keys_ = true; keys_movement_ = movement; @@ -385,7 +387,7 @@ void ElementPrimitiveDecorator::keyReleaseEvent(QKeyEvent *e) { Initialize an ElementPrimitiveDecorator */ void ElementPrimitiveDecorator::init() { - //setAcceptedMouseButtons(Qt::LeftButton); + setFlag(QGraphicsItem::ItemIsFocusable, true); grid_step_x_ = grid_step_y_ = 1; setAcceptHoverEvents(true); } @@ -414,7 +416,6 @@ void ElementPrimitiveDecorator::startMovement() { adjust(); foreach(CustomElementPart *item, decorated_items_) { - qDebug() << Q_FUNC_INFO << "starting movement with rect" << original_bounding_rect_ << "i.e. in scene coordinates " << mapToScene(original_bounding_rect_).boundingRect(); item -> startUserTransformation(mapToScene(original_bounding_rect_).boundingRect()); } } @@ -497,8 +498,6 @@ void ElementPrimitiveDecorator::scaleItems(const QRectF &original_rect, const QR QRectF scene_original_rect = mapToScene(original_rect).boundingRect(); QRectF scene_new_rect = mapToScene(new_rect).boundingRect(); - qDebug() << Q_FUNC_INFO << "from " << original_rect << " to " << new_rect; - qDebug() << Q_FUNC_INFO << "from " << scene_original_rect << " to " << scene_new_rect << "(scene coordinates)"; foreach(CustomElementPart *item, decorated_items_) { item -> handleUserTransformation(scene_original_rect, scene_new_rect); diff --git a/sources/editor/parttext.cpp b/sources/editor/parttext.cpp index 9ed25e351..28437dba0 100644 --- a/sources/editor/parttext.cpp +++ b/sources/editor/parttext.cpp @@ -178,6 +178,20 @@ void PartText::focusOutEvent(QFocusEvent *e) { endEdition(); } +/** + @reimp QGraphicsTextItem::keyPressEvent() + Used to handle the escape key when the event is delivered to the field, not + to the decorator. +*/ +void PartText::keyPressEvent(QKeyEvent *event) { + if (event -> key() == Qt::Key_Escape) { + endEdition(); + } + else { + QGraphicsTextItem::keyPressEvent(event); + } +} + /** Permet a l'element texte de devenir editable lorsqu'on double-clique dessus @param e Le QGraphicsSceneMouseEvent qui decrit le double-clic diff --git a/sources/editor/parttext.h b/sources/editor/parttext.h index caf095a8f..5f0ef85fb 100644 --- a/sources/editor/parttext.h +++ b/sources/editor/parttext.h @@ -78,6 +78,7 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { virtual bool sceneEventFilter(QGraphicsItem *, QEvent *); virtual void focusInEvent(QFocusEvent *); virtual void focusOutEvent(QFocusEvent *); + virtual void keyPressEvent(QKeyEvent *); virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *); virtual QVariant itemChange(GraphicsItemChange, const QVariant &); QRectF boundingRect() const; diff --git a/sources/editor/parttextfield.cpp b/sources/editor/parttextfield.cpp index fb9eb604c..32471c203 100644 --- a/sources/editor/parttextfield.cpp +++ b/sources/editor/parttextfield.cpp @@ -220,6 +220,20 @@ void PartTextField::focusOutEvent(QFocusEvent *e) { endEdition(); } +/** + @reimp QGraphicsTextItem::keyPressEvent() + Used to handle the escape key when the event is delivered to the field, not + to the decorator. +*/ +void PartTextField::keyPressEvent(QKeyEvent *event) { + if (event -> key() == Qt::Key_Escape) { + endEdition(); + } + else { + QGraphicsTextItem::keyPressEvent(event); + } +} + /** Permet a l'element texte de devenir editable lorsqu'on double-clique dessus @param e Le QGraphicsSceneMouseEvent qui decrit le double-clic diff --git a/sources/editor/parttextfield.h b/sources/editor/parttextfield.h index c219aab62..108a40ea5 100644 --- a/sources/editor/parttextfield.h +++ b/sources/editor/parttextfield.h @@ -84,6 +84,7 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart { virtual bool sceneEventFilter(QGraphicsItem *, QEvent *); virtual void focusInEvent(QFocusEvent *); virtual void focusOutEvent(QFocusEvent *); + virtual void keyPressEvent(QKeyEvent *); virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *); virtual QVariant itemChange(GraphicsItemChange, const QVariant &); QRectF boundingRect() const;