1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# PatchBay Canvas engine using QGraphicsView/Scene
# Copyright (C) 2010-2019 Filipe Coelho <falktx@falktx.com>
# Copyright (C) 2019-2024 Mathieu Picot <picotmathieu@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a full copy of the GNU General Public License see the doc/GPL.txt file.
from typing import TYPE_CHECKING
from qtpy.QtGui import QColor
from qtpy.QtWidgets import QGraphicsDropShadowEffect, QGraphicsObject
from .init_values import canvas
from .theme import StyleAttributer
if TYPE_CHECKING:
from .box_widget_moth import BoxWidgetMoth
class BoxWidgetShadow(QGraphicsDropShadowEffect):
def __init__(self, parent: QGraphicsObject):
QGraphicsDropShadowEffect.__init__(self, parent)
self._fake_parent = None
self._theme = None
self.setBlurRadius(20)
self.setOffset(0, 2)
def set_theme(self, theme: StyleAttributer):
self._theme = theme
self.setColor(theme.background_color)
def set_opacity(self, opacity: float):
if self._theme is None:
return
color = QColor(self._theme.background_color)
color.setAlphaF(opacity)
self.setColor(color)
def set_fake_parent(self, parent: 'BoxWidgetMoth'):
self._fake_parent = parent
def draw(self, painter):
if self._fake_parent is not None:
if ((self._fake_parent.boundingRect().height()
* canvas.scene.get_zoom_scale())
>= canvas.scene._view.height()):
# workaround for a visual bug with cached QGraphicsItem,
# QDropShadowEffect and big zoom.
# see https://bugreports.qt.io/browse/QTBUG-77400
self._fake_parent.set_in_cache(False)
else:
self._fake_parent.set_in_cache(True)
self._fake_parent.repaint_lines()
QGraphicsDropShadowEffect.draw(self, painter)
# ------------------------------------------------------------------------------------------------------------
|