diff layer/Layer.cpp @ 267:4ed1446ad604

* more on measurement tool -- pull out some logic from pane to layer &c still more to do
author Chris Cannam
date Thu, 21 Jun 2007 16:12:00 +0000
parents 6d113226bb4c
children 70537b0434c4
line wrap: on
line diff
--- a/layer/Layer.cpp	Thu Jun 21 14:05:23 2007 +0000
+++ b/layer/Layer.cpp	Thu Jun 21 16:12:00 2007 +0000
@@ -20,11 +20,13 @@
 #include <iostream>
 
 #include <QMutexLocker>
+#include <QMouseEvent>
 
 #include "LayerFactory.h"
 #include "base/PlayParameterRepository.h"
 
-Layer::Layer()
+Layer::Layer() :
+    m_haveDraggingRect(false)
 {
 }
 
@@ -123,7 +125,7 @@
 }
 
 bool
-Layer::getXScaleValue(View *v, int x, float &value, QString &unit) const
+Layer::getXScaleValue(const View *v, int x, float &value, QString &unit) const
 {
     if (!hasTimeXAxis()) return false;
 
@@ -135,3 +137,60 @@
     return true;
 }
 
+void
+Layer::measureStart(View *v, QMouseEvent *e)
+{
+    m_draggingRect.pixrect = QRect(e->x(), e->y(), 0, 0);
+    if (hasTimeXAxis()) {
+        m_draggingRect.startFrame = v->getFrameForX(e->x());
+        m_draggingRect.endFrame = m_draggingRect.startFrame;
+    }
+    m_haveDraggingRect = true;
+}
+
+void
+Layer::measureDrag(View *v, QMouseEvent *e)
+{
+    if (!m_haveDraggingRect) return;
+    m_draggingRect.pixrect = QRect(m_draggingRect.pixrect.x(),
+                                   m_draggingRect.pixrect.y(),
+                                   e->x() - m_draggingRect.pixrect.x(),
+                                   e->y() - m_draggingRect.pixrect.y());
+    if (hasTimeXAxis()) {
+        m_draggingRect.endFrame = v->getFrameForX(e->x());
+    }
+}
+
+void
+Layer::measureEnd(View *v, QMouseEvent *e)
+{
+    //!!! command
+    if (!m_haveDraggingRect) return;
+    measureDrag(v, e);
+    m_measureRectList.push_back(m_draggingRect);
+    m_haveDraggingRect = false;
+}
+
+void
+Layer::paintMeasurementRects(View *v, QPainter &paint) const
+{
+    if (m_haveDraggingRect) {
+        v->drawMeasurementRect(paint, this, m_draggingRect.pixrect);
+    }
+
+    bool timex = hasTimeXAxis();
+
+    for (MeasureRectList::const_iterator i = m_measureRectList.begin(); 
+         i != m_measureRectList.end(); ++i) {
+    
+        if (timex) {
+            int x0 = v->getXForFrame(i->startFrame);
+            int x1 = v->getXForFrame(i->endFrame);
+            QRect pr = QRect(x0, i->pixrect.y(), x1 - x0, i->pixrect.height());
+            i->pixrect = pr;
+        }
+
+        v->drawMeasurementRect(paint, this, i->pixrect);
+    }
+}
+