Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
irgolic committed Feb 19, 2021
1 parent bb3ba52 commit 42ddc85
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 171 deletions.
7 changes: 7 additions & 0 deletions orangecanvas/application/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from AnyQt.QtCore import (
Qt, QUrl, QEvent, QSettings, QLibraryInfo, pyqtSignal as Signal
)
from PyQt5.QtGui import QFont, QPalette

from orangecanvas.utils.after_exit import run_after_exit
from orangecanvas.utils.asyncutils import get_event_loop
Expand Down Expand Up @@ -117,6 +118,12 @@ def __init__(self, argv):
sh.setShowShortcutsInContextMenus(True)
self.configureStyle()

if sys.platform != 'darwin':
font = QFont('Titillium Web',
self.font().pointSize(),
self.font().weight())
self.setFont(font)

def event(self, event):
if event.type() == QEvent.FileOpen:
self.fileOpenRequest.emit(event.url())
Expand Down
23 changes: 2 additions & 21 deletions orangecanvas/application/widgettoolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from ..gui.toolbox import ToolBox
from ..gui.toolgrid import ToolGrid
from ..gui.quickhelp import StatusTipPromoter
from ..gui.utils import create_gradient
from ..gui.utils import create_gradient, foreground_for_background
from ..registry.qt import QtWidgetRegistry


Expand Down Expand Up @@ -415,26 +415,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
20 changes: 14 additions & 6 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,6 +809,10 @@ def __updatePen(self):
# type: () -> None
self.prepareGeometryChange()
self.__boundingRect = None

app = QApplication.instance()
darkMode = app.property('darkMode')

if self.__dynamic:
if self.__dynamicEnabled:
color = QColor(0, 150, 0, 150)
Expand All @@ -818,8 +822,12 @@ def __updatePen(self):
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)
if darkMode:
brush = QBrush(QColor('#FFFFFF'))
else:
brush = QBrush(QColor('#878787'))
normal = QPen(brush, 2.0)
hover = QPen(brush.color().darker(105), 2.0)

if self.__state & LinkItem.Empty:
pen_style = Qt.DashLine
Expand Down
123 changes: 58 additions & 65 deletions orangecanvas/canvas/items/nodeitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

from .graphicspathobject import GraphicsPathObject
from .graphicstextitem import GraphicsTextItem
from .utils import saturated, radial_gradient
from .utils import radial_gradient
from ...registry.utils import default_palette, create_palette

from ...scheme.node import UserMessage
from ...registry import NAMED_COLORS, WidgetDescription, CategoryDescription, \
Expand All @@ -48,48 +49,14 @@
# from . import LinkItem


def create_palette(light_color, color):
# type: (QColor, QColor) -> QPalette
"""
Return a new :class:`QPalette` from for the :class:`NodeBodyItem`.
"""
palette = QPalette()

palette.setColor(QPalette.Inactive, QPalette.Light,
saturated(light_color, 50))
palette.setColor(QPalette.Inactive, QPalette.Midlight,
saturated(light_color, 90))
palette.setColor(QPalette.Inactive, QPalette.Button,
light_color)

palette.setColor(QPalette.Active, QPalette.Light,
saturated(color, 50))
palette.setColor(QPalette.Active, QPalette.Midlight,
saturated(color, 90))
palette.setColor(QPalette.Active, QPalette.Button,
color)
palette.setColor(QPalette.ButtonText, QColor("#515151"))
return palette


def default_palette():
# type: () -> QPalette
"""
Create and return a default palette for a node.
"""
return create_palette(QColor(NAMED_COLORS["light-yellow"]),
QColor(NAMED_COLORS["yellow"]))


def animation_restart(animation):
# type: (QPropertyAnimation) -> None
if animation.state() == QPropertyAnimation.Running:
animation.pause()
animation.start()


SHADOW_COLOR = "#9CACB4"
SELECTED_SHADOW_COLOR = "#609ED7"
DEFAULT_SHADOW_COLOR = "#9CACB4"


class NodeBodyItem(GraphicsPathObject):
Expand Down Expand Up @@ -120,7 +87,7 @@ def __init__(self, parent=None):

self.shadow = QGraphicsDropShadowEffect(
blurRadius=0,
color=QColor(SHADOW_COLOR),
color=QColor(DEFAULT_SHADOW_COLOR),
offset=QPointF(0, 0),
)
self.shadow.setEnabled(False)
Expand All @@ -131,7 +98,7 @@ def __init__(self, parent=None):
# non devicePixelRatio aware.
shadowitem = GraphicsPathObject(self, objectName="shadow-shape-item")
shadowitem.setPen(Qt.NoPen)
shadowitem.setBrush(QBrush(QColor(SHADOW_COLOR).lighter()))
shadowitem.setBrush(QBrush(QColor(DEFAULT_SHADOW_COLOR).lighter()))
shadowitem.setGraphicsEffect(self.shadow)
shadowitem.setFlag(QGraphicsItem.ItemStacksBehindParent)
self.__shadow = shadowitem
Expand Down Expand Up @@ -285,11 +252,7 @@ def __updateShadowState(self):
if enabled and not self.shadow.isEnabled():
self.shadow.setEnabled(enabled)

if self.__isSelected:
color = QColor(SELECTED_SHADOW_COLOR)
else:
color = QColor(SHADOW_COLOR)

color = self.palette.color(QPalette.Shadow)
self.shadow.setColor(color)

if self.__animationEnabled:
Expand Down Expand Up @@ -352,8 +315,10 @@ def __init__(self, parent=None):
self.setAcceptedMouseButtons(Qt.NoButton)
self.setRect(-3.5, -3.5, 7., 7.)
self.setPen(QPen(Qt.NoPen))
self.setBrush(QBrush(QColor("#9CACB4")))
self.hoverBrush = QBrush(QColor("#959595"))

color = QColor("#9CACB4")
self.brush = QBrush(color)
self.hover_brush = QBrush(color.darker(115))

self.__hover = False

Expand All @@ -378,7 +343,7 @@ def setLinkState(self, state: 'LinkItem.State'):
def paint(self, painter, option, widget=None):
# type: (QPainter, QStyleOptionGraphicsItem, Optional[QWidget]) -> None
hover = self.__styleState & (QStyle.State_Selected | QStyle.State_MouseOver)
brush = self.hoverBrush if hover else self.brush()
brush = self.hover_brush if hover else self.brush
if self.__linkState & (LinkItem.Pending | LinkItem.Invalidated):
brush = QBrush(Qt.red)

Expand Down Expand Up @@ -639,15 +604,15 @@ def __init__(self, parent, **kwargs):

self.shadow = QGraphicsDropShadowEffect(
blurRadius=0,
color=QColor(SHADOW_COLOR),
# color=QColor(DEFAULT_SHADOW_COLOR),
offset=QPointF(0, 0),
)
# self.setGraphicsEffect(self.shadow)
self.shadow.setEnabled(False)

shadowitem = GraphicsPathObject(self, objectName="shadow-shape-item")
shadowitem.setPen(Qt.NoPen)
shadowitem.setBrush(QBrush(QColor(SHADOW_COLOR)))
# shadowitem.setBrush(QBrush(QColor(DEFAULT_SHADOW_COLOR)))
shadowitem.setGraphicsEffect(self.shadow)
shadowitem.setFlag(QGraphicsItem.ItemStacksBehindParent)
self.__shadow = shadowitem
Expand Down Expand Up @@ -1345,6 +1310,9 @@ def __init__(self, widget_description=None, parent=None, **kwargs):
self.outputAnchorItem.setAnchorPath(output_path)
self.outputAnchorItem.setAnimationEnabled(self.__animationEnabled)

self.widget_palette = None
self.__updateAnchorBrushes()

self.inputAnchorItem.hide()
self.outputAnchorItem.hide()

Expand Down Expand Up @@ -1428,11 +1396,34 @@ def setWidgetCategory(self, desc):
Set the widget category.
"""
self.category_description = desc
if desc and desc.background:
background = NAMED_COLORS.get(desc.background, desc.background)
color = QColor(background)
if color.isValid():
self.setColor(color)

background = desc.background
if desc.background:
palette = create_palette(background)
else:
palette = default_palette()
self.widget_palette = palette
self.setPalette(palette)

def __updateAnchorBrushes(self):
app = QApplication.instance()
darkMode = app.property('darkMode')
if darkMode:
link_brush = QBrush(QColor('#FFFFFF'))
else:
link_brush = QBrush(QColor('#878787'))
hover_brush = QBrush(link_brush.color().darker(105))
con_hover_brush = QBrush(hover_brush.color().darker(105))

for anchor in (self.outputAnchorItem, self.inputAnchorItem):
anchor.connectedBrush = hover_brush
anchor.normalBrush = link_brush
anchor.connectedHoverBrush = con_hover_brush
anchor.normalHoverBrush = hover_brush
for point in anchor.anchorPoints():
point.indicator.brush = link_brush
point.indicator.hover_brush = hover_brush
anchor.update()

def setIcon(self, icon):
# type: (QIcon) -> None
Expand All @@ -1444,18 +1435,8 @@ def setIcon(self, icon):
)
self.icon_item.setPos(-18, -18)

def setColor(self, color, selectedColor=None):
# type: (QColor, Optional[QColor]) -> None
"""
Set the widget color.
"""
if selectedColor is None:
selectedColor = saturated(color, 150)
palette = create_palette(color, selectedColor)
self.shapeItem.setPalette(palette)

def setTitle(self, title):
# type: (str) -> None
# type: (str) -> Nne
"""
Set the node title. The title text is displayed at the bottom of the
node.
Expand Down Expand Up @@ -1594,8 +1575,11 @@ def newInputAnchor(self, signal=None):
if not (self.widget_description and self.widget_description.inputs):
raise ValueError("Widget has no inputs.")

palette = self.palette()

anchor = AnchorPoint(self, signal=signal)
self.inputAnchorItem.addAnchor(anchor)
self.__updateAnchorBrushes()

return anchor

Expand All @@ -1614,8 +1598,11 @@ def newOutputAnchor(self, signal=None):
if not (self.widget_description and self.widget_description.outputs):
raise ValueError("Widget has no outputs.")

palette = self.palette()

anchor = AnchorPoint(self, signal=signal)
self.outputAnchorItem.addAnchor(anchor)
self.__updateAnchorBrushes()

return anchor

Expand Down Expand Up @@ -1806,8 +1793,14 @@ def itemChange(self, change, value):

def __updatePalette(self):
# type: () -> None
palette = self.palette()
if self.widget_palette:
palette = self.widget_palette
else:
palette = self.palette()

self.shapeItem.setPalette(palette)
self.captionTextItem.setPalette(palette)
self.__updateAnchorBrushes()

def __updateFont(self):
# type: () -> None
Expand Down
15 changes: 2 additions & 13 deletions orangecanvas/canvas/items/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from AnyQt.QtWidgets import QGraphicsItem

from orangecanvas.registry.utils import saturated

if typing.TYPE_CHECKING:
T = typing.TypeVar("T")
A = typing.TypeVar("A")
Expand Down Expand Up @@ -93,19 +95,6 @@ def sample_path(path, num=10):
return [path.pointAtPercent(p) for p in linspace(num)]


def saturated(color, factor=150):
# type: (QColor, int) -> QColor
"""Return a saturated color.
"""
h = color.hsvHueF()
s = color.hsvSaturationF()
v = color.valueF()
a = color.alphaF()
s = factor * s / 100.0
s = max(min(1.0, s), 0.0)
return QColor.fromHsvF(h, s, v, a).convertTo(color.spec())


def radial_gradient(color, color_light=50):
# type: (QColor, Union[int, QColor]) -> QRadialGradient
"""
Expand Down
Loading

0 comments on commit 42ddc85

Please sign in to comment.