[qet] [3339] DVEventAddShape : add a cross for help drawing |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3339
Author: blacksun
Date: 2014-09-28 13:42:08 +0200 (Sun, 28 Sep 2014)
Log Message:
-----------
DVEventAddShape : add a cross for help drawing
Modified Paths:
--------------
trunk/sources/dvevent/dveventaddshape.cpp
trunk/sources/dvevent/dveventaddshape.h
Modified: trunk/sources/dvevent/dveventaddshape.cpp
===================================================================
--- trunk/sources/dvevent/dveventaddshape.cpp 2014-09-28 09:47:06 UTC (rev 3338)
+++ trunk/sources/dvevent/dveventaddshape.cpp 2014-09-28 11:42:08 UTC (rev 3339)
@@ -31,7 +31,9 @@
DVEventAddShape::DVEventAddShape(DiagramView *dv, QetShapeItem::ShapeType shape_type) :
DVEventInterface(dv),
m_shape_type (shape_type),
- m_shape_item (nullptr)
+ m_shape_item (nullptr),
+ m_help_horiz (nullptr),
+ m_help_verti (nullptr)
{}
/**
@@ -42,6 +44,8 @@
m_diagram -> removeItem(m_shape_item);
delete m_shape_item;
}
+ delete m_help_horiz;
+ delete m_help_verti;
m_dv -> setContextMenuPolicy(Qt::DefaultContextMenu);
}
@@ -104,6 +108,7 @@
* @return : true if this event is managed, otherwise false
*/
bool DVEventAddShape::mouseMoveEvent(QMouseEvent *event) {
+ updateHelpCross(event->pos());
if (!m_running) return false;
if (m_shape_item && event -> buttons() == Qt::NoButton) {
m_shape_item -> setP2 (m_dv -> mapToScene (event -> pos()));
@@ -128,3 +133,35 @@
}
return false;
}
+
+/**
+ * @brief DVEventAddShape::updateHelpCross
+ * Create and update the position of the cross to help user for draw new shape
+ * @param event
+ */
+void DVEventAddShape::updateHelpCross(const QPoint &p) {
+ //If line isn't created yet, we create it.
+ if (!m_help_horiz || !m_help_verti) {
+ QPen pen;
+ pen.setColor(Qt::yellow);
+ //Add +5 for each line, because the topleft of diagram isn't draw at position (0:0) but (5:5)
+ if (!m_help_horiz) {
+ m_help_horiz = new QGraphicsLineItem(m_diagram -> border_and_titleblock.rowsHeaderWidth() + 5, 0,
+ m_diagram -> border_and_titleblock.diagramWidth() + 5, 0,
+ 0, m_diagram);
+ m_help_horiz->setPen(pen);
+ }
+ if (!m_help_verti) {
+ m_help_verti = new QGraphicsLineItem(0, m_diagram -> border_and_titleblock.columnsHeaderHeight() + 5,
+ 0, m_diagram -> border_and_titleblock.diagramHeight() + 5,
+ 0, m_diagram);
+ m_help_verti->setPen(pen);
+ }
+ }
+
+ //Update the position of the cross
+ QPointF point = Diagram::snapToGrid(m_dv->mapToScene(p));
+
+ m_help_horiz->setY(point.y());
+ m_help_verti->setX(point.x());
+}
Modified: trunk/sources/dvevent/dveventaddshape.h
===================================================================
--- trunk/sources/dvevent/dveventaddshape.h 2014-09-28 09:47:06 UTC (rev 3338)
+++ trunk/sources/dvevent/dveventaddshape.h 2014-09-28 11:42:08 UTC (rev 3339)
@@ -32,9 +32,13 @@
virtual bool mouseMoveEvent (QMouseEvent *event);
virtual bool mouseReleaseEvent (QMouseEvent *event);
+ private:
+ void updateHelpCross (const QPoint &p);
+
protected:
QetShapeItem::ShapeType m_shape_type;
QetShapeItem *m_shape_item;
+ QGraphicsLineItem *m_help_horiz, *m_help_verti;
};
#endif // DVEVENTADDSHAPE_H