Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] canvas/annotationitem: Use separate item for shadow base #2821

Merged
merged 1 commit into from
Dec 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions Orange/canvas/canvas/items/annotationitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
QGraphicsDropShadowEffect, QMenu, QAction, QActionGroup
)
from AnyQt.QtGui import (
QPainterPath, QPainterPathStroker, QPolygonF, QColor, QPen
QPainterPath, QPainterPathStroker, QPolygonF, QColor, QPen, QBrush
)
from AnyQt.QtCore import (
Qt, QPointF, QSizeF, QRectF, QLineF, QEvent, QMetaObject, QT_VERSION
Expand Down Expand Up @@ -699,22 +699,32 @@ def __init__(self, parent=None, line=None, **kwargs):
if line is None:
line = QLineF(0, 0, 20, 0)

self.__line = line
self.__line = QLineF(line)
self.__color = QColor(Qt.red)
self.__arrowItem = ArrowItem(self)
self.__arrowItem.setLine(line)
self.__arrowItem.setBrush(self.__color)
self.__arrowItem.setPen(QPen(Qt.NoPen))
self.__arrowItem.setArrowStyle(ArrowItem.Concave)
self.__arrowItem.setLineWidth(5)
# An item with the same shape as this arrow, stacked behind this
# item as a source for QGraphicsDropShadowEffect. Cannot attach
# the effect to this item directly as QGraphicsEffect makes the item
# non devicePixelRatio aware.
self.__arrowShadowBase = ArrowItem(self, line=line)
self.__arrowShadowBase.setPen(Qt.NoPen) # no pen -> slightly thinner
self.__arrowShadowBase.setBrush(QBrush(self.__color))
self.__arrowShadowBase.setArrowStyle(ArrowItem.Concave)
self.__arrowShadowBase.setLineWidth(5)

self.__shadow = QGraphicsDropShadowEffect(
blurRadius=5, offset=QPointF(1.0, 2.0),
)

self.__arrowItem.setGraphicsEffect(self.__shadow)
self.__arrowShadowBase.setGraphicsEffect(self.__shadow)
self.__shadow.setEnabled(True)

# The 'real' shape item
self.__arrowItem = ArrowItem(self, line=line)
self.__arrowItem.setBrush(self.__color)
self.__arrowItem.setPen(QPen(self.__color))
self.__arrowItem.setArrowStyle(ArrowItem.Concave)
self.__arrowItem.setLineWidth(5)

self.__autoAdjustGeometry = True

def setAutoAdjustGeometry(self, autoAdjust):
Expand Down Expand Up @@ -742,7 +752,7 @@ def setLine(self, line):
Set the arrow base line (a `QLineF` in object coordinates).
"""
if self.__line != line:
self.__line = line
self.__line = QLineF(line)

# local item coordinate system
geom = self.geometry().translated(-self.pos())
Expand All @@ -764,6 +774,7 @@ def setLine(self, line):
diff = geom.topLeft()
line = QLineF(line.p1() - diff, line.p2() - diff)
self.__arrowItem.setLine(line)
self.__arrowShadowBase.setLine(line)
self.__line = line

# parent item coordinate system
Expand Down Expand Up @@ -795,6 +806,7 @@ def setLineWidth(self, lineWidth):
Set the arrow line width.
"""
self.__arrowItem.setLineWidth(lineWidth)
self.__arrowShadowBase.setLineWidth(lineWidth)

def lineWidth(self):
"""
Expand Down Expand Up @@ -846,11 +858,14 @@ def __updateStyleState(self):
pen = QPen(QColor(96, 158, 215), Qt.DashDotLine)
pen.setWidthF(1.25)
pen.setCosmetic(True)
self.__shadow.setColor(pen.color().darker(150))
shadow = pen.color().darker(150)
else:
color = self.__color
pen = QPen(Qt.NoPen)
self.__shadow.setColor(QColor(63, 63, 63, 180))
pen = QPen(color)
shadow = QColor(63, 63, 63, 180)

self.__arrowShadowBase.setBrush(color)
self.__shadow.setColor(shadow)

self.__arrowItem.setBrush(color)
self.__arrowItem.setPen(pen)