[qet] [2030] ElementEditor: decorator: got rid of calls to grabKeyboard()

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2030
Author:   xavier
Date:     2013-02-08 23:05:22 +0100 (Fri, 08 Feb 2013)
Log Message:
-----------
ElementEditor: decorator: got rid of calls to grabKeyboard()

Modified Paths:
--------------
    trunk/sources/editor/elementprimitivedecorator.cpp
    trunk/sources/editor/parttext.cpp
    trunk/sources/editor/parttext.h
    trunk/sources/editor/parttextfield.cpp
    trunk/sources/editor/parttextfield.h

Modified: trunk/sources/editor/elementprimitivedecorator.cpp
===================================================================
--- trunk/sources/editor/elementprimitivedecorator.cpp	2013-02-08 22:05:20 UTC (rev 2029)
+++ trunk/sources/editor/elementprimitivedecorator.cpp	2013-02-08 22:05:22 UTC (rev 2030)
@@ -107,7 +107,9 @@
 	end_setItems:
 	adjust();
 	show();
-	grabKeyboard();
+	if (focusItem() != this) {
+		setFocus();
+	}
 }
 
 /**
@@ -347,7 +349,7 @@
 		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 @@
 	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 @@
 	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 @@
 	
 	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);

Modified: trunk/sources/editor/parttext.cpp
===================================================================
--- trunk/sources/editor/parttext.cpp	2013-02-08 22:05:20 UTC (rev 2029)
+++ trunk/sources/editor/parttext.cpp	2013-02-08 22:05:22 UTC (rev 2030)
@@ -179,6 +179,20 @@
 }
 
 /**
+	@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
 */

Modified: trunk/sources/editor/parttext.h
===================================================================
--- trunk/sources/editor/parttext.h	2013-02-08 22:05:20 UTC (rev 2029)
+++ trunk/sources/editor/parttext.h	2013-02-08 22:05:22 UTC (rev 2030)
@@ -78,6 +78,7 @@
 	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;

Modified: trunk/sources/editor/parttextfield.cpp
===================================================================
--- trunk/sources/editor/parttextfield.cpp	2013-02-08 22:05:20 UTC (rev 2029)
+++ trunk/sources/editor/parttextfield.cpp	2013-02-08 22:05:22 UTC (rev 2030)
@@ -221,6 +221,20 @@
 }
 
 /**
+	@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
 */

Modified: trunk/sources/editor/parttextfield.h
===================================================================
--- trunk/sources/editor/parttextfield.h	2013-02-08 22:05:20 UTC (rev 2029)
+++ trunk/sources/editor/parttextfield.h	2013-02-08 22:05:22 UTC (rev 2030)
@@ -84,6 +84,7 @@
 	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;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/