From 6424b5e652188c989356be92ab90fbade6551bb9 Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 19 Mar 2014 17:18:23 +0000 Subject: [PATCH] Rework of PixmapDial class --- resources/ui/carla_edit.ui | 39 ----- source/carla_widgets.py | 41 +++-- source/widgets/pixmapdial.py | 326 ++++++++++++++++++++++------------- 3 files changed, 232 insertions(+), 174 deletions(-) diff --git a/resources/ui/carla_edit.ui b/resources/ui/carla_edit.ui index 7061de3eb..c77754a79 100644 --- a/resources/ui/carla_edit.ui +++ b/resources/ui/carla_edit.ui @@ -127,12 +127,6 @@ Output dry/wet (100%) - - 1000 - - - 1000 - @@ -155,12 +149,6 @@ Output volume (100%) - - 1270 - - - 1000 - @@ -205,15 +193,6 @@ Balance Left (0%) - - -1000 - - - 1000 - - - -1000 - @@ -236,15 +215,6 @@ Balance Right (0%) - - -1000 - - - 1000 - - - 1000 - @@ -277,15 +247,6 @@ Balance Right (0%) - - -1000 - - - 1000 - - - 0 - diff --git a/source/carla_widgets.py b/source/carla_widgets.py index c5217fbc7..8da86f291 100755 --- a/source/carla_widgets.py +++ b/source/carla_widgets.py @@ -414,25 +414,40 @@ class PluginEdit(QDialog): # ------------------------------------------------------------- # Set-up GUI - self.ui.dial_drywet.setCustomPaint(self.ui.dial_drywet.CUSTOM_PAINT_CARLA_WET) + self.ui.dial_drywet.setCustomPaintMode(self.ui.dial_drywet.CUSTOM_PAINT_MODE_CARLA_WET) self.ui.dial_drywet.setPixmap(3) self.ui.dial_drywet.setLabel("Dry/Wet") + self.ui.dial_drywet.setMinimum(0.0) + self.ui.dial_drywet.setMaximum(1.0) + self.ui.dial_drywet.setValue(1.0) - self.ui.dial_vol.setCustomPaint(self.ui.dial_vol.CUSTOM_PAINT_CARLA_VOL) + self.ui.dial_vol.setCustomPaintMode(self.ui.dial_vol.CUSTOM_PAINT_MODE_CARLA_VOL) self.ui.dial_vol.setPixmap(3) self.ui.dial_vol.setLabel("Volume") + self.ui.dial_vol.setMinimum(0.0) + self.ui.dial_vol.setMaximum(1.27) + self.ui.dial_vol.setValue(1.0) - self.ui.dial_b_left.setCustomPaint(self.ui.dial_b_left.CUSTOM_PAINT_CARLA_L) + self.ui.dial_b_left.setCustomPaintMode(self.ui.dial_b_left.CUSTOM_PAINT_MODE_CARLA_L) self.ui.dial_b_left.setPixmap(4) self.ui.dial_b_left.setLabel("L") + self.ui.dial_b_left.setMinimum(-1.0) + self.ui.dial_b_left.setMaximum(1.0) + self.ui.dial_b_left.setValue(0.0) - self.ui.dial_b_right.setCustomPaint(self.ui.dial_b_right.CUSTOM_PAINT_CARLA_R) + self.ui.dial_b_right.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_R) self.ui.dial_b_right.setPixmap(4) self.ui.dial_b_right.setLabel("R") + self.ui.dial_b_right.setMinimum(-1.0) + self.ui.dial_b_right.setMaximum(1.0) + self.ui.dial_b_right.setValue(0.0) - self.ui.dial_pan.setCustomPaint(self.ui.dial_b_right.CUSTOM_PAINT_CARLA_R) # FIXME + self.ui.dial_pan.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_PAN) self.ui.dial_pan.setPixmap(4) self.ui.dial_pan.setLabel("Pan") + self.ui.dial_pan.setMinimum(-1.0) + self.ui.dial_pan.setMaximum(1.0) + self.ui.dial_pan.setValue(0.0) self.ui.scrollArea = PixmapKeyboardHArea(self) self.layout().addWidget(self.ui.scrollArea) @@ -467,11 +482,11 @@ class PluginEdit(QDialog): self.ui.ch_send_pitchbend.clicked.connect(self.slot_optionChanged) self.ui.ch_send_all_sound_off.clicked.connect(self.slot_optionChanged) - self.ui.dial_drywet.valueChanged.connect(self.slot_dryWetChanged) - self.ui.dial_vol.valueChanged.connect(self.slot_volumeChanged) - self.ui.dial_b_left.valueChanged.connect(self.slot_balanceLeftChanged) - self.ui.dial_b_right.valueChanged.connect(self.slot_balanceRightChanged) - self.ui.dial_pan.valueChanged.connect(self.slot_panChanged) + self.ui.dial_drywet.realValueChanged.connect(self.slot_dryWetChanged) + self.ui.dial_vol.realValueChanged.connect(self.slot_volumeChanged) + self.ui.dial_b_left.realValueChanged.connect(self.slot_balanceLeftChanged) + self.ui.dial_b_right.realValueChanged.connect(self.slot_balanceRightChanged) + self.ui.dial_pan.realValueChanged.connect(self.slot_panChanged) self.ui.sb_ctrl_channel.valueChanged.connect(self.slot_ctrlChannelChanged) self.ui.dial_drywet.customContextMenuRequested.connect(self.slot_knobCustomMenu) @@ -1128,17 +1143,17 @@ class PluginEdit(QDialog): @pyqtSlot(int) def slot_dryWetChanged(self, value): if gCarla.host is not None: - gCarla.host.set_drywet(self.fPluginId, float(value)/1000) + gCarla.host.set_drywet(self.fPluginId, value) @pyqtSlot(int) def slot_volumeChanged(self, value): if gCarla.host is not None: - gCarla.host.set_volume(self.fPluginId, float(value)/1000) + gCarla.host.set_volume(self.fPluginId, value) @pyqtSlot(int) def slot_balanceLeftChanged(self, value): if gCarla.host is not None: - gCarla.host.set_balance_left(self.fPluginId, float(value)/1000) + gCarla.host.set_balance_left(self.fPluginId, value) @pyqtSlot(int) def slot_balanceRightChanged(self, value): diff --git a/source/widgets/pixmapdial.py b/source/widgets/pixmapdial.py index a5a5aa317..5549b1d51 100644 --- a/source/widgets/pixmapdial.py +++ b/source/widgets/pixmapdial.py @@ -27,12 +27,12 @@ from carla_config import * from math import cos, floor, pi, sin if config_UseQt5: - from PyQt5.QtCore import Qt, QPointF, QRectF, QTimer, QSize + from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QPointF, QRectF, QTimer, QSize from PyQt5.QtGui import QColor, QConicalGradient, QFont, QFontMetrics from PyQt5.QtGui import QLinearGradient, QPainter, QPainterPath, QPen, QPixmap from PyQt5.QtWidgets import QDial else: - from PyQt4.QtCore import Qt, QPointF, QRectF, QTimer, QSize + from PyQt4.QtCore import pyqtSignal, pyqtSlot, Qt, QPointF, QRectF, QTimer, QSize from PyQt4.QtGui import QColor, QConicalGradient, QFont, QFontMetrics from PyQt4.QtGui import QDial, QLinearGradient, QPainter, QPainterPath, QPen, QPixmap @@ -40,15 +40,16 @@ else: # Widget Class class PixmapDial(QDial): - # enum CustomPaint - CUSTOM_PAINT_NULL = 0 - CUSTOM_PAINT_CARLA_WET = 1 - CUSTOM_PAINT_CARLA_VOL = 2 - CUSTOM_PAINT_CARLA_L = 3 - CUSTOM_PAINT_CARLA_R = 4 - CUSTOM_PAINT_COLOR = 5 - CUSTOM_PAINT_ZITA = 6 - CUSTOM_PAINT_NO_GRADIENT = 7 + # enum CustomPaintMode + CUSTOM_PAINT_MODE_NULL = 0 # default (NOTE: only this mode has label gradient) + CUSTOM_PAINT_MODE_CARLA_WET = 1 # color blue-green gradient (reserved #3) + CUSTOM_PAINT_MODE_CARLA_VOL = 2 # color blue (reserved #3) + CUSTOM_PAINT_MODE_CARLA_L = 3 # color yellow (reserved #4) + CUSTOM_PAINT_MODE_CARLA_R = 4 # color yellow (reserved #4) + CUSTOM_PAINT_MODE_CARLA_PAN = 5 # color yellow (reserved #3) + CUSTOM_PAINT_MODE_COLOR = 6 # color, selectable (reserved #3) + CUSTOM_PAINT_MODE_ZITA = 7 # custom zita knob (reserved #6) + CUSTOM_PAINT_MODE_NO_GRADIENT = 8 # skip label gradient # enum Orientation HORIZONTAL = 0 @@ -57,23 +58,27 @@ class PixmapDial(QDial): HOVER_MIN = 0 HOVER_MAX = 9 + # signals + realValueChanged = pyqtSignal(float) + def __init__(self, parent, index=0): QDial.__init__(self, parent) - self.fIndex = index - self.fPixmap = QPixmap(":/bitmaps/dial_01d.png") - self.fPixmapNum = "01" - - self.fCustomColor = QColor(0, 0, 0) - self.fCustomPaint = self.CUSTOM_PAINT_NULL + self.fMinimum = 0.0 + self.fMaximum = 1.0 + self.fRealValue = 0.0 self.fIsHovered = False self.fHoverStep = self.HOVER_MIN + self.fIndex = index + self.fPixmap = QPixmap(":/bitmaps/dial_01d.png") + self.fPixmapNum = "01" + if self.fPixmap.width() > self.fPixmap.height(): - self.fOrientation = self.HORIZONTAL + self.fPixmapOrientation = self.HORIZONTAL else: - self.fOrientation = self.VERTICAL + self.fPixmapOrientation = self.VERTICAL self.fLabel = "" self.fLabelPos = QPointF(0.0, 0.0) @@ -81,113 +86,179 @@ class PixmapDial(QDial): self.fLabelFont.setPointSize(6) self.fLabelWidth = 0 self.fLabelHeight = 0 - self.fLabelGradient = QLinearGradient(0, 0, 0, 1) if self.palette().window().color().lightness() > 100: # Light background c = self.palette().dark().color() - self.fColor1 = c - self.fColor2 = QColor(c.red(), c.green(), c.blue(), 0) - self.fColorT = [self.palette().buttonText().color(), self.palette().mid().color()] + self.fLabelGradientColor1 = c + self.fLabelGradientColor2 = QColor(c.red(), c.green(), c.blue(), 0) + self.fLabelGradientColorT = [self.palette().buttonText().color(), self.palette().mid().color()] else: # Dark background - self.fColor1 = QColor(0, 0, 0, 255) - self.fColor2 = QColor(0, 0, 0, 0) - self.fColorT = [Qt.white, Qt.darkGray] + self.fLabelGradientColor1 = QColor(0, 0, 0, 255) + self.fLabelGradientColor2 = QColor(0, 0, 0, 0) + self.fLabelGradientColorT = [Qt.white, Qt.darkGray] + + self.fLabelGradient = QLinearGradient(0, 0, 0, 1) + self.fLabelGradient.setColorAt(0.0, self.fLabelGradientColor1) + self.fLabelGradient.setColorAt(0.6, self.fLabelGradientColor1) + self.fLabelGradient.setColorAt(1.0, self.fLabelGradientColor2) + + self.fLabelGradientRect = QRectF(0.0, 0.0, 0.0, 0.0) + + self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_NULL + self.fCustomPaintColor = QColor(0xff, 0xff, 0xff) self.updateSizes() + # Fake internal value, 10'000 precision + QDial.setMinimum(self, 0) + QDial.setMaximum(self, 10000) + QDial.setValue(self, 0) + + self.valueChanged.connect(self.slot_valueChanged) + def getIndex(self): return self.fIndex - def getSize(self): - return self.fSize + def getBaseSize(self): + return self.fPixmapBaseSize - def setCustomColor(self, color): - self.fCustomColor = color - #self.update() + def forceWhiteLabelGradientText(self): + self.fLabelGradientColor1 = QColor(0, 0, 0, 255) + self.fLabelGradientColor2 = QColor(0, 0, 0, 0) + self.fLabelGradientColorT = [Qt.white, Qt.darkGray] - def setCustomPaint(self, paint): - self.fCustomPaint = paint - self.fLabelPos.setY(self.fSize + self.fLabelHeight/2) - #self.update() + #def setMidWhiteText(self): + #self.fColor1 = QColor(0, 0, 0, 255) + #self.fColor2 = QColor(0, 0, 0, 0) + #self.fColorT = [QColor("#BBB"), Qt.darkGray] - def setEnabled(self, enabled): - if self.isEnabled() != enabled: - self.fPixmap.load(":/bitmaps/dial_%s%s.png" % (self.fPixmapNum, "" if enabled else "d")) - self.updateSizes() - self.update() - QDial.setEnabled(self, enabled) + def updateSizes(self): + self.fPixmapWidth = self.fPixmap.width() + self.fPixmapHeight = self.fPixmap.height() - def setIndex(self, index): - self.fIndex = index + if self.fPixmapWidth < 1: + self.fPixmapWidth = 1 - def setLabel(self, label): - self.fLabel = label + if self.fPixmapHeight < 1: + self.fPixmapHeight = 1 + + if self.fPixmapOrientation == self.HORIZONTAL: + self.fPixmapBaseSize = self.fPixmapHeight + self.fPixmapLayersCount = self.fPixmapWidth / self.fPixmapHeight + else: + self.fPixmapBaseSize = self.fPixmapWidth + self.fPixmapLayersCount = self.fPixmapHeight / self.fPixmapWidth + + self.setMinimumSize(self.fPixmapBaseSize, self.fPixmapBaseSize + self.fLabelHeight + 5) + self.setMaximumSize(self.fPixmapBaseSize, self.fPixmapBaseSize + self.fLabelHeight + 5) - self.fLabelWidth = QFontMetrics(self.fLabelFont).width(label) + if not self.fLabel: + self.fLabelHeight = 0 + self.fLabelWidth = 0 + return + + self.fLabelWidth = QFontMetrics(self.fLabelFont).width(self.fLabel) self.fLabelHeight = QFontMetrics(self.fLabelFont).height() - self.fLabelPos.setX(float(self.fSize)/2.0 - float(self.fLabelWidth)/2.0) - self.fLabelPos.setY(self.fSize + self.fLabelHeight) + self.fLabelPos.setX(float(self.fPixmapBaseSize)/2.0 - float(self.fLabelWidth)/2.0) + + if self.fPixmapNum in ("01", "02"): + self.fLabelPos.setY(self.fPixmapBaseSize + self.fLabelHeight) + else: + self.fLabelPos.setY(self.fPixmapBaseSize + self.fLabelHeight/2) + + self.fLabelGradient.setStart(0, float(self.fPixmapBaseSize)/2.0) + self.fLabelGradient.setFinalStop(0, self.fPixmapBaseSize + self.fLabelHeight + 5) + + self.fLabelGradientRect = QRectF(float(self.fPixmapBaseSize)/8.0, float(self.fPixmapBaseSize)/2.0, float(self.fPixmapBaseSize*3)/4.0, self.fPixmapBaseSize+self.fLabelHeight+5) + + def setCustomPaintMode(self, paintMode): + if self.fCustomPaintMode == paintMode: + return + + self.fCustomPaintMode = paintMode + self.update() + + def setCustomPaintColor(self, color): + if self.fCustomPaintColor == color: + return + + self.fCustomPaintColor = color + self.update() + + def setLabel(self, label): + if self.fLabel == label: + return + + self.fLabel = label + self.updateSizes() + self.update() + + def setEnabled(self, enabled): + if self.isEnabled() == enabled: + return - self.fLabelGradient.setColorAt(0.0, self.fColor1) - self.fLabelGradient.setColorAt(0.6, self.fColor1) - self.fLabelGradient.setColorAt(1.0, self.fColor2) + QDial.setEnabled(self, enabled) - self.fLabelGradient.setStart(0, float(self.fSize)/2.0) - self.fLabelGradient.setFinalStop(0, self.fSize + self.fLabelHeight + 5) + self.fPixmap.load(":/bitmaps/dial_%s%s.png" % (self.fPixmapNum, "" if enabled else "d")) + self.updateSizes() + self.update() - self.fLabelGradientRect = QRectF(float(self.fSize)/8.0, float(self.fSize)/2.0, float(self.fSize*6)/8.0, self.fSize+self.fLabelHeight+5) - #self.update() + def setIndex(self, index): + self.fIndex = index def setPixmap(self, pixmapId): self.fPixmapNum = "%02i" % pixmapId self.fPixmap.load(":/bitmaps/dial_%s%s.png" % (self.fPixmapNum, "" if self.isEnabled() else "d")) if self.fPixmap.width() > self.fPixmap.height(): - self.fOrientation = self.HORIZONTAL + self.fPixmapOrientation = self.HORIZONTAL else: - self.fOrientation = self.VERTICAL + self.fPixmapOrientation = self.VERTICAL - self.updateSizes() - #self.update() + # special pixmaps + if self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_NULL: + # reserved for carla-wet, carla-vol, carla-pan and color + if self.fPixmapNum == "03": + self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_COLOR - def setWhiteText(self): - self.fColor1 = QColor(0, 0, 0, 255) - self.fColor2 = QColor(0, 0, 0, 0) - self.fColorT = [Qt.white, Qt.darkGray] + # reserved for carla-L and carla-R + elif self.fPixmapNum == "04": + self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_CARLA_L - def setMidWhiteText(self): - self.fColor1 = QColor(0, 0, 0, 255) - self.fColor2 = QColor(0, 0, 0, 0) - self.fColorT = [QColor("#BBB"), Qt.darkGray] + # reserved for zita + elif self.fPixmapNum == "06": + self.fCustomPaintMode = self.CUSTOM_PAINT_MODE_ZITA - def minimumSizeHint(self): - return QSize(self.fSize, self.fSize) + self.updateSizes() + self.update() - def sizeHint(self): - return QSize(self.fSize, self.fSize) + def setMinimum(self, value): + self.fMinimum = value - def updateSizes(self): - self.fWidth = self.fPixmap.width() - self.fHeight = self.fPixmap.height() + def setMaximum(self, value): + self.fMaximum = value - if self.fWidth < 1: - self.fWidth = 1 + def setValue(self, value): + if self.fRealValue == value: + return - if self.fHeight < 1: - self.fHeight = 1 + self.fRealValue = value + normValue = float(value - self.fMinimum) / float(self.fMaximum - self.fMinimum) + QDial.setValue(self, int(normValue * 10000)) - if self.fOrientation == self.HORIZONTAL: - self.fSize = self.fHeight - self.fCount = self.fWidth / self.fHeight - else: - self.fSize = self.fWidth - self.fCount = self.fHeight / self.fWidth + @pyqtSlot(int) + def slot_valueChanged(self, value): + self.fRealValue = float(value)/10000.0 * (self.fMaximum - self.fMinimum) + self.fMinimum + self.realValueChanged.emit(self.fRealValue) - self.setMinimumSize(self.fSize, self.fSize + self.fLabelHeight + 5) - self.setMaximumSize(self.fSize, self.fSize + self.fLabelHeight + 5) + def minimumSizeHint(self): + return QSize(self.fPixmapBaseSize, self.fPixmapBaseSize) + + def sizeHint(self): + return QSize(self.fPixmapBaseSize, self.fPixmapBaseSize) def enterEvent(self, event): self.fIsHovered = True @@ -209,39 +280,33 @@ class PixmapDial(QDial): painter.setRenderHint(QPainter.Antialiasing, True) if self.fLabel: - if self.fCustomPaint == self.CUSTOM_PAINT_NULL: - painter.setPen(self.fColor2) + if self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_NULL: + painter.setPen(self.fLabelGradientColor2) painter.setBrush(self.fLabelGradient) painter.drawRect(self.fLabelGradientRect) painter.setFont(self.fLabelFont) - painter.setPen(self.fColorT[0 if self.isEnabled() else 1]) + painter.setPen(self.fLabelGradientColorT[0 if self.isEnabled() else 1]) painter.drawText(self.fLabelPos, self.fLabel) if self.isEnabled(): - current = float(self.value() - self.minimum()) - divider = float(self.maximum() - self.minimum()) - - if divider == 0.0: - return + normValue = float(self.fRealValue - self.fMinimum) / float(self.fMaximum - self.fMinimum) + target = QRectF(0.0, 0.0, self.fPixmapBaseSize, self.fPixmapBaseSize) - value = current / divider - target = QRectF(0.0, 0.0, self.fSize, self.fSize) + curLayer = int((self.fPixmapLayersCount - 1) * normValue) - per = int((self.fCount - 1) * value) - - if self.fOrientation == self.HORIZONTAL: - xpos = self.fSize * per + if self.fPixmapOrientation == self.HORIZONTAL: + xpos = self.fPixmapBaseSize * curLayer ypos = 0.0 else: xpos = 0.0 - ypos = self.fSize * per + ypos = self.fPixmapBaseSize * curLayer - source = QRectF(xpos, ypos, self.fSize, self.fSize) + source = QRectF(xpos, ypos, self.fPixmapBaseSize, self.fPixmapBaseSize) painter.drawPixmap(target, self.fPixmap, source) # Custom knobs (Dry/Wet and Volume) - if self.fCustomPaint in (self.CUSTOM_PAINT_CARLA_WET, self.CUSTOM_PAINT_CARLA_VOL): + if self.fCustomPaintMode in (self.CUSTOM_PAINT_MODE_CARLA_WET, self.CUSTOM_PAINT_MODE_CARLA_VOL): # knob color colorGreen = QColor(0x5D, 0xE7, 0x3D).lighter(100 + self.fHoverStep*6) colorBlue = QColor(0x3E, 0xB8, 0xBE).lighter(100 + self.fHoverStep*6) @@ -251,15 +316,15 @@ class PixmapDial(QDial): ballPath = QPainterPath() ballPath.addEllipse(ballRect) #painter.drawRect(ballRect) - tmpValue = (0.375 + 0.75*value) + tmpValue = (0.375 + 0.75*normValue) ballValue = tmpValue - floor(tmpValue) ballPoint = ballPath.pointAtPercent(ballValue) # draw arc startAngle = 216*16 - spanAngle = -252*16*value + spanAngle = -252*16*normValue - if self.fCustomPaint == self.CUSTOM_PAINT_CARLA_WET: + if self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_CARLA_WET: painter.setBrush(colorBlue) painter.setPen(QPen(colorBlue, 0)) painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2)) @@ -285,7 +350,7 @@ class PixmapDial(QDial): painter.drawArc(4.0, 4.0, 26.0, 26.0, startAngle, spanAngle) # Custom knobs (L and R) - elif self.fCustomPaint in (self.CUSTOM_PAINT_CARLA_L, self.CUSTOM_PAINT_CARLA_R): + elif self.fCustomPaintMode in (self.CUSTOM_PAINT_MODE_CARLA_L, self.CUSTOM_PAINT_MODE_CARLA_R): # knob color color = QColor(0xAD, 0xD5, 0x48).lighter(100 + self.fHoverStep*6) @@ -294,7 +359,7 @@ class PixmapDial(QDial): ballPath = QPainterPath() ballPath.addEllipse(ballRect) #painter.drawRect(ballRect) - tmpValue = (0.375 + 0.75*value) + tmpValue = (0.375 + 0.75*normValue) ballValue = tmpValue - floor(tmpValue) ballPoint = ballPath.pointAtPercent(ballValue) @@ -303,34 +368,32 @@ class PixmapDial(QDial): painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.0, 2.0)) # draw arc - if self.fCustomPaint == self.CUSTOM_PAINT_CARLA_L: + if self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_CARLA_L: startAngle = 216*16 - spanAngle = -252.0*16*value - elif self.fCustomPaint == self.CUSTOM_PAINT_CARLA_R: - startAngle = 324.0*16 - spanAngle = 252.0*16*(1.0-value) + spanAngle = -252.0*16*normValue else: - return + startAngle = 324.0*16 + spanAngle = 252.0*16*(1.0-normValue) painter.setPen(QPen(color, 2)) painter.drawArc(3.5, 4.5, 22.0, 22.0, startAngle, spanAngle) # Custom knobs (Color) - elif self.fCustomPaint == self.CUSTOM_PAINT_COLOR: + elif self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_COLOR: # knob color - color = self.fCustomColor.lighter(100 + self.fHoverStep*6) + color = self.fCustomPaintColor.lighter(100 + self.fHoverStep*6) # draw small circle ballRect = QRectF(8.0, 8.0, 15.0, 15.0) ballPath = QPainterPath() ballPath.addEllipse(ballRect) - tmpValue = (0.375 + 0.75*value) + tmpValue = (0.375 + 0.75*normValue) ballValue = tmpValue - floor(tmpValue) ballPoint = ballPath.pointAtPercent(ballValue) # draw arc startAngle = 216*16 - spanAngle = -252*16*value + spanAngle = -252*16*normValue painter.setBrush(color) painter.setPen(QPen(color, 0)) @@ -341,8 +404,8 @@ class PixmapDial(QDial): painter.drawArc(4.0, 4.0, 26.0, 26.0, startAngle, spanAngle) # Custom knobs (Zita) - elif self.fCustomPaint == self.CUSTOM_PAINT_ZITA: - a = value * pi * 1.5 - 2.35 + elif self.fCustomPaintMode == self.CUSTOM_PAINT_MODE_ZITA: + a = normValue * pi * 1.5 - 2.35 r = 10.0 x = 10.5 y = 10.5 @@ -362,11 +425,30 @@ class PixmapDial(QDial): QTimer.singleShot(20, self.update) else: # isEnabled() - target = QRectF(0.0, 0.0, self.fSize, self.fSize) + target = QRectF(0.0, 0.0, self.fPixmapBaseSize, self.fPixmapBaseSize) painter.drawPixmap(target, self.fPixmap, target) painter.restore() def resizeEvent(self, event): - self.updateSizes() QDial.resizeEvent(self, event) + self.updateSizes() + +# ------------------------------------------------------------------------------------------------------------ +# Main Testing + +if __name__ == '__main__': + import sys + from PyQt4.QtGui import QApplication + import resources_rc + + app = QApplication(sys.argv) + + gui = PixmapDial(None) + #gui.setEnabled(True) + #gui.setEnabled(False) + gui.setPixmap(3) + gui.setLabel("hahaha") + gui.show() + + sys.exit(app.exec_())