Skip to content

Commit

Permalink
Merge pull request #400 from vtexier/dev0121
Browse files Browse the repository at this point in the history
refs #392 redisplay expiration date on certification arrow in Wot and…
  • Loading branch information
Insoleet committed Apr 11, 2016
2 parents 6324007 + 1822dc5 commit 662c7e2
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 8 deletions.
34 changes: 33 additions & 1 deletion src/sakia/gui/views/edges/explorer_edge.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
34 changes: 33 additions & 1 deletion src/sakia/gui/views/edges/wot_edge.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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
9 changes: 6 additions & 3 deletions src/sakia/tests/unit/gui/views/test_explorer_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
9 changes: 6 additions & 3 deletions src/sakia/tests/unit/gui/views/test_wot_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 662c7e2

Please sign in to comment.