x/y pixel values update to match output resolution
This commit is contained in:
parent
3c1b52205f
commit
5784cdbcf8
|
@ -6,6 +6,7 @@ from PyQt5 import uic, QtCore, QtWidgets
|
|||
from PyQt5.QtGui import QColor
|
||||
import os
|
||||
import sys
|
||||
import math
|
||||
import time
|
||||
|
||||
from toolkit.frame import BlankFrame
|
||||
|
@ -176,7 +177,9 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass):
|
|||
self._presetNames = {}
|
||||
self._commandArgs = {}
|
||||
self._colorWidgets = {}
|
||||
self._colorFuncs = {}
|
||||
self._relativeWidgets = {}
|
||||
self._relativeValues = {}
|
||||
self._lockedProperties = None
|
||||
self._lockedError = None
|
||||
|
||||
|
@ -291,14 +294,44 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass):
|
|||
'''
|
||||
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:
|
||||
|
|
|
@ -60,6 +60,9 @@ class Component(Component):
|
|||
}, colorWidgets={
|
||||
'color1': self.page.pushButton_color1,
|
||||
'color2': self.page.pushButton_color2,
|
||||
}, relativeWidgets={
|
||||
'x': 'x',
|
||||
'y': 'y',
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -28,6 +28,9 @@ class Component(Component):
|
|||
'imagePath': 'image',
|
||||
'xPosition': 'x',
|
||||
'yPosition': 'y',
|
||||
}, relativeWidgets={
|
||||
'xPosition': 'x',
|
||||
'yPosition': 'y',
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ class Component(Component):
|
|||
'y': self.page.spinBox_y,
|
||||
}, colorWidgets={
|
||||
'visColor': self.page.pushButton_visColor,
|
||||
}, relativeWidgets={
|
||||
'y': 'y',
|
||||
})
|
||||
|
||||
def previewRender(self):
|
||||
|
|
|
@ -49,6 +49,9 @@ class Component(Component):
|
|||
'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():
|
||||
|
|
|
@ -17,15 +17,12 @@ class Component(Component):
|
|||
|
||||
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")
|
||||
|
@ -35,8 +32,11 @@ class Component(Component):
|
|||
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
|
||||
|
@ -50,6 +50,9 @@ class Component(Component):
|
|||
'yPosition': self.page.spinBox_yTextAlign,
|
||||
}, colorWidgets={
|
||||
'textColor': self.page.pushButton_textColor,
|
||||
}, relativeWidgets={
|
||||
'xPosition': 'x',
|
||||
'yPosition': 'y',
|
||||
})
|
||||
|
||||
def update(self):
|
||||
|
|
|
@ -38,6 +38,9 @@ class Component(Component):
|
|||
'loopVideo': 'loop',
|
||||
'xPosition': 'x',
|
||||
'yPosition': 'y',
|
||||
}, relativeWidgets={
|
||||
'xPosition': 'x',
|
||||
'yPosition': 'y',
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@ class Component(Component):
|
|||
'mono': self.page.checkBox_mono,
|
||||
}, colorWidgets={
|
||||
'color': self.page.pushButton_color,
|
||||
}, relativeWidgets={
|
||||
'x': 'x',
|
||||
'y': 'y',
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -644,9 +644,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
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'''
|
||||
|
|
Reference in New Issue