[qet] [4613] Fix Home and End Buttons Handling and DiagramEditor Scroll

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


Revision: 4613
Author:   dfochi
Date:     2016-08-08 18:42:47 +0200 (Mon, 08 Aug 2016)
Log Message:
-----------
Fix Home and End Buttons Handling and DiagramEditor Scroll

Modified Paths:
--------------
    trunk/sources/diagram.cpp
    trunk/sources/diagramview.cpp
    trunk/sources/diagramview.h

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2016-08-08 16:17:50 UTC (rev 4612)
+++ trunk/sources/diagram.cpp	2016-08-08 16:42:47 UTC (rev 4613)
@@ -244,27 +244,27 @@
 		QPointF movement;
 		qreal top_position = 0;
 		qreal left_position = 0;
-		QList<Element*> selected_elmts = this->selectedContent().elements.toList();
-	if (!this->selectedContent().elements.isEmpty()) {
+		QList<QGraphicsItem*> selected_elmts = this->selectedContent().items();
+		if (!this->selectedContent().items(255).isEmpty()) {
 		switch(e -> key()) {
 			case Qt::Key_Left:
 				foreach (QGraphicsItem *item, selected_elmts) {
 					left_position = item->mapRectFromScene(item->boundingRect()).x();
 					if (left_position >= this->sceneRect().left() - item->boundingRect().width())
 					return;
-			}
+				}
 				movement = QPointF(-xGrid, 0.0);
 				break;
 			case Qt::Key_Right: movement = QPointF(+xGrid, 0.0); break;
 			case Qt::Key_Up:
 				foreach (QGraphicsItem *item, selected_elmts) {
 					top_position = item->mapRectFromScene(item->boundingRect()).y();
-						if (top_position >= this->sceneRect().top() - item->boundingRect().height())
+					if (top_position >= this->sceneRect().top() - item->boundingRect().height())
 						return;
 				}
 				movement = QPointF(0.0, -yGrid);
 				break;
-			case Qt::Key_Down:  movement = QPointF(0.0, +yGrid); break;
+			case Qt::Key_Down: movement = QPointF(0.0, +yGrid); break;
 		}
 		if (!movement.isNull() && !focusItem()) {
 			beginMoveElements();

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2016-08-08 16:17:50 UTC (rev 4612)
+++ trunk/sources/diagramview.cpp	2016-08-08 16:42:47 UTC (rev 4613)
@@ -604,11 +604,31 @@
 			current_project->changeTabDown();
 			return;
 		case Qt::Key_Home:
-			current_project->changeFirstTab();
-			return;
+			if (!hasTextItems()) {
+				if (
+					qgraphicsitem_cast<IndependentTextItem *>(scene->focusItem()) ||
+					qgraphicsitem_cast<ElementTextItem *>(scene->focusItem()) ||
+					qgraphicsitem_cast<ConductorTextItem *>(scene->focusItem()) ||
+					qgraphicsitem_cast<DiagramTextItem *>(scene->focusItem())
+					)
+					break;
+				current_project->changeFirstTab();
+				return;
+			}
+			else break;
 		case Qt::Key_End:
-			current_project->changeLastTab();
-			return;
+			if (!hasTextItems()) {
+				if (
+					qgraphicsitem_cast<IndependentTextItem *>(scene->focusItem()) ||
+					qgraphicsitem_cast<ElementTextItem *>(scene->focusItem()) ||
+					qgraphicsitem_cast<ConductorTextItem *>(scene->focusItem()) ||
+					qgraphicsitem_cast<DiagramTextItem *>(scene->focusItem())
+					)
+					break;
+				current_project->changeLastTab();
+				return;
+			}
+			else break;
 		case Qt::Key_ZoomOut:
 			zoom(0.85);
 			return;
@@ -622,19 +642,19 @@
 			if (e->modifiers() & Qt::ControlModifier)
 				zoom(1.15);
 		case Qt::Key_Up:
-			if(!scene->selectedContent().elements.isEmpty()){
+			if(!(scene->selectedContent().items(255).isEmpty())){
 				scrollOnMovement(e);
 			}
 		case Qt::Key_Down:
-			if(!scene->selectedContent().elements.isEmpty()){
+			if(!(scene->selectedContent().items(255).isEmpty())){
 				scrollOnMovement(e);
 			}
 		case Qt::Key_Left:
-			if(!scene->selectedContent().elements.isEmpty()){
+			if(!(scene->selectedContent().items(255).isEmpty())){
 				scrollOnMovement(e);
 			}
 		case Qt::Key_Right:
-			if(!scene->selectedContent().elements.isEmpty()){
+			if(!(scene->selectedContent().items(255).isEmpty())){
 				scrollOnMovement(e);
 			}
 	}
@@ -659,7 +679,7 @@
 	or below the editor SceneRect is expanded
 */
 void DiagramView::scrollOnMovement(QKeyEvent *e){
-			QList<QGraphicsItem *> selected_elmts = scene ->selectedItems();
+			QList<QGraphicsItem *> selected_elmts = scene->selectedContent().items(255);
 			QRectF viewed_scene = viewedSceneRect();
 			foreach (QGraphicsItem *qgi, selected_elmts){
 				qreal x = qgi->pos().x();
@@ -682,15 +702,21 @@
 						QScrollBar *v = verticalScrollBar();
 						int h_increment=0;
 						int v_increment=0;
-						if (e->key()==Qt::Key_Up && elmt_above_bottom_margin)
+						if (e->key()==Qt::Key_Up && elmt_above_bottom_margin) {
 							v_increment = 2*qgi->boundingRect().top();
-						else if(e->key()==Qt::Key_Down && elmt_below_top_margin){
+							if (v_increment == 0) v_increment = -2*qgi->boundingRect().height();
+						}
+						else if(e->key()==Qt::Key_Down && elmt_below_top_margin) {
 							v_increment = 2*qgi->boundingRect().bottom();
+							if (v_increment == 0) v_increment = -2*qgi->boundingRect().height();
 						}
-						else if (e->key()==Qt::Key_Left && elmt_left_of_right_margin)
+						else if (e->key()==Qt::Key_Left && elmt_left_of_right_margin) {
 							h_increment = 2*qgi->boundingRect().left();
-						else if (e->key()==Qt::Key_Right && elmt_right_of_left_margin){
+							if (h_increment == 0) h_increment = -2*qgi->boundingRect().width();
+						}
+						else if (e->key()==Qt::Key_Right && elmt_right_of_left_margin) {
 							h_increment = 2*qgi->boundingRect().right();
+							if (h_increment == 0) h_increment = -2*qgi->boundingRect().width();
 						}
 						if (((elmt_right  >= scene->sceneRect().right() -  qgi->boundingRect().right())  ||
 							(elmt_bottom >= scene->sceneRect().bottom() - qgi->boundingRect().bottom())) &&
@@ -755,6 +781,23 @@
 }
 
 /**
+	@return true if there is any Text Item selected
+*/
+bool DiagramView::hasTextItems() {
+	foreach(QGraphicsItem *qgi, scene -> selectedItems()) {
+		if (
+			qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
+			qgraphicsitem_cast<ElementTextItem *>(qgi) ||
+			qgraphicsitem_cast<ConductorTextItem *>(qgi) ||
+			qgraphicsitem_cast<DiagramTextItem *>(qgi)
+		) {
+			return(true);
+		}
+	}
+	return(false);
+}
+
+/**
 	@return true s'il y a des items selectionnes sur le schema et que ceux-ci
 	peuvent etre supprimes, false sinon
 */

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2016-08-08 16:17:50 UTC (rev 4612)
+++ trunk/sources/diagramview.h	2016-08-08 16:42:47 UTC (rev 4613)
@@ -72,6 +72,7 @@
 	QETDiagramEditor *diagramEditor() const;
 	bool hasSelectedItems();
 	bool hasCopiableItems();
+	bool hasTextItems();
 	bool hasDeletableItems();
 	void editSelection();
 	void setEventInterface (DVEventInterface *event_interface);


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