From 71aa20bd7d51165c46c129cbeab6ca332a01ec40 Mon Sep 17 00:00:00 2001 From: Vincent Texier Date: Sat, 9 Apr 2016 12:10:57 +0200 Subject: [PATCH 1/2] refs #392 redisplay expiration date on certification arrow in Wot and Explorer --- src/sakia/gui/views/edges/explorer_edge.py | 34 +++++++++++++++++++++- src/sakia/gui/views/edges/wot_edge.py | 34 +++++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/sakia/gui/views/edges/explorer_edge.py b/src/sakia/gui/views/edges/explorer_edge.py index 6f39bea9..61678607 100644 --- a/src/sakia/gui/views/edges/explorer_edge.py +++ b/src/sakia/gui/views/edges/explorer_edge.py @@ -1,6 +1,6 @@ from PyQt5.QtCore import Qt, QRectF, QLineF, QPointF, QSizeF, \ qFuzzyCompare, QTimeLine -from PyQt5.QtGui import QColor, QPen, QPolygonF +from PyQt5.QtGui import QColor, QPen, QPolygonF, QPainterPath, QBrush import math from .base_edge import BaseEdge from ....core.graph.constants import EdgeStatus @@ -34,6 +34,7 @@ def __init__(self, source_node, destination_node, metadata, nx_pos, steps, steps EdgeStatus.WEAK: Qt.DashLine } self.timeline = None + self.setToolTip(self.metadata['tooltip']) @property def line_style(self): @@ -101,6 +102,9 @@ def paint(self, painter, option, widget): hpy = line.p1().y() + (line.dy() / 2.0) head_point = QPointF(hpx, hpy) + # debug : display shape for tooltip triggering zone + #painter.fillPath(self.shape(), QBrush(QColor(0, 255, 0, 255))) + painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) destination_arrow_p1 = head_point + QPointF( math.sin(angle - math.pi / 3) * self.arrow_size, @@ -152,3 +156,31 @@ def neutralize(self): """ self.highlighted = False self.update(self.boundingRect()) + + def shape(self): + """ + Return real shape of the item to detect collision or hover accurately + + :return: QPainterPath + """ + if not self.source or not self.destination: + return + line = QLineF(self.source_point, self.destination_point) + + # detection mouse hover on arc path + path = QPainterPath() + path.addPolygon(QPolygonF([line.p1(), line.p2()])) + + # arrow in the middle of the arc + hpx = line.p1().x() + (line.dx() / 2.0) + hpy = line.p1().y() + (line.dy() / 2.0) + + # add detection zone around the arrow head + path.addRect(QRectF( + hpx-10, + hpy-10, + 20, + 20 + )) + + return path diff --git a/src/sakia/gui/views/edges/wot_edge.py b/src/sakia/gui/views/edges/wot_edge.py index 50fcf150..5a8e04eb 100644 --- a/src/sakia/gui/views/edges/wot_edge.py +++ b/src/sakia/gui/views/edges/wot_edge.py @@ -1,6 +1,6 @@ from PyQt5.QtCore import Qt, QRectF, QLineF, QPointF, QSizeF, \ qFuzzyCompare -from PyQt5.QtGui import QColor, QPen, QPolygonF +from PyQt5.QtGui import QColor, QPen, QPolygonF, QPainterPath, QBrush import math from .base_edge import BaseEdge from ....core.graph.constants import EdgeStatus @@ -29,6 +29,7 @@ def __init__(self, source_node, destination_node, metadata, pos): EdgeStatus.STRONG: Qt.SolidLine, EdgeStatus.WEAK: Qt.DashLine } + self.setToolTip(self.metadata['tooltip']) @property def color_name(self): @@ -95,6 +96,9 @@ def paint(self, painter, option, widget): hpy = line.p1().y() + (line.dy() / 2.0) head_point = QPointF(hpx, hpy) + # debug : display shape for tooltip triggering zone + #painter.fillPath(self.shape(), QBrush(QColor(0, 255, 0, 255))) + painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) destination_arrow_p1 = head_point + QPointF( math.sin(angle - math.pi / 3) * self.arrow_size, @@ -108,3 +112,31 @@ def paint(self, painter, option, widget): if self.metadata["confirmation_text"]: painter.drawText(head_point, self.metadata["confirmation_text"]) + + def shape(self): + """ + Return real shape of the item to detect collision or hover accurately + + :return: QPainterPath + """ + if not self.source or not self.destination: + return + line = QLineF(self.source_point, self.destination_point) + + # detection mouse hover on arc path + path = QPainterPath() + path.addPolygon(QPolygonF([line.p1(), line.p2()])) + + # arrow in the middle of the arc + hpx = line.p1().x() + (line.dx() / 2.0) + hpy = line.p1().y() + (line.dy() / 2.0) + + # add detection zone around the arrow head + path.addRect(QRectF( + hpx-10, + hpy-10, + 20, + 20 + )) + + return path From 1822dc5e4eb5a4d12df6e5f1595b4f0cd13c7984 Mon Sep 17 00:00:00 2001 From: Vincent Texier Date: Sun, 10 Apr 2016 09:41:50 +0200 Subject: [PATCH 2/2] refs #392 fix tests --- src/sakia/tests/unit/gui/views/test_explorer_edge.py | 9 ++++++--- src/sakia/tests/unit/gui/views/test_wot_edge.py | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/sakia/tests/unit/gui/views/test_explorer_edge.py b/src/sakia/tests/unit/gui/views/test_explorer_edge.py index 5732190c..e74029db 100644 --- a/src/sakia/tests/unit/gui/views/test_explorer_edge.py +++ b/src/sakia/tests/unit/gui/views/test_explorer_edge.py @@ -17,7 +17,8 @@ def tearDown(self): def test_create_wot_edge(self): metadata = { 'status': EdgeStatus.STRONG, - 'confirmation_text': "0/6" + 'confirmation_text': "0/6", + 'tooltip': "17/04/2016" } nx_pos = { "A": (0, 5), @@ -40,7 +41,8 @@ async def exec_test(): def test_paint(self, painter, widget): metadata = { 'status': EdgeStatus.STRONG, - 'confirmation_text': "0/6" + 'confirmation_text': "0/6", + 'tooltip': "17/04/2016" } nx_pos = { "A": (0, 5), @@ -58,7 +60,8 @@ async def exec_test(): def test_bounding_rect(self, painter, widget): metadata = { 'status': EdgeStatus.STRONG, - 'confirmation_text': "0/6" + 'confirmation_text': "0/6", + 'tooltip': "17/04/2016" } nx_pos = { "A": (0, 5), diff --git a/src/sakia/tests/unit/gui/views/test_wot_edge.py b/src/sakia/tests/unit/gui/views/test_wot_edge.py index 6c0632b9..794fbc8e 100644 --- a/src/sakia/tests/unit/gui/views/test_wot_edge.py +++ b/src/sakia/tests/unit/gui/views/test_wot_edge.py @@ -17,7 +17,8 @@ def tearDown(self): def test_create_wot_edge(self): metadata = { 'status': EdgeStatus.STRONG, - 'confirmation_text': "0/6" + 'confirmation_text': "0/6", + 'tooltip': "17/04/2016" } nx_pos = { "A": (0, 5), @@ -40,7 +41,8 @@ async def exec_test(): def test_paint(self, painter, widget): metadata = { 'status': EdgeStatus.STRONG, - 'confirmation_text': "0/6" + 'confirmation_text': "0/6", + 'tooltip': "17/04/2016" } nx_pos = { "A": (0, 5), @@ -58,7 +60,8 @@ async def exec_test(): def test_bounding_rect(self, painter, widget): metadata = { 'status': EdgeStatus.STRONG, - 'confirmation_text': "0/6" + 'confirmation_text': "0/6", + 'tooltip': "17/04/2016" } nx_pos = { "A": (0, 5),