Skip to content

Commit

Permalink
x/y pixel values update to match output resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
tassaron committed Aug 2, 2017
1 parent 3c1b522 commit 5784cdb
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 12 deletions.
39 changes: 36 additions & 3 deletions src/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from PyQt5.QtGui import QColor
import os
import sys
import math
import time

from toolkit.frame import BlankFrame
Expand Down Expand Up @@ -176,7 +177,9 @@ def __init__(self, moduleIndex, compPos, core):
self._presetNames = {}
self._commandArgs = {}
self._colorWidgets = {}
self._colorFuncs = {}
self._relativeWidgets = {}
self._relativeValues = {}
self._lockedProperties = None
self._lockedError = None

Expand Down Expand Up @@ -291,14 +294,44 @@ def update(self):
'''
for attr, widget in self._trackedWidgets.items():
if attr in self._colorWidgets:
# Color Widgets: text stored as tuple & update the button color
rgbTuple = rgbFromString(widget.text())
setattr(self, attr, rgbTuple)
btnStyle = (
"QPushButton { background-color : %s; outline: none; }"
% QColor(*rgbTuple).name()
)
% QColor(*rgbTuple).name())
self._colorWidgets[attr].setStyleSheet(btnStyle)
setattr(self, attr, rgbTuple)

elif attr in self._relativeWidgets:
# Relative widgets: number scales to fit export resolution
if self._relativeWidgets[attr] == 'x':
dimension = self.width
else:
dimension = self.height
try:
oldUserValue = getattr(self, attr)
except AttributeError:
oldUserValue = self._trackedWidgets[attr].value()
newUserValue = self._trackedWidgets[attr].value()
newRelativeVal = newUserValue / dimension

if attr in self._relativeValues:
if oldUserValue == newUserValue:
oldRelativeVal = self._relativeValues[attr]
if oldRelativeVal != newRelativeVal:
# Float changed without pixel value changing, which
# means the pixel value needs to be updated
self._trackedWidgets[attr].blockSignals(True)
self._trackedWidgets[attr].setValue(
math.ceil(dimension * oldRelativeVal))
self._trackedWidgets[attr].blockSignals(False)
if oldUserValue != newUserValue \
or attr not in self._relativeValues:
self._relativeValues[attr] = newRelativeVal
setattr(self, attr, self._trackedWidgets[attr].value())

else:
# Normal tracked widget
setattr(self, attr, getWidgetValue(widget))

if not self.core.openingProject:
Expand Down
3 changes: 3 additions & 0 deletions src/components/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def widget(self, *args):
}, colorWidgets={
'color1': self.page.pushButton_color1,
'color2': self.page.pushButton_color2,
}, relativeWidgets={
'x': 'x',
'y': 'y',
},
)

Expand Down
3 changes: 3 additions & 0 deletions src/components/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def widget(self, *args):
'imagePath': 'image',
'xPosition': 'x',
'yPosition': 'y',
}, relativeWidgets={
'xPosition': 'x',
'yPosition': 'y',
},
)

Expand Down
2 changes: 2 additions & 0 deletions src/components/original.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def widget(self, *args):
'y': self.page.spinBox_y,
}, colorWidgets={
'visColor': self.page.pushButton_visColor,
}, relativeWidgets={
'y': 'y',
})

def previewRender(self):
Expand Down
3 changes: 3 additions & 0 deletions src/components/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def widget(self, *args):
'compress': self.page.checkBox_compress,
'mono': self.page.checkBox_mono,
'hue': self.page.spinBox_hue,
}, relativeWidgets={
'x': 'x',
'y': 'y',
}
)
for widget in self._trackedWidgets.values():
Expand Down
19 changes: 11 additions & 8 deletions src/components/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ def __init__(self, *args):

def widget(self, *args):
super().widget(*args)
height = int(self.settings.value('outputHeight'))
width = int(self.settings.value('outputWidth'))
# height = int(self.settings.value('outputHeight'))
# width = int(self.settings.value('outputWidth'))
self.textColor = (255, 255, 255)
self.title = 'Text'
self.alignment = 1
self.fontSize = height / 13.5
fm = QtGui.QFontMetrics(self.titleFont)
self.xPosition = width / 2 - fm.width(self.title)/2
self.yPosition = height / 2 * 1.036
self.fontSize = self.height / 13.5

self.page.comboBox_textAlign.addItem("Left")
self.page.comboBox_textAlign.addItem("Middle")
Expand All @@ -35,8 +32,11 @@ def widget(self, *args):
self.page.lineEdit_title.setText(self.title)
self.page.comboBox_textAlign.setCurrentIndex(int(self.alignment))
self.page.spinBox_fontSize.setValue(int(self.fontSize))
self.page.spinBox_xTextAlign.setValue(int(self.xPosition))
self.page.spinBox_yTextAlign.setValue(int(self.yPosition))

fm = QtGui.QFontMetrics(self.titleFont)
self.page.spinBox_xTextAlign.setValue(
self.width / 2 - fm.width(self.title)/2)
self.page.spinBox_yTextAlign.setValue(self.height / 2 * 1.036)

self.page.fontComboBox_titleFont.currentFontChanged.connect(
self.update
Expand All @@ -50,6 +50,9 @@ def widget(self, *args):
'yPosition': self.page.spinBox_yTextAlign,
}, colorWidgets={
'textColor': self.page.pushButton_textColor,
}, relativeWidgets={
'xPosition': 'x',
'yPosition': 'y',
})

def update(self):
Expand Down
3 changes: 3 additions & 0 deletions src/components/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def widget(self, *args):
'loopVideo': 'loop',
'xPosition': 'x',
'yPosition': 'y',
}, relativeWidgets={
'xPosition': 'x',
'yPosition': 'y',
}
)

Expand Down
3 changes: 3 additions & 0 deletions src/components/waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def widget(self, *args):
'mono': self.page.checkBox_mono,
}, colorWidgets={
'color': self.page.pushButton_color,
}, relativeWidgets={
'x': 'x',
'y': 'y',
}
)

Expand Down
5 changes: 4 additions & 1 deletion src/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,12 @@ def progressBarSetText(self, value):
def updateResolution(self):
resIndex = int(self.window.comboBox_resolution.currentIndex())
res = Core.resolutions[resIndex].split('x')
changed = res[0] != self.settings.value("outputWidth")
self.settings.setValue('outputWidth', res[0])
self.settings.setValue('outputHeight', res[1])
self.drawPreview()
if changed:
for i in range(len(self.core.selectedComponents)):
self.core.updateComponent(i)

def drawPreview(self, force=False, **kwargs):
'''Use autosave keyword arg to force saving or not saving if needed'''
Expand Down

0 comments on commit 5784cdb

Please sign in to comment.