Skip to content

Commit 0d41936

Browse files
committed
Fix integration problems #121 fix
1 parent 3096aa9 commit 0d41936

1 file changed

Lines changed: 36 additions & 9 deletions

File tree

‎BlocksScreen/lib/utils/blocks_label.py‎

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,17 @@ def __init__(self, parent: QtWidgets.QWidget = None, *args, **kwargs):
2828
QtWidgets.QSizePolicy.Policy.MinimumExpanding,
2929
QtWidgets.QSizePolicy.Policy.MinimumExpanding,
3030
)
31-
3231
self._glow_color: QtGui.QColor = QtGui.QColor("#E95757")
3332
self._animation_speed: int = 300
3433
self.glow_animation = QtCore.QPropertyAnimation(self, b"glow_color")
3534
self.glow_animation.setEasingCurve(QtCore.QEasingCurve().Type.InOutQuart)
3635
self.glow_animation.setDuration(self.animation_speed)
37-
3836
self.glow_animation.finished.connect(self.change_glow_direction)
3937
self.glow_animation.finished.connect(self.repaint)
40-
4138
self.total_scroll_width: float = 0.0
4239
self.text_width: float = 0.0
4340
self.label_width: float = 0.0
41+
self.icon_margin: int = 5
4442
self.first_run = True
4543

4644
def resizeEvent(self, a0: QtGui.QResizeEvent) -> None:
@@ -203,17 +201,46 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
203201
qp.fillRect(rect, self._background_color)
204202

205203
if self.icon_pixmap:
206-
icon_rect = QtCore.QRectF(0, 0, self.height(), self.height())
207-
scaled = self.icon_pixmap.scaled(
204+
icon_rect = QtCore.QRectF(
205+
0.0 + self.icon_margin,
206+
0.0 + self.icon_margin,
207+
self.width() - self.icon_margin,
208+
self.height() - self.icon_margin,
209+
)
210+
_icon_scaled = self.icon_pixmap.scaled(
208211
icon_rect.size().toSize(),
209212
QtCore.Qt.AspectRatioMode.KeepAspectRatio,
210213
QtCore.Qt.TransformationMode.SmoothTransformation,
211214
)
212-
qp.drawPixmap(icon_rect.toRect(), scaled)
215+
scaled_width = _icon_scaled.width()
216+
scaled_height = _icon_scaled.height()
217+
adjusted_x = (icon_rect.width() - scaled_width) // 2.0
218+
adjusted_y = (icon_rect.height() - scaled_height) // 2.0
219+
adjusted_icon = QtCore.QRectF(
220+
icon_rect.x() + adjusted_x,
221+
icon_rect.y() + adjusted_y,
222+
scaled_width,
223+
scaled_height,
224+
)
225+
qp.drawPixmap(adjusted_icon, _icon_scaled, _icon_scaled.rect().toRectF())
213226
if self.glow_animation.state() == self.glow_animation.State.Running:
214-
path = QtGui.QPainterPath()
215-
path.addRoundedRect(QtCore.QRectF(rect), 10, 10)
216-
qp.fillPath(path, self.glow_color)
227+
big_rect = QtGui.QPainterPath()
228+
rect = self.contentsRect().toRectF()
229+
big_rect.addRoundedRect(rect, 10.0, 10.0, QtCore.Qt.SizeMode.AbsoluteSize)
230+
sub_rect = QtCore.QRectF(
231+
(rect.width() - rect.width() * 0.99) / 2,
232+
(rect.height() - rect.height() * 0.85) / 2,
233+
rect.width() * 0.99,
234+
rect.height() * 0.85,
235+
)
236+
sub_path = QtGui.QPainterPath()
237+
sub_path.addRoundedRect(
238+
sub_rect, 10.0, 10.0, QtCore.Qt.SizeMode.AbsoluteSize
239+
)
240+
subtracted = big_rect.subtracted(sub_path)
241+
qp.setCompositionMode(qp.CompositionMode.CompositionMode_SourceOver)
242+
subtracted.setFillRule(QtCore.Qt.FillRule.OddEvenFill)
243+
qp.fillPath(subtracted, self.glow_color)
217244
if self._text:
218245
text_option = QtGui.QTextOption(self.alignment())
219246
text_option.setWrapMode(QtGui.QTextOption.WrapMode.NoWrap)

0 commit comments

Comments
 (0)