[timeline] fix positionsing
This commit is contained in:
parent
7d3e3af498
commit
98b665ec3c
@ -21,7 +21,7 @@ class DetectionSceneSignals(QObject):
|
||||
itemsSelected = Signal(list)
|
||||
|
||||
class DetectionTimelineSignals(QObject):
|
||||
windowMoved = Signal((float, float))
|
||||
windowMoved = Signal()
|
||||
|
||||
class DetectionSignals(QObject):
|
||||
hover = Signal((int, QPointF))
|
||||
|
@ -3,8 +3,8 @@ import numpy as np
|
||||
import pandas as pd
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QGraphicsView, QGraphicsScene, QGraphicsItem, QGraphicsRectItem, QGraphicsLineItem
|
||||
from PySide6.QtCore import Qt, QPointF, QRectF, QPointF, QRectF
|
||||
from PySide6.QtGui import QPixmap, QBrush, QColor, QImage, QPen, QFont, QPainter
|
||||
from PySide6.QtCore import Qt, QRectF, QRectF
|
||||
from PySide6.QtGui import QBrush, QColor, QPen, QFont
|
||||
|
||||
from fixtracks.utils.signals import DetectionTimelineSignals
|
||||
|
||||
@ -27,26 +27,23 @@ class Window(QGraphicsRectItem):
|
||||
|
||||
def setWindowX(self, newx):
|
||||
logging.debug("timeline.window: set position to %.3f", newx)
|
||||
r = self.rect()
|
||||
self.setRect(newx, r.y(), self._width, r.height())
|
||||
r = self.rect()
|
||||
self.signals.windowMoved.emit(r.left(), r.right())
|
||||
self.setX(newx)
|
||||
self.signals.windowMoved.emit()
|
||||
|
||||
def setWindowWidth(self, newwidth):
|
||||
logging.debug("timeline.window: update window widthto %.3f", newwidth)
|
||||
logging.debug("timeline.window: update window width to %.3f", newwidth)
|
||||
self._width = newwidth
|
||||
r = self.rect()
|
||||
self.setRect(r.x(), r.y(), self._width, r.height())
|
||||
r = self.rect()
|
||||
self.signals.windowMoved.emit(r.left(), r.right())
|
||||
r.setWidth(newwidth)
|
||||
self.setRect(r)
|
||||
self.signals.windowMoved.emit()
|
||||
|
||||
def setWindow(self, newx, newwidth):
|
||||
logging.debug("timeline.window: update window to range %.3f to %.3f", newx, newwidth)
|
||||
self._width = newwidth
|
||||
r = self.rect()
|
||||
self.setRect(newx, r.y(), self._width, r.height())
|
||||
r = self.rect()
|
||||
self.signals.windowMoved.emit(r.left(), r.right())
|
||||
self.signals.windowMoved.emit()
|
||||
|
||||
def mouseMoveEvent(self, event):
|
||||
super().mouseMoveEvent(event)
|
||||
@ -56,20 +53,19 @@ class Window(QGraphicsRectItem):
|
||||
super().mousePressEvent(event)
|
||||
|
||||
def mouseReleaseEvent(self, event):
|
||||
self.setCursor(Qt.OpenHandCursor)
|
||||
r = self.scenePos()
|
||||
if r.x() < -1000:
|
||||
self.setPos(-1000., self._y)
|
||||
if r.x() > 1000 - self._width:
|
||||
self.setPos(1000 - self._width, self._y)
|
||||
logging.debug("Timeline.Window:MouseRelease event!")
|
||||
r = self.sceneBoundingRect()
|
||||
if r.left() < 0:
|
||||
self.setX(0.)
|
||||
if r.right() > self.scene().width():
|
||||
self.setX(self.scene().width() - self._width)
|
||||
if r.y() != self._y:
|
||||
self.setPos(self.scenePos().x(), self._y)
|
||||
r = self.rect()
|
||||
self.signals.windowMoved.emit(r.left(), r.right())
|
||||
self.setY(self._y)
|
||||
print(self.sceneBoundingRect())
|
||||
super().mouseReleaseEvent(event)
|
||||
self.signals.windowMoved.emit()
|
||||
|
||||
def hoverEnterEvent(self, event):
|
||||
# self.signals.hover.emit(self.data(0), QPointF(event.scenePos().x(), event.scenePos().y()))
|
||||
super().hoverEnterEvent(event)
|
||||
|
||||
|
||||
@ -101,10 +97,10 @@ class DetectionTimeline(QWidget):
|
||||
font.setPointSize(15)
|
||||
font.setBold(False)
|
||||
|
||||
self._window = Window(self.total_width//2, 0, 100, 60, axis_pen, transparent_brush)
|
||||
self._window = Window(0, 0, 100, 60, axis_pen, transparent_brush)
|
||||
self._window.signals.windowMoved.connect(self.on_windowMoved)
|
||||
|
||||
self._scene = QGraphicsScene(QRectF(0, 0, self.total_width+1, 55.))
|
||||
self._scene = QGraphicsScene(QRectF(0, 0, self.total_width, 55.))
|
||||
self._scene.setBackgroundBrush(self._bg_brush)
|
||||
self._scene.addItem(self._window)
|
||||
|
||||
@ -186,7 +182,6 @@ class DetectionTimeline(QWidget):
|
||||
|
||||
def fit_scene_to_view(self):
|
||||
"""Scale the image to fit the QGraphicsView."""
|
||||
logging.debug("Call to fit_scene_to_view")
|
||||
self._view.fitInView(self._scene.sceneRect(), Qt.KeepAspectRatio)
|
||||
|
||||
def resizeEvent(self, event):
|
||||
@ -194,13 +189,12 @@ class DetectionTimeline(QWidget):
|
||||
super().resizeEvent(event)
|
||||
self.fit_scene_to_view()
|
||||
|
||||
def on_windowMoved(self, left, right):
|
||||
logging.debug("Timeline: Window moved to start x-position %.3f and end-x: %.3f", left, right)
|
||||
def on_windowMoved(self):
|
||||
scene_width = self._scene.width()
|
||||
self._rangeStart = np.round(left / scene_width, 3)
|
||||
self._rangeStop = np.round(right / scene_width, 3)
|
||||
logging.debug("Timeline: Updated positions start: %.3f end: %.3f", self.rangeStart, self.rangeStop)
|
||||
self.signals.windowMoved.emit(self._rangeStart, self._rangeStop)
|
||||
self._rangeStart = np.round(self._window.sceneBoundingRect().left() / scene_width, 3)
|
||||
self._rangeStop = np.round(self._window.sceneBoundingRect().right() / scene_width, 3)
|
||||
logging.debug("Timeline: WindowUpdated positions start: %.3f end: %.3f", self.rangeStart, self.rangeStop)
|
||||
self.signals.windowMoved.emit()
|
||||
|
||||
def setWindowPos(self, newx: float):
|
||||
"""Set the x-position of the selection window.
|
||||
|
@ -96,10 +96,12 @@ class DetectionView(QWidget):
|
||||
self._view.fitInView(self._scene.sceneRect(), aspectRadioMode=Qt.AspectRatioMode.KeepAspectRatio)
|
||||
|
||||
def clearDetections(self):
|
||||
for it in self._scene.items():
|
||||
if isinstance(it, Detection):
|
||||
self._scene.removeItem(it)
|
||||
del it
|
||||
items = self._scene.items()
|
||||
if items is not None:
|
||||
for it in self._scene.items():
|
||||
if isinstance(it, Detection):
|
||||
self._scene.removeItem(it)
|
||||
del it
|
||||
|
||||
def addDetections(self, coordinates:np.array, track_ids:np.array, detection_ids:np.array, brush:QBrush):
|
||||
logging.debug("DetectionView: add %i detections with color", coordinates.shape[0])
|
||||
|
@ -516,8 +516,8 @@ class FixTracks(QWidget):
|
||||
self._timeline.setDetectionData(self._data.data)
|
||||
self.update()
|
||||
|
||||
def on_windowChanged(self, start, stop):
|
||||
logging.info("Timeline reports window change to range %f %f percent of data", start, stop)
|
||||
def on_windowChanged(self):
|
||||
logging.info("Timeline reports window change ")
|
||||
self.update()
|
||||
|
||||
def on_windowSizeChanged(self, value):
|
||||
|
Loading…
Reference in New Issue
Block a user