[qet] [4080] Qet shape item : Change the cursor shape, according to the current available behavior

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


Revision: 4080
Author:   blacksun
Date:     2015-07-29 11:25:41 +0200 (Wed, 29 Jul 2015)
Log Message:
-----------
Qet shape item : Change the cursor shape, according to the current available behavior

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/qetshapeitem.cpp
    trunk/sources/qetgraphicsitem/qetshapeitem.h

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2015-07-28 18:35:52 UTC (rev 4079)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2015-07-29 09:25:41 UTC (rev 4080)
@@ -193,7 +193,7 @@
 						path.lineTo(m_P2);                   break;
 		case Rectangle: path.addRect(QRectF(m_P1, m_P2));    break;
 		case Ellipse:   path.addEllipse(QRectF(m_P1, m_P2)); break;
-		case Polygon:  path.addPolygon(m_polygon);          break;
+		case Polygon:   path.addPolygon(m_polygon);          break;
 		default:        Q_ASSERT(false);                     break;
 	}
 
@@ -276,7 +276,7 @@
 			break;
 
 		case Polygon:
-			painter->drawPolygon(m_polygon);
+			painter->drawPolyline(m_polygon);
 			if (isSelected())
 				m_handler.drawHandler(painter, m_polygon);
 			break;
@@ -293,6 +293,36 @@
 	QetGraphicsItem::hoverEnterEvent(event);
 }
 
+void QetShapeItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
+{
+	QVector <QPointF> vector;
+	switch (m_shapeType)
+	{
+		case Line:      vector << m_P1 << m_P2;                               break;
+		case Rectangle: vector = m_handler.pointsForRect(QRectF(m_P1, m_P2)); break;
+		case Ellipse:   vector = m_handler.pointsForRect(QRectF(m_P1, m_P2)); break;
+		case Polygon:   vector = m_polygon;                                   break;
+	}
+
+	int handler = m_handler.pointIsHoverHandler(event->pos(), vector);
+	if (isSelected() &&  handler >= 0)
+	{
+		if (m_shapeType & (Line | Polygon)) {
+			setCursor(Qt::SizeAllCursor);
+			return;
+		}
+
+		if (handler == 0 || handler == 2 || handler == 5 || handler == 7)
+			setCursor(Qt::SizeAllCursor);
+		else if (handler == 1 || handler == 6)
+			setCursor(Qt::SizeVerCursor);
+		else if (handler == 3 || handler == 4)
+			setCursor(Qt::SizeHorCursor);
+	}
+	else
+		setCursor(Qt::OpenHandCursor);
+}
+
 /**
  * @brief QetShapeItem::hoverLeaveEvent
  * Handle hover leave event
@@ -300,6 +330,7 @@
  */
 void QetShapeItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
 	m_hovered = false;
+	setCursor(Qt::ArrowCursor);
 	QetGraphicsItem::hoverLeaveEvent(event);
 }
 
@@ -310,6 +341,7 @@
  */
 void QetShapeItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
+	setCursor(Qt::ClosedHandCursor);
 		//Shape is selected, we see if user click in a handler
 	if (isSelected())
 	{
@@ -404,6 +436,7 @@
 				diagram()->undoStack().push(undo);
 			}
 		}
+		setCursor(Qt::OpenHandCursor);
 	}
 
 	QetGraphicsItem::mouseReleaseEvent(event);

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.h	2015-07-28 18:35:52 UTC (rev 4079)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.h	2015-07-29 09:25:41 UTC (rev 4080)
@@ -86,6 +86,7 @@
 	protected:
 		virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
 		virtual void hoverEnterEvent   (QGraphicsSceneHoverEvent *event);
+		virtual void hoverMoveEvent    (QGraphicsSceneHoverEvent *event);
 		virtual void hoverLeaveEvent   (QGraphicsSceneHoverEvent *event);
 		virtual void mousePressEvent   (QGraphicsSceneMouseEvent *event);
 		virtual void mouseMoveEvent    (QGraphicsSceneMouseEvent *event);


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