changeset 260:6d113226bb4c

* a bit more work on measurement tool mode * use arrow cursors on thumbwheels and panner in pane HUD
author Chris Cannam
date Thu, 14 Jun 2007 15:20:49 +0000
parents 2d891e02c5ce
children 11021509c4eb
files layer/Layer.cpp layer/Layer.h layer/SpectrumLayer.cpp layer/SpectrumLayer.h view/Pane.cpp
diffstat 5 files changed, 85 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Layer.cpp	Wed Jun 13 13:44:19 2007 +0000
+++ b/layer/Layer.cpp	Thu Jun 14 15:20:49 2007 +0000
@@ -122,3 +122,16 @@
     emit layerParametersChanged();
 }
 
+bool
+Layer::getXScaleValue(View *v, int x, float &value, QString &unit) const
+{
+    if (!hasTimeXAxis()) return false;
+
+    const Model *m = getModel();
+    if (!m) return false;
+
+    value = float(v->getFrameForX(x)) / m->getSampleRate();
+    unit = "s";
+    return true;
+}
+
--- a/layer/Layer.h	Wed Jun 13 13:44:19 2007 +0000
+++ b/layer/Layer.h	Thu Jun 14 15:20:49 2007 +0000
@@ -318,6 +318,24 @@
     }
 
     /**
+     * Return the value and unit at the given x coordinate in the
+     * given view.  This is for descriptive purposes using the
+     * measurement tool.  The default implementation works correctly
+     * if the layer hasTimeXAxis().
+     */
+    virtual bool getXScaleValue(View *v, int x,
+                                float &value, QString &unit) const;
+
+    /** 
+     * Return the value and unit at the given y coordinate in the
+     * given view.
+     */
+    virtual bool getYScaleValue(View *, int /* y */,
+                                float &/* value */, QString &/* unit */) const {
+        return false;
+    }
+
+    /**
      * Get the number of vertical zoom steps available for this layer.
      * If vertical zooming is not available, return 0.  The meaning of
      * "zooming" is entirely up to the layer -- changing the zoom
--- a/layer/SpectrumLayer.cpp	Wed Jun 13 13:44:19 2007 +0000
+++ b/layer/SpectrumLayer.cpp	Thu Jun 14 15:20:49 2007 +0000
@@ -323,6 +323,15 @@
     return x;
 }
 
+bool
+SpectrumLayer::getXScaleValue(View *v, int x, 
+                              float &value, QString &unit) const
+{
+    value = getFrequencyForX(x, v->width() - m_xorigins[v]);
+    unit = "Hz";
+    return true;
+}
+
 void
 SpectrumLayer::paintCrosshairs(View *v, QPainter &paint,
                                QPoint cursorPos) const
--- a/layer/SpectrumLayer.h	Wed Jun 13 13:44:19 2007 +0000
+++ b/layer/SpectrumLayer.h	Thu Jun 14 15:20:49 2007 +0000
@@ -59,6 +59,9 @@
     virtual bool getValueExtents(float &min, float &max,
                                  bool &logarithmic, QString &unit) const;
 
+    virtual bool getXScaleValue(View *v, int x,
+                                float &value, QString &unit) const;
+
     virtual bool isLayerScrollable(const View *) const { return false; }
 
     void setChannel(int);
--- a/view/Pane.cpp	Wed Jun 13 13:44:19 2007 +0000
+++ b/view/Pane.cpp	Thu Jun 14 15:20:49 2007 +0000
@@ -102,6 +102,7 @@
         
         m_hthumb = new Thumbwheel(Qt::Horizontal);
         m_hthumb->setObjectName(tr("Horizontal Zoom"));
+        m_hthumb->setCursor(Qt::ArrowCursor);
         layout->addWidget(m_hthumb, 1, 0, 1, 2);
         m_hthumb->setFixedWidth(70);
         m_hthumb->setFixedHeight(16);
@@ -113,6 +114,7 @@
         connect(m_hthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
 
         m_vpan = new Panner;
+        m_vpan->setCursor(Qt::ArrowCursor);
         layout->addWidget(m_vpan, 0, 1);
         m_vpan->setFixedWidth(12);
         m_vpan->setFixedHeight(70);
@@ -126,6 +128,7 @@
 
         m_vthumb = new Thumbwheel(Qt::Vertical);
         m_vthumb->setObjectName(tr("Vertical Zoom"));
+        m_vthumb->setCursor(Qt::ArrowCursor);
         layout->addWidget(m_vthumb, 0, 2);
         m_vthumb->setFixedWidth(16);
         m_vthumb->setFixedHeight(70);
@@ -140,6 +143,7 @@
         }
 
         m_reset = new NotifyingPushButton;
+        m_reset->setCursor(Qt::ArrowCursor);
         m_reset->setFixedHeight(16);
         m_reset->setFixedWidth(16);
         layout->addWidget(m_reset, 1, 2);
@@ -735,12 +739,44 @@
     }
 
     if (m_clickedInRange && m_manager) {
-        if ((m_shiftPressed && toolMode == ViewManager::NavigateMode) ||
-            toolMode == ViewManager::MeasureMode) {
-	    //!!! be nice if this looked a bit more in keeping with the
-	    //selection block
-	    paint.setPen(toolMode == ViewManager::MeasureMode ? Qt::green :
-                         Qt::blue);
+
+        //!!! be nice if this looked a bit more in keeping with the
+        //selection block
+
+        if (m_shiftPressed && toolMode == ViewManager::NavigateMode) {
+
+	    paint.setPen(Qt::blue);
+            //!!! shouldn't use clickPos -- needs to use a clicked frame
+	    paint.drawRect(m_clickPos.x(), m_clickPos.y(),
+			   m_mousePos.x() - m_clickPos.x(),
+			   m_mousePos.y() - m_clickPos.y());
+
+        } else if (toolMode == ViewManager::MeasureMode && topLayer) {
+
+            float v0, v1;
+            QString u0, u1;
+            bool b0, b1;
+
+            if ((b0 = topLayer->getXScaleValue(this, m_clickPos.x(), v0, u0))) {
+                drawVisibleText(paint,
+                                m_clickPos.x() + 2,
+                                m_clickPos.y() + fontAscent + 2,
+                                QString("%1 %2").arg(v0).arg(u0),
+                                OutlinedText);
+
+                if ((b1 = topLayer->getXScaleValue(this, m_mousePos.x(), v1, u1))
+                    && u1 == u0) {
+                    QString t = QString("%1 %2").arg(v1 - v0).arg(u1);
+                    drawVisibleText(paint,
+                                    m_mousePos.x() - paint.fontMetrics().width(t) - 2,
+                                    m_mousePos.y() - 2,
+                                    t,
+                                    OutlinedText);
+                }
+            }
+
+	    paint.setPen(Qt::green);
+
             //!!! shouldn't use clickPos -- needs to use a clicked frame
 	    paint.drawRect(m_clickPos.x(), m_clickPos.y(),
 			   m_mousePos.x() - m_clickPos.x(),