Skip to content

Commit dbc9b8e

Browse files
irgolicmarkotoplak
authored andcommitted
canvas: Style dark mode
1 parent 674cd70 commit dbc9b8e

File tree

5 files changed

+175
-105
lines changed

5 files changed

+175
-105
lines changed

orangecanvas/canvas/items/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
"""
55

6-
from .nodeitem import NodeItem, NodeAnchorItem, NodeBodyItem, SHADOW_COLOR
6+
from .nodeitem import NodeItem, NodeAnchorItem, NodeBodyItem, DEFAULT_SHADOW_COLOR
77
from .nodeitem import SourceAnchorItem, SinkAnchorItem, AnchorPoint
88
from .linkitem import LinkItem, LinkCurveItem
99
from .annotationitem import TextAnnotation, ArrowAnnotation

orangecanvas/canvas/items/graphicstextitem.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
QGraphicsItem, QGraphicsSceneContextMenuEvent, QMenu, QAction,
1717
)
1818

19+
from orangecanvas.gui.utils import foreground_for_background
1920
from orangecanvas.utils import set_flag
2021

2122

@@ -63,11 +64,7 @@ def paint(self, painter, option, widget=None):
6364
if not window.isActiveWindow():
6465
cg = QPalette.Inactive
6566

66-
color = palette.color(
67-
cg,
68-
QPalette.Highlight if state & QStyle.State_Selected
69-
else QPalette.Light
70-
)
67+
color = palette.color(cg, QPalette.Light)
7168

7269
painter.save()
7370
painter.setPen(QPen(Qt.NoPen))
@@ -113,10 +110,13 @@ def __updateDefaultTextColor(self):
113110
# type: () -> None
114111
if self.__styleState & QStyle.State_Selected \
115112
and not self.__styleState & QStyle.State_Editing:
116-
role = QPalette.HighlightedText
113+
bgRole = QPalette.Light
114+
bgColor = self.palette().color(bgRole)
115+
color = foreground_for_background(bgColor)
117116
else:
118117
role = QPalette.WindowText
119-
self.setDefaultTextColor(self.palette().color(role))
118+
color = self.palette().color(role)
119+
self.setDefaultTextColor(color)
120120

121121
def setHtml(self, contents):
122122
# type: (str) -> None

orangecanvas/canvas/items/linkitem.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
from AnyQt.QtWidgets import (
1414
QGraphicsItem, QGraphicsPathItem, QGraphicsWidget,
1515
QGraphicsDropShadowEffect, QGraphicsSceneHoverEvent, QStyle,
16-
QGraphicsSceneMouseEvent
17-
)
16+
QGraphicsSceneMouseEvent,
17+
QApplication)
1818
from AnyQt.QtGui import (
1919
QPen, QBrush, QColor, QPainterPath, QTransform, QPalette, QFont,
2020
)
2121
from AnyQt.QtCore import Qt, QPointF, QRectF, QLineF, QEvent, QPropertyAnimation, Signal, QTimer
2222

23-
from .nodeitem import AnchorPoint, SHADOW_COLOR
23+
from .nodeitem import AnchorPoint, DEFAULT_SHADOW_COLOR
2424
from .graphicstextitem import GraphicsTextItem
2525
from .utils import stroke_path, qpainterpath_sub_path
2626
from ...registry import InputSignal, OutputSignal
@@ -52,7 +52,7 @@ def __init__(self, parent):
5252
self.setPen(QPen(QBrush(QColor("#9CACB4")), 2.0))
5353

5454
self.shadow = QGraphicsDropShadowEffect(
55-
blurRadius=5, color=QColor(SHADOW_COLOR),
55+
blurRadius=5, color=QColor(DEFAULT_SHADOW_COLOR),
5656
offset=QPointF(0, 0)
5757
)
5858
self.setGraphicsEffect(self.shadow)
@@ -718,27 +718,46 @@ def __updatePen(self):
718718
# type: () -> None
719719
self.prepareGeometryChange()
720720
self.__boundingRect = None
721-
if self.__dynamic:
722-
if self.__dynamicEnabled:
723-
color = QColor(0, 150, 0, 150)
724-
else:
725-
color = QColor(150, 0, 0, 150)
726721

727-
normal = QPen(QBrush(color), 2.0)
728-
hover = QPen(QBrush(color.darker(120)), 2.0)
729-
else:
730-
normal = QPen(QBrush(QColor("#9CACB4")), 2.0)
731-
hover = QPen(QBrush(QColor("#959595")), 2.0)
722+
app = QApplication.instance()
723+
darkMode = app.property('darkMode')
732724

725+
if self.__dynamic:
726+
# TODO
727+
pass
728+
# if self.__dynamicEnabled:
729+
# color = QColor(0, 150, 0, 150)
730+
# else:
731+
# color = QColor(150, 0, 0, 150)
732+
#
733+
# normal = QPen(QBrush(color), 2.0)
734+
# hover = QPen(QBrush(color.darker(120)), 2.0)
733735
if self.__state & LinkItem.Empty:
734736
pen_style = Qt.DashLine
735737
else:
736738
pen_style = Qt.SolidLine
737739

740+
if darkMode:
741+
brush = QBrush(QColor('#EEEEEE'))
742+
hover = QPen(
743+
QBrush(QColor('#FFFFFF')),
744+
3.0 if pen_style == Qt.SolidLine else 2.0
745+
)
746+
else:
747+
brush = QBrush(QColor('#878787'))
748+
hover = QPen(
749+
brush.color().darker(105),
750+
3.0 if pen_style == Qt.SolidLine else 2.0
751+
)
752+
normal = QPen(
753+
brush,
754+
3.0 if pen_style == Qt.SolidLine and self.__state else 2.0
755+
)
756+
738757
normal.setStyle(pen_style)
739758
hover.setStyle(pen_style)
740759

741-
if self.hover or self.isSelected():
760+
if self.hover or self.isSelected() or self.__isSelectedImplicit():
742761
pen = hover
743762
else:
744763
pen = normal

0 commit comments

Comments
 (0)