Skip to content

Commit

Permalink
canvas: Style dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
irgolic committed Feb 20, 2021
1 parent 42c6d6b commit bff9b98
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 116 deletions.
2 changes: 1 addition & 1 deletion orangecanvas/canvas/items/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from .nodeitem import NodeItem, NodeAnchorItem, NodeBodyItem, SHADOW_COLOR
from .nodeitem import NodeItem, NodeAnchorItem, NodeBodyItem, DEFAULT_SHADOW_COLOR
from .nodeitem import SourceAnchorItem, SinkAnchorItem, AnchorPoint
from .linkitem import LinkItem, LinkCurveItem
from .annotationitem import TextAnnotation, ArrowAnnotation
14 changes: 7 additions & 7 deletions orangecanvas/canvas/items/graphicstextitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
QGraphicsTextItem, QStyleOptionGraphicsItem, QStyle, QWidget, QApplication,
)

from orangecanvas.gui.utils import foreground_for_background
from orangecanvas.utils import set_flag


Expand Down Expand Up @@ -54,11 +55,7 @@ def paint(self, painter, option, widget=None):
if not window.isActiveWindow():
cg = QPalette.Inactive

color = palette.color(
cg,
QPalette.Highlight if state & QStyle.State_Selected
else QPalette.Light
)
color = palette.color(cg, QPalette.Light)

painter.save()
painter.setPen(QPen(Qt.NoPen))
Expand Down Expand Up @@ -103,10 +100,13 @@ def palette(self):
def __updateDefaultTextColor(self):
# type: () -> None
if self.__styleState & QStyle.State_Selected:
role = QPalette.HighlightedText
bgRole = QPalette.Light
bgColor = self.palette().color(bgRole)
color = foreground_for_background(bgColor)
else:
role = QPalette.WindowText
self.setDefaultTextColor(self.palette().color(role))
color = self.palette().color(role)
self.setDefaultTextColor(color)

def setHtml(self, contents):
# type: (str) -> None
Expand Down
49 changes: 34 additions & 15 deletions orangecanvas/canvas/items/linkitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
from AnyQt.QtWidgets import (
QGraphicsItem, QGraphicsPathItem, QGraphicsWidget,
QGraphicsDropShadowEffect, QGraphicsSceneHoverEvent, QStyle,
QGraphicsSceneMouseEvent
)
QGraphicsSceneMouseEvent,
QApplication)
from AnyQt.QtGui import (
QPen, QBrush, QColor, QPainterPath, QTransform, QPalette,
)
from AnyQt.QtCore import Qt, QPointF, QRectF, QLineF, QEvent, QPropertyAnimation, Signal, QTimer

from .nodeitem import AnchorPoint, SHADOW_COLOR
from .nodeitem import AnchorPoint, DEFAULT_SHADOW_COLOR
from .graphicstextitem import GraphicsTextItem
from .utils import stroke_path
from ...registry import InputSignal, OutputSignal
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, parent):
self.setPen(QPen(QBrush(QColor("#9CACB4")), 2.0))

self.shadow = QGraphicsDropShadowEffect(
blurRadius=5, color=QColor(SHADOW_COLOR),
blurRadius=5, color=QColor(DEFAULT_SHADOW_COLOR),
offset=QPointF(0, 0)
)
self.setGraphicsEffect(self.shadow)
Expand Down Expand Up @@ -809,27 +809,46 @@ def __updatePen(self):
# type: () -> None
self.prepareGeometryChange()
self.__boundingRect = None
if self.__dynamic:
if self.__dynamicEnabled:
color = QColor(0, 150, 0, 150)
else:
color = QColor(150, 0, 0, 150)

normal = QPen(QBrush(color), 2.0)
hover = QPen(QBrush(color.darker(120)), 2.0)
else:
normal = QPen(QBrush(QColor("#9CACB4")), 2.0)
hover = QPen(QBrush(QColor("#959595")), 2.0)
app = QApplication.instance()
darkMode = app.property('darkMode')

if self.__dynamic:
# TODO
pass
# if self.__dynamicEnabled:
# color = QColor(0, 150, 0, 150)
# else:
# color = QColor(150, 0, 0, 150)
#
# normal = QPen(QBrush(color), 2.0)
# hover = QPen(QBrush(color.darker(120)), 2.0)
if self.__state & LinkItem.Empty:
pen_style = Qt.DashLine
else:
pen_style = Qt.SolidLine

if darkMode:
brush = QBrush(QColor('#EEEEEE'))
hover = QPen(
QBrush(QColor('#FFFFFF')),
3.0 if pen_style == Qt.SolidLine else 2.0
)
else:
brush = QBrush(QColor('#878787'))
hover = QPen(
brush.color().darker(105),
3.0 if pen_style == Qt.SolidLine else 2.0
)
normal = QPen(
brush,
3.0 if pen_style == Qt.SolidLine and self.__state else 2.0
)

normal.setStyle(pen_style)
hover.setStyle(pen_style)

if self.hover or self.isSelected():
if self.hover or self.isSelected() or self.__isSelectedImplicit():
pen = hover
else:
pen = normal
Expand Down

0 comments on commit bff9b98

Please sign in to comment.