Browse Source

Make ScalableButton compatible with old pixmaps

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.2.0-RC1
falkTX 4 years ago
parent
commit
8d9c63bfbe
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 84 additions and 42 deletions
  1. +15
    -13
      source/frontend/carla_skin.py
  2. +69
    -29
      source/frontend/widgets/scalablebutton.py

+ 15
- 13
source/frontend/carla_skin.py View File

@@ -377,9 +377,9 @@ class AbstractPluginSlot(QFrame, PluginEditParentMeta):
self.b_enable.clicked.connect(self.slot_enableClicked)

if isCalfSkin:
self.b_enable.setSvgs(":/scalable/button_calf3.svg",
":/scalable/button_calf3_down.svg",
":/scalable/button_calf3.svg")
self.b_enable.setPixmaps(":/bitmaps/button_calf3.png",
":/bitmaps/button_calf3_down.png",
":/bitmaps/button_calf3.png")
else:
self.b_enable.setSvgs(":/scalable/button_off.svg",
":/scalable/button_on.svg",
@@ -390,13 +390,13 @@ class AbstractPluginSlot(QFrame, PluginEditParentMeta):
self.b_gui.setEnabled(bool(self.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI))

if isCalfSkin:
self.b_gui.setSvgs(":/scalable/button_calf2.svg",
":/scalable/button_calf2_down.svg",
":/scalable/button_calf2_hover.svg")
self.b_gui.setPixmaps(":/scalable/button_calf2.png",
":/scalable/button_calf2_down.png",
":/scalable/button_calf2_hover.png")
elif self.fPluginInfo['iconName'] == "distrho" or self.fSkinStyle in ("3bandeq", "3bandsplitter", "pingpongpan", "nekobi"):
self.b_gui.setSvgs(":/scalable/button_distrho-{}.svg".format(imageSuffix),
":/scalable/button_distrho_down-{}.svg".format(imageSuffix),
":/scalable/button_distrho_hover-{}.svg".format(imageSuffix))
self.b_gui.setPixmaps(":/bitmaps/button_distrho-{}.png".format(imageSuffix),
":/bitmaps/button_distrho_down-{}.png".format(imageSuffix),
":/bitmaps/button_distrho_hover-{}.png".format(imageSuffix))
elif self.fPluginInfo['iconName'] == "file":
self.b_gui.setSvgs(":/scalable/button_file-{}.svg".format(imageSuffix),
":/scalable/button_file_down-{}.svg".format(imageSuffix),
@@ -410,9 +410,9 @@ class AbstractPluginSlot(QFrame, PluginEditParentMeta):
self.b_edit.clicked.connect(self.slot_showEditDialog)

if isCalfSkin:
self.b_edit.setSvgs(":/scalable/button_calf2.svg",
":/scalable/button_calf2_down.svg",
":/scalable/button_calf2_hover.svg")
self.b_edit.setPixmaps(":/bitmaps/button_calf2.png",
":/bitmaps/button_calf2_down.png",
":/bitmaps/button_calf2_hover.png")
else:
self.b_edit.setSvgs(":/scalable/button_edit-{}.svg".format(imageSuffix),
":/scalable/button_edit_down-{}.svg".format(imageSuffix),
@@ -1530,7 +1530,9 @@ class PluginSlot_Calf(AbstractPluginSlot):

self.ui.label_active.setFont(self.fButtonFont)

self.ui.b_remove.setSvgs(":/scalable/button_calf1.svg", ":/scalable/button_calf1_down.svg", ":/scalable/button_calf1_hover.svg")
self.ui.b_remove.setPixmaps(":/scalable/button_calf1.png",
":/scalable/button_calf1_down.png",
":/scalable/button_calf1_hover.png")

self.ui.b_edit.setTopText(self.tr("Edit"), self.fButtonColorOn, self.fButtonFont)
self.ui.b_remove.setTopText(self.tr("Remove"), self.fButtonColorOn, self.fButtonFont)


+ 69
- 29
source/frontend/widgets/scalablebutton.py View File

@@ -1,8 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Svg Button, a custom Qt widget
# Copyright (C) 2020 Filipe Coelho <falktx@falktx.com>
# Scalable Button, a custom Qt widget
# Copyright (C) 2013-2020 Filipe Coelho <falktx@falktx.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
@@ -20,39 +20,52 @@
# Imports (Global)

from PyQt5.QtCore import QPointF, QRectF
from PyQt5.QtGui import QColor, QFont, QPainter
from PyQt5.QtGui import QColor, QFont, QPainter, QPixmap
from PyQt5.QtSvg import QSvgWidget
from PyQt5.QtWidgets import QPushButton

# ------------------------------------------------------------------------------------------------------------
# Widget Class


class ScalableButton(QPushButton):
def __init__(self, parent):
QPushButton.__init__(self, parent)

self.fSvgNormal = QSvgWidget()
self.fSvgDown = QSvgWidget()
self.fSvgHover = QSvgWidget()

self.fIsHovered = False

self.fImageNormal = None
self.fImageDown = None
self.fImageHover = None
self.fImageRect = QRectF()
self.fIsHovered = False
self.fTopText = ""
self.fTopTextColor = QColor()
self.fTopTextFont = QFont()

self.setText("")

def setSvgs(self, normal, down, hover):
self.fSvgNormal.load(normal)
self.fSvgDown.load(down)
self.fSvgHover.load(hover)
def setPixmaps(self, normal, down, hover):
self.fImageNormal = QPixmap()
self.fImageDown = QPixmap()
self.fImageHover = QPixmap()
self._loadImages(normal, down, hover)

width = self.fSvgNormal.sizeHint().width()
height = self.fSvgNormal.sizeHint().height()
def setSvgs(self, normal, down, hover):
self.fImageNormal = QSvgWidget()
self.fImageDown = QSvgWidget()
self.fImageHover = QSvgWidget()
self._loadImages(normal, down, hover)

def _loadImages(self, normal, down, hover):
self.fImageNormal.load(normal)
self.fImageDown.load(down)
self.fImageHover.load(hover)

if isinstance(self.fImageNormal, QPixmap):
width = self.fImageNormal.width()
height = self.fImageNormal.height()
else:
width = self.fImageNormal.sizeHint().width()
height = self.fImageNormal.sizeHint().height()

self.fSvgRect = QRectF(0, 0, width, height)
self.fImageRect = QRectF(0, 0, width, height)

self.setMinimumSize(width, height)
self.setMaximumSize(width, height)
@@ -74,19 +87,14 @@ class ScalableButton(QPushButton):
painter = QPainter(self)
event.accept()

if not self.isEnabled():
painter.save()
painter.setOpacity(0.2)
self.fSvgNormal.renderer().render(painter, self.fSvgRect)
painter.restore()

elif self.isChecked() or self.isDown():
self.fSvgDown.renderer().render(painter, self.fSvgRect)
if self.fImageNormal is None:
return

elif self.fIsHovered:
self.fSvgHover.renderer().render(painter, self.fSvgRect)
if isinstance(self.fImageNormal, QPixmap):
self.paintEventPixmap(painter)
else:
self.fSvgNormal.renderer().render(painter, self.fSvgRect)
self.paintEventSvg(painter)

if not self.fTopText:
return

@@ -96,3 +104,35 @@ class ScalableButton(QPushButton):
painter.setFont(self.fTopTextFont)
painter.drawText(QPointF(10, 16), self.fTopText)
painter.restore()

def paintEventPixmap(self, painter):
if not self.isEnabled():
painter.save()
painter.setOpacity(0.2)
painter.drawPixmap(self.fImageRect, self.fImageNormal, self.fImageRect)
painter.restore()

elif self.isChecked() or self.isDown():
painter.drawPixmap(self.fImageRect, self.fImageDown, self.fImageRect)

elif self.fIsHovered:
painter.drawPixmap(self.fImageRect, self.fImageHover, self.fImageRect)

else:
painter.drawPixmap(self.fImageRect, self.fImageNormal, self.fImageRect)

def paintEventSvg(self, painter):
if not self.isEnabled():
painter.save()
painter.setOpacity(0.2)
self.fImageNormal.renderer().render(painter, self.fImageRect)
painter.restore()

elif self.isChecked() or self.isDown():
self.fImageDown.renderer().render(painter, self.fImageRect)

elif self.fIsHovered:
self.fImageHover.renderer().render(painter, self.fImageRect)

else:
self.fImageNormal.renderer().render(painter, self.fImageRect)

Loading…
Cancel
Save