changeset 1436:c697186a8471 single-point

Fix tendency of start position of measure rect to wander as you drag out the rect (at certain zoom resolutions)
author Chris Cannam
date Thu, 21 Mar 2019 15:22:19 +0000
parents 9abddbd57667
children e2b6a13a1f69
files layer/Layer.cpp
diffstat 1 files changed, 27 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Layer.cpp	Thu Mar 21 13:34:08 2019 +0000
+++ b/layer/Layer.cpp	Thu Mar 21 15:22:19 2019 +0000
@@ -373,8 +373,24 @@
 void
 Layer::measureStart(LayerGeometryProvider *v, QMouseEvent *e)
 {
-    setMeasureRectFromPixrect(v, m_draggingRect,
-                              QRect(e->x(), e->y(), 0, 0));
+    m_draggingRect.haveFrames = hasTimeXAxis();
+
+    // NB if haveFrames, then pixrect x and width will be rewritten on
+    // every paint according to the current locations of the
+    // definitive frame values. So we should set the start frame value
+    // once on measureStart, and then not modify it on drag (to avoid
+    // drift from repeated conversion back and forth).
+    
+    m_draggingRect.pixrect = QRect(e->x(), e->y(), 0, 0);
+
+    if (m_draggingRect.haveFrames) {
+        m_draggingRect.startFrame = v->getFrameForX(e->x());
+        m_draggingRect.endFrame = v->getFrameForX(e->x());
+    }
+
+    setMeasureRectYCoord(v, m_draggingRect, true, e->y());
+    setMeasureRectYCoord(v, m_draggingRect, false, e->y());
+
     m_haveDraggingRect = true;
 }
 
@@ -383,11 +399,15 @@
 {
     if (!m_haveDraggingRect) return;
 
-    setMeasureRectFromPixrect(v, m_draggingRect,
-                              QRect(m_draggingRect.pixrect.x(),
-                                    m_draggingRect.pixrect.y(),
-                                    e->x() - m_draggingRect.pixrect.x(),
-                                    e->y() - m_draggingRect.pixrect.y()));
+    m_draggingRect.pixrect.setHeight(e->y() - m_draggingRect.pixrect.y());
+
+    if (m_draggingRect.haveFrames) {
+        m_draggingRect.endFrame = v->getFrameForX(e->x());
+    } else {
+        m_draggingRect.pixrect.setWidth(e->x() - m_draggingRect.pixrect.x());
+    }
+
+    setMeasureRectYCoord(v, m_draggingRect, false, e->y());
 }
 
 void