Browse Source

Implement custom canvas sizes in the preview frame

tags/1.9.4
falkTX 10 years ago
parent
commit
ca359f9cd0
4 changed files with 75 additions and 79 deletions
  1. +1
    -1
      resources/ui/carla_host.ui
  2. +8
    -0
      source/carla
  3. +3
    -2
      source/carla_patchbay.py
  4. +63
    -76
      source/widgets/canvaspreviewframe.py

+ 1
- 1
resources/ui/carla_host.ui View File

@@ -153,7 +153,7 @@
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>210</width>
<width>16777215</width>
<height>162</height> <height>162</height>
</size> </size>
</property> </property>


+ 8
- 0
source/carla View File

@@ -148,6 +148,14 @@ class CarlaMultiW(QTabWidget):
self.fPatchbay.resize(self.fRack.size()) self.fPatchbay.resize(self.fRack.size())
self.fPatchbay.slot_miniCanvasCheckSize() self.fPatchbay.slot_miniCanvasCheckSize()


#def paintEvent(self, event):
#QTabWidget.paintEvent(self, event)

#painter = QPainter(self)
#painter.setBrush(QColor(36, 36, 36))
#painter.setPen(QColor(62, 62, 62))
#painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)

def resizeEvent(self, event): def resizeEvent(self, event):
QTabWidget.resizeEvent(self, event) QTabWidget.resizeEvent(self, event)




+ 3
- 2
source/carla_patchbay.py View File

@@ -339,8 +339,8 @@ class CarlaPatchbayW(QGraphicsView):
@pyqtSlot(float, float) @pyqtSlot(float, float)
def slot_miniCanvasMoved(self, xp, yp): def slot_miniCanvasMoved(self, xp, yp):
self.fMovingViaMiniCanvas = True self.fMovingViaMiniCanvas = True
self.horizontalScrollBar().setValue(xp * self.fCanvasWidth)
self.verticalScrollBar().setValue(yp * self.fCanvasHeight)
self.horizontalScrollBar().setValue(xp * self.horizontalScrollBar().maximum())
self.verticalScrollBar().setValue(yp * self.verticalScrollBar().maximum())
self.fMovingViaMiniCanvas = False self.fMovingViaMiniCanvas = False
self.updateCanvasInitialPos() self.updateCanvasInitialPos()


@@ -451,6 +451,7 @@ class CarlaPatchbayW(QGraphicsView):


self.setupCanvas() self.setupCanvas()
self.fParent.updateContainer(self.themeData) self.fParent.updateContainer(self.themeData)
self.slot_miniCanvasCheckAll()


if Carla.host.is_engine_running(): if Carla.host.is_engine_running():
Carla.host.patchbay_refresh() Carla.host.patchbay_refresh()


+ 63
- 76
source/widgets/canvaspreviewframe.py View File

@@ -36,43 +36,42 @@ iHeight = 3
class CanvasPreviewFrame(QFrame): class CanvasPreviewFrame(QFrame):
miniCanvasMoved = pyqtSignal(float, float) miniCanvasMoved = pyqtSignal(float, float)


# x = 2
# y = 2
# w = width-4
# h = height-3
# bounds -1 px

kInternalWidth = 210-6 # -4 for width + -1px*2 bounds
kInternalHeight = 162-5 # -3 for height + -1px*2 bounds

def __init__(self, parent): def __init__(self, parent):
QFrame.__init__(self, parent) QFrame.__init__(self, parent)


#self.setMinimumWidth(210)
#self.setMinimumHeight(162)
#self.setMaximumHeight(162)

self.fRealParent = None

self.fScene = None
self.fRenderSource = QRectF(0.0, 0.0, 0.0, 0.0)
self.fRenderTarget = QRectF(0.0, 0.0, 0.0, 0.0)
self.fUseCustomPaint = False self.fUseCustomPaint = False


self.fMouseDown = False
self.fInitialX = 0.0
self.fScale = 1.0


self.fViewBg = QColor(0, 0, 0) self.fViewBg = QColor(0, 0, 0)
self.fViewBrush = QBrush(QColor(75, 75, 255, 30)) self.fViewBrush = QBrush(QColor(75, 75, 255, 30))
self.fViewPen = QPen(Qt.blue, 1) self.fViewPen = QPen(Qt.blue, 1)
self.fViewRect = [3.0, 3.0, 10.0, 10.0]


self.fScale = 1.0
self.fScene = None

self.fRealParent = None
self.fFakeWidth = 0.0
self.fFakeHeight = 0.0

self.fRenderSource = self.getRenderSource()
self.fRenderTarget = QRectF(0, 0, 0, 0)

self.fViewPadX = 0.0
self.fViewPadY = 0.0
self.fViewRect = [0.0, 0.0, 10.0, 10.0]
self.fMouseDown = False


def init(self, scene, realWidth, realHeight, useCustomPaint = False): def init(self, scene, realWidth, realHeight, useCustomPaint = False):
padding = 6

self.fScene = scene self.fScene = scene
self.fFakeWidth = float(realWidth) / 15.0
self.fFakeHeight = float(realHeight) / 15.0

self.setMinimumSize(self.fFakeWidth+padding, self.fFakeHeight+padding)
self.setMaximumSize(self.fFakeWidth*4+padding, self.fFakeHeight+padding)

self.fRenderTarget.setWidth(realWidth)
self.fRenderTarget.setHeight(realHeight)
self.fRenderSource = QRectF(0.0, 0.0, float(realWidth), float(realHeight))


if self.fUseCustomPaint != useCustomPaint: if self.fUseCustomPaint != useCustomPaint:
self.fUseCustomPaint = useCustomPaint self.fUseCustomPaint = useCustomPaint
@@ -81,21 +80,12 @@ class CanvasPreviewFrame(QFrame):
def setRealParent(self, parent): def setRealParent(self, parent):
self.fRealParent = parent self.fRealParent = parent


def getRenderSource(self):
xPadding = (float(self.width()) - self.fFakeWidth) / 2.0
yPadding = (float(self.height()) - self.fFakeHeight) / 2.0
return QRectF(xPadding, yPadding, self.fFakeWidth, self.fFakeHeight)

def setViewPosX(self, xp): def setViewPosX(self, xp):
x = self.fFakeWidth*xp
xRatio = (x / self.fFakeWidth) * self.fViewRect[iWidth] / self.fScale
self.fViewRect[iX] = x - xRatio + self.fRenderSource.x()
self.fViewRect[iX] = (xp * self.kInternalWidth) - (xp * (self.fViewRect[iWidth]/self.fScale)) + xp
self.update() self.update()


def setViewPosY(self, yp): def setViewPosY(self, yp):
y = self.fFakeHeight*yp
yRatio = (y / self.fFakeHeight) * self.fViewRect[iHeight] / self.fScale
self.fViewRect[iY] = y - yRatio + self.fRenderSource.y()
self.fViewRect[iY] = (yp * self.kInternalHeight) - (yp * (self.fViewRect[iHeight]/self.fScale)) + yp
self.update() self.update()


def setViewScale(self, scale): def setViewScale(self, scale):
@@ -105,8 +95,8 @@ class CanvasPreviewFrame(QFrame):
QTimer.singleShot(0, self.fRealParent.slot_miniCanvasCheckAll) QTimer.singleShot(0, self.fRealParent.slot_miniCanvasCheckAll)


def setViewSize(self, width, height): def setViewSize(self, width, height):
self.fViewRect[iWidth] = width * self.fFakeWidth
self.fViewRect[iHeight] = height * self.fFakeHeight
self.fViewRect[iWidth] = width * self.kInternalWidth
self.fViewRect[iHeight] = height * self.kInternalHeight
self.update() self.update()


def setViewTheme(self, bgColor, brushColor, penColor): def setViewTheme(self, bgColor, brushColor, penColor):
@@ -117,85 +107,81 @@ class CanvasPreviewFrame(QFrame):
self.fViewPen = QPen(penColor, 1) self.fViewPen = QPen(penColor, 1)


def handleMouseEvent(self, eventX, eventY): def handleMouseEvent(self, eventX, eventY):
x = float(eventX) - self.fRenderSource.x() - (self.fViewRect[iWidth] / self.fScale / 2)
y = float(eventY) - self.fRenderSource.y() - (self.fViewRect[iHeight] / self.fScale / 2)

maxWidth = self.fViewRect[iWidth] / self.fScale
maxHeight = self.fViewRect[iHeight] / self.fScale

if maxWidth > self.fFakeWidth:
maxWidth = self.fFakeWidth
if maxHeight > self.fFakeHeight:
maxHeight = self.fFakeHeight
x = float(eventX) - self.fInitialX
y = float(eventY) - 3.0


if x < 0.0: if x < 0.0:
x = 0.0 x = 0.0
elif x > self.fFakeWidth - maxWidth:
x = self.fFakeWidth - maxWidth
elif x > self.kInternalWidth:
x = float(self.kInternalWidth)


if y < 0.0: if y < 0.0:
y = 0.0 y = 0.0
elif y > self.fFakeHeight - maxHeight:
y = self.fFakeHeight - maxHeight
elif y > self.kInternalHeight:
y = float(self.kInternalHeight)

xp = x/self.kInternalWidth
yp = y/self.kInternalHeight


self.fViewRect[iX] = x + self.fRenderSource.x()
self.fViewRect[iY] = y + self.fRenderSource.y()
self.fViewRect[iX] = x - (xp * self.fViewRect[iWidth]/self.fScale) + xp
self.fViewRect[iY] = y - (yp * self.fViewRect[iHeight]/self.fScale) + yp
self.update() self.update()


self.miniCanvasMoved.emit(x * self.fScale / self.fFakeWidth, y * self.fScale / self.fFakeHeight)
self.miniCanvasMoved.emit(xp, yp)


def mousePressEvent(self, event): def mousePressEvent(self, event):
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
self.fMouseDown = True self.fMouseDown = True
self.setCursor(QCursor(Qt.SizeAllCursor)) self.setCursor(QCursor(Qt.SizeAllCursor))
self.handleMouseEvent(event.x(), event.y()) self.handleMouseEvent(event.x(), event.y())
event.accept()
return event.accept()
QFrame.mouseMoveEvent(self, event)


def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
if self.fMouseDown: if self.fMouseDown:
self.handleMouseEvent(event.x(), event.y()) self.handleMouseEvent(event.x(), event.y())
event.accept()
return event.accept()
QFrame.mouseMoveEvent(self, event)


def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
if self.fMouseDown: if self.fMouseDown:
self.setCursor(QCursor(Qt.ArrowCursor)) self.setCursor(QCursor(Qt.ArrowCursor))
self.fMouseDown = False
self.fMouseDown = False
return event.accept()
QFrame.mouseReleaseEvent(self, event) QFrame.mouseReleaseEvent(self, event)


def paintEvent(self, event): def paintEvent(self, event):
painter = QPainter(self) painter = QPainter(self)


if self.fUseCustomPaint: if self.fUseCustomPaint:
painter.setBrush(self.fViewBg)
painter.setPen(QColor(12, 12, 12))
painter.drawRect(0, 0, self.width(), self.height()-2)

painter.setBrush(QColor(36, 36, 36)) painter.setBrush(QColor(36, 36, 36))
painter.setPen(QColor(62, 62, 62)) painter.setPen(QColor(62, 62, 62))
painter.drawRect(1, 1, self.width()-2, self.height()-4)

painter.setBrush(self.fViewBg)
painter.setPen(self.fViewBg)
painter.drawRect(2, 3, self.width()-5, self.height()-7)
painter.drawRect(2, 2, self.width()-4, self.height()-3)


#painter.setBrush(self.fViewBg)
#painter.setPen(self.fViewBg)
painter.setBrush(QColor(62, 62, 255))
painter.setPen(QColor(62, 62, 255))
painter.drawRect(3, 3, self.width()-6, self.height()-6)
else: else:
painter.setBrush(self.fViewBg) painter.setBrush(self.fViewBg)
painter.setPen(self.fViewBg) painter.setPen(self.fViewBg)
painter.drawRoundedRect(2, 2, self.width()-6, self.height()-6, 3, 3)
painter.drawRoundedRect(3, 3, self.width()-6, self.height()-6, 3, 3)


self.fScene.render(painter, self.fRenderSource, self.fRenderTarget, Qt.KeepAspectRatio)
self.fScene.render(painter, self.fRenderTarget, self.fRenderSource, Qt.KeepAspectRatio)


maxWidth = self.fViewRect[iWidth] / self.fScale
maxHeight = self.fViewRect[iHeight] / self.fScale
width = self.fViewRect[iWidth]/self.fScale
height = self.fViewRect[iHeight]/self.fScale


if maxWidth > self.fFakeWidth:
maxWidth = self.fFakeWidth
if maxHeight > self.fFakeHeight:
maxHeight = self.fFakeHeight
if width > self.kInternalWidth:
width = self.kInternalWidth
if height > self.kInternalHeight:
height = self.kInternalHeight


# cursor
painter.setBrush(self.fViewBrush) painter.setBrush(self.fViewBrush)
painter.setPen(self.fViewPen) painter.setPen(self.fViewPen)
painter.drawRect(self.fViewRect[iX], self.fViewRect[iY], maxWidth, maxHeight)
painter.drawRect(self.fViewRect[iX]+self.fInitialX, self.fViewRect[iY]+3, width, height)


if self.fUseCustomPaint: if self.fUseCustomPaint:
event.accept() event.accept()
@@ -203,7 +189,8 @@ class CanvasPreviewFrame(QFrame):
QFrame.paintEvent(self, event) QFrame.paintEvent(self, event)


def resizeEvent(self, event): def resizeEvent(self, event):
self.fRenderSource = self.getRenderSource()
self.fInitialX = float(self.width())/2.0 - float(self.kInternalWidth)/2.0
self.fRenderTarget = QRectF(self.fInitialX, 3.0, float(self.kInternalWidth), float(self.kInternalHeight))


if self.fRealParent is not None: if self.fRealParent is not None:
QTimer.singleShot(0, self.fRealParent.slot_miniCanvasCheckAll) QTimer.singleShot(0, self.fRealParent.slot_miniCanvasCheckAll)


Loading…
Cancel
Save