Commit 498e4c42 authored by Andy Regensky's avatar Andy Regensky
Browse files

Extend SlidableLineEdit configuration with support for float/double value inputs

parent 5f577079
...@@ -56,36 +56,36 @@ class PropertiesWidget(QWidget): ...@@ -56,36 +56,36 @@ class PropertiesWidget(QWidget):
self.sensorSizeLabel = QLabel(self) self.sensorSizeLabel = QLabel(self)
self.sensorSizeLabel.setText("Sensor height in mm") self.sensorSizeLabel.setText("Sensor height in mm")
self.sensorSizeHeightEdit = QLineEdit(self) self.sensorSizeHeightEdit = SlidableLineEdit(self, 0.01)
self.sensorSizeHeightEdit.setValidator(doubleValidator) self.sensorSizeHeightEdit.setValidator(doubleValidator)
self.sensorSizeHeightEdit.editingFinished.connect(self.sensorSizeHeightEditingFinished) self.sensorSizeHeightEdit.editingFinished.connect(self.sensorSizeHeightEditingFinished)
self.resolutionLabel = QLabel(self) self.resolutionLabel = QLabel(self)
self.resolutionLabel.setText("Sensor resolution") self.resolutionLabel.setText("Sensor resolution")
self.resolutionWidthEdit = SlidableLineEdit(self) self.resolutionWidthEdit = SlidableLineEdit(self, 0.1)
self.resolutionWidthEdit.setValidator(intValidator) self.resolutionWidthEdit.setValidator(intValidator)
self.resolutionWidthEdit.editingFinished.connect(self.resolutionWidthEditingFinished) self.resolutionWidthEdit.editingFinished.connect(self.resolutionWidthEditingFinished)
self.resolutionHeightEdit = SlidableLineEdit(self) self.resolutionHeightEdit = SlidableLineEdit(self, 0.1)
self.resolutionHeightEdit.setValidator(intValidator) self.resolutionHeightEdit.setValidator(intValidator)
self.resolutionHeightEdit.editingFinished.connect(self.resolutionHeightEditingFinished) self.resolutionHeightEdit.editingFinished.connect(self.resolutionHeightEditingFinished)
self.opticalCenterLabel = QLabel(self) self.opticalCenterLabel = QLabel(self)
self.opticalCenterLabel.setText("Optical center") self.opticalCenterLabel.setText("Optical center")
self.opticalCenterXEdit = QLineEdit(self) self.opticalCenterXEdit = SlidableLineEdit(self, 0.1)
self.opticalCenterXEdit.setValidator(doubleValidator) self.opticalCenterXEdit.setValidator(doubleValidator)
self.opticalCenterXEdit.editingFinished.connect(self.opticalCenterXEditingFinished) self.opticalCenterXEdit.editingFinished.connect(self.opticalCenterXEditingFinished)
self.opticalCenterYEdit = QLineEdit(self) self.opticalCenterYEdit = SlidableLineEdit(self, 0.1)
self.opticalCenterYEdit.setValidator(doubleValidator) self.opticalCenterYEdit.setValidator(doubleValidator)
self.opticalCenterYEdit.editingFinished.connect(self.opticalCenterYEditingFinished) self.opticalCenterYEdit.editingFinished.connect(self.opticalCenterYEditingFinished)
self.focalLengthLabel = QLabel(self) self.focalLengthLabel = QLabel(self)
self.focalLengthLabel.setText("Focal length in mm") self.focalLengthLabel.setText("Focal length in mm")
self.focalLengthEdit = QLineEdit(self) self.focalLengthEdit = SlidableLineEdit(self, 0.01)
self.focalLengthEdit.setValidator(doubleValidator) self.focalLengthEdit.setValidator(doubleValidator)
self.focalLengthEdit.editingFinished.connect(self.focalLengthEditingFinished) self.focalLengthEdit.editingFinished.connect(self.focalLengthEditingFinished)
...@@ -99,22 +99,22 @@ class PropertiesWidget(QWidget): ...@@ -99,22 +99,22 @@ class PropertiesWidget(QWidget):
self.originLabel = QLabel(self) self.originLabel = QLabel(self)
self.originLabel.setText("Origin") self.originLabel.setText("Origin")
self.originXEdit = SlidableLineEdit(self) self.originXEdit = SlidableLineEdit(self, 0.1)
self.originXEdit.setValidator(intValidator) self.originXEdit.setValidator(intValidator)
self.originXEdit.editingFinished.connect(self.originXEditingFinished) self.originXEdit.editingFinished.connect(self.originXEditingFinished)
self.originYEdit = SlidableLineEdit(self) self.originYEdit = SlidableLineEdit(self, 0.1)
self.originYEdit.setValidator(intValidator) self.originYEdit.setValidator(intValidator)
self.originYEdit.editingFinished.connect(self.originYEditingFinished) self.originYEdit.editingFinished.connect(self.originYEditingFinished)
self.blocksizeLabel = QLabel(self) self.blocksizeLabel = QLabel(self)
self.blocksizeLabel.setText("Blocksize") self.blocksizeLabel.setText("Blocksize")
self.blocksizeWidthEdit = SlidableLineEdit(self) self.blocksizeWidthEdit = SlidableLineEdit(self, 0.1)
self.blocksizeWidthEdit.setValidator(intValidator) self.blocksizeWidthEdit.setValidator(intValidator)
self.blocksizeWidthEdit.editingFinished.connect(self.blocksizeWidthEditingFinished) self.blocksizeWidthEdit.editingFinished.connect(self.blocksizeWidthEditingFinished)
self.blocksizeHeightEdit = SlidableLineEdit(self) self.blocksizeHeightEdit = SlidableLineEdit(self, 0.1)
self.blocksizeHeightEdit.setValidator(intValidator) self.blocksizeHeightEdit.setValidator(intValidator)
self.blocksizeHeightEdit.editingFinished.connect(self.blocksizeHeightEditingFinished) self.blocksizeHeightEdit.editingFinished.connect(self.blocksizeHeightEditingFinished)
...@@ -135,33 +135,33 @@ class PropertiesWidget(QWidget): ...@@ -135,33 +135,33 @@ class PropertiesWidget(QWidget):
self.motionVector0Label = QLabel(self) self.motionVector0Label = QLabel(self)
self.motionVector0Label.setText("Motion Vector") self.motionVector0Label.setText("Motion Vector")
self.motionVectorX0Edit = SlidableLineEdit(self) self.motionVectorX0Edit = SlidableLineEdit(self, 0.1)
self.motionVectorX0Edit.setValidator(negIntValidator) self.motionVectorX0Edit.setValidator(negIntValidator)
self.motionVectorX0Edit.editingFinished.connect(self.motionVectorX0EditingFinished) self.motionVectorX0Edit.editingFinished.connect(self.motionVectorX0EditingFinished)
self.motionVectorY0Edit = SlidableLineEdit(self) self.motionVectorY0Edit = SlidableLineEdit(self, 0.1)
self.motionVectorY0Edit.setValidator(negIntValidator) self.motionVectorY0Edit.setValidator(negIntValidator)
self.motionVectorY0Edit.editingFinished.connect(self.motionVectorY0EditingFinished) self.motionVectorY0Edit.editingFinished.connect(self.motionVectorY0EditingFinished)
self.motionVector1Label = QLabel(self) self.motionVector1Label = QLabel(self)
self.motionVector1Label.setText("CP1 Motion Vector") self.motionVector1Label.setText("CP1 Motion Vector")
self.motionVectorX1Edit = SlidableLineEdit(self) self.motionVectorX1Edit = SlidableLineEdit(self, 0.1)
self.motionVectorX1Edit.setValidator(negIntValidator) self.motionVectorX1Edit.setValidator(negIntValidator)
self.motionVectorX1Edit.editingFinished.connect(self.motionVectorX1EditingFinished) self.motionVectorX1Edit.editingFinished.connect(self.motionVectorX1EditingFinished)
self.motionVectorY1Edit = SlidableLineEdit(self) self.motionVectorY1Edit = SlidableLineEdit(self, 0.1)
self.motionVectorY1Edit.setValidator(negIntValidator) self.motionVectorY1Edit.setValidator(negIntValidator)
self.motionVectorY1Edit.editingFinished.connect(self.motionVectorY1EditingFinished) self.motionVectorY1Edit.editingFinished.connect(self.motionVectorY1EditingFinished)
self.motionVector2Label = QLabel(self) self.motionVector2Label = QLabel(self)
self.motionVector2Label.setText("CP2 Motion Vector") self.motionVector2Label.setText("CP2 Motion Vector")
self.motionVectorX2Edit = SlidableLineEdit(self) self.motionVectorX2Edit = SlidableLineEdit(self, 0.1)
self.motionVectorX2Edit.setValidator(negIntValidator) self.motionVectorX2Edit.setValidator(negIntValidator)
self.motionVectorX2Edit.editingFinished.connect(self.motionVectorX2EditingFinished) self.motionVectorX2Edit.editingFinished.connect(self.motionVectorX2EditingFinished)
self.motionVectorY2Edit = SlidableLineEdit(self) self.motionVectorY2Edit = SlidableLineEdit(self, 0.1)
self.motionVectorY2Edit.setValidator(negIntValidator) self.motionVectorY2Edit.setValidator(negIntValidator)
self.motionVectorY2Edit.editingFinished.connect(self.motionVectorY2EditingFinished) self.motionVectorY2Edit.editingFinished.connect(self.motionVectorY2EditingFinished)
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
from PySide2.QtCore import Qt from PySide2.QtCore import Qt
from PySide2.QtWidgets import QLineEdit from PySide2.QtWidgets import QLineEdit
from PySide2.QtGui import QValidator, QDoubleValidator
class SlidableLineEdit(QLineEdit): class SlidableLineEdit(QLineEdit):
def __init__(self, parent): def __init__(self, parent, step):
super().__init__(parent) super().__init__(parent)
self.step = step
self.lastCursor = None self.lastCursor = None
self.initialValue = None self.initialValue = None
self.initialMouseX = None self.initialMouseX = None
...@@ -44,14 +46,19 @@ class SlidableLineEdit(QLineEdit): ...@@ -44,14 +46,19 @@ class SlidableLineEdit(QLineEdit):
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
self.lastCursor = self.cursor() self.lastCursor = self.cursor()
self.setCursor(Qt.SizeHorCursor) self.setCursor(Qt.SizeHorCursor)
self.initialValue = int(self.text()) self.initialValue = float(self.text()) if isinstance(self.validator(), QDoubleValidator) else int(self.text())
self.initialMouseX = event.pos().x() self.initialMouseX = event.pos().x()
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
if self.initialMouseX is not None: if self.initialMouseX is not None:
deltaX = int((event.pos().x() - self.initialMouseX) * 0.25) if isinstance(self.validator(), QDoubleValidator):
self.setText(str(self.initialValue + deltaX)) deltaX = float((event.pos().x() - self.initialMouseX) * self.step)
self.editingFinished.emit() else:
deltaX = int((event.pos().x() - self.initialMouseX) * self.step)
slidedText = str(self.initialValue + deltaX)
if self.validator().validate(slidedText, 0)[0] == QValidator.Acceptable:
self.setText(str(self.initialValue + deltaX))
self.editingFinished.emit()
def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment