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

Dark mode #175

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 1 addition & 21 deletions orangecanvas/application/widgettoolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from ..gui.toolbox import ToolBox
from ..gui.toolgrid import ToolGrid
from ..gui.quickhelp import StatusTipPromoter
from ..gui.utils import create_gradient
from ..registry.qt import QtWidgetRegistry


Expand Down Expand Up @@ -415,26 +414,7 @@ def __insertItem(self, item, index):
self.insertItem(index, grid, text, icon, tooltip)
button = self.tabButton(index)

# Set the 'highlight' color if applicable
highlight_foreground = None
highlight = item_background(item)
if highlight is None \
and item.data(QtWidgetRegistry.BACKGROUND_ROLE) is not None:
highlight = item.data(QtWidgetRegistry.BACKGROUND_ROLE)

if isinstance(highlight, QBrush) and highlight.style() != Qt.NoBrush:
if not highlight.gradient():
value = highlight.color().value()
gradient = create_gradient(highlight.color())
highlight = QBrush(gradient)
highlight_foreground = Qt.black if value > 128 else Qt.white

palette = button.palette()

if highlight is not None:
palette.setBrush(QPalette.Highlight, highlight)
if highlight_foreground is not None:
palette.setBrush(QPalette.HighlightedText, highlight_foreground)
palette = item.data(QtWidgetRegistry.BACKGROUND_ROLE)
button.setPalette(palette)

def __on_dataChanged(self, topLeft, bottomRight):
Expand Down
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 @@ -16,6 +16,7 @@
QGraphicsItem, QGraphicsSceneContextMenuEvent, QMenu, QAction,
)

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


Expand Down Expand Up @@ -63,11 +64,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 @@ -113,10 +110,13 @@ def __updateDefaultTextColor(self):
# type: () -> None
if self.__styleState & QStyle.State_Selected \
and not self.__styleState & QStyle.State_Editing:
role = QPalette.HighlightedText
bgRole = QPalette.Light
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modification was written before #177. Perhaps we should instead leave role = QPalette.HighlightedText from #177 in.

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, QFont,
)
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, qpainterpath_sub_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 @@ -718,27 +718,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