changeset 256:c492902dba40

* Make shift+mousewheel scroll vertically (where applicable) and alt+mousewheel zoom vertically (where applicable). Closes #1734844
author Chris Cannam
date Wed, 13 Jun 2007 10:27:39 +0000
parents e175ade2d6b0
children 1ab41ee36952
files view/Pane.cpp widgets/Panner.cpp widgets/Panner.h widgets/Thumbwheel.cpp widgets/Thumbwheel.h
diffstat 5 files changed, 74 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/view/Pane.cpp	Wed Jun 13 09:19:33 2007 +0000
+++ b/view/Pane.cpp	Wed Jun 13 10:27:39 2007 +0000
@@ -1479,6 +1479,22 @@
 	    setCentreFrame(m_centreFrame - delta);
 	}
 
+    } else if (e->modifiers() & Qt::ShiftModifier) {
+
+        // Zoom vertically
+
+        if (m_vpan) {
+            m_vpan->scroll(e->delta() > 0);
+        }
+
+    } else if (e->modifiers() & Qt::AltModifier) {
+
+        // Zoom vertically
+
+        if (m_vthumb) {
+            m_vthumb->scroll(e->delta() > 0);
+        }
+
     } else {
 
 	// Zoom in or out
--- a/widgets/Panner.cpp	Wed Jun 13 09:19:33 2007 +0000
+++ b/widgets/Panner.cpp	Wed Jun 13 10:27:39 2007 +0000
@@ -29,6 +29,7 @@
     m_rectY(0),
     m_rectWidth(1),
     m_rectHeight(1),
+    m_scrollUnit(0),
     m_defaultCentreX(0),
     m_defaultCentreY(0),
     m_defaultsSet(false),
@@ -51,6 +52,31 @@
 }
 
 void
+Panner::setScrollUnit(float unit)
+{
+    m_scrollUnit = unit;
+}
+
+void
+Panner::scroll(bool up)
+{
+    float unit = m_scrollUnit;
+    if (unit == 0.f) {
+        unit = float(m_rectHeight) / (6 * float(height()));
+        if (unit < 0.01) unit = 0.01;
+    }
+
+    if (!up) {
+        m_rectY += unit;
+    } else {
+        m_rectY -= unit;
+    }
+
+    normalise();
+    emitAndUpdate();
+}
+
+void
 Panner::mousePressEvent(QMouseEvent *e)
 {
     if (e->button() == Qt::MidButton ||
@@ -104,14 +130,7 @@
 void
 Panner::wheelEvent(QWheelEvent *e)
 {
-    if (e->delta() < 0) {
-        m_rectY += 0.1;
-    } else {
-        m_rectY -= 0.1;
-    }
-
-    normalise();
-    emitAndUpdate();
+    scroll(e->delta() > 0);
 }
 
 void
--- a/widgets/Panner.h	Wed Jun 13 09:19:33 2007 +0000
+++ b/widgets/Panner.h	Wed Jun 13 10:27:39 2007 +0000
@@ -31,6 +31,14 @@
     void setThumbColour(QColor colour);
     void setAlpha(int backgroundAlpha, int thumbAlpha);
 
+    /**
+     * Set the amount the scroll() function or mouse wheel movement
+     * makes the panner rectangle move by.  The default value of 0
+     * means to select a value automatically based on the dimensions
+     * of the panner rectangle.
+     */
+    void setScrollUnit(float unit);
+
     void getRectExtents(float &x0, float &y0, float &width, float &height);
 
     virtual QSize sizeHint() const;
@@ -95,6 +103,12 @@
      */
     void setRectCentreY(float y);
 
+    /**
+     * Move up (if up is true) or down a bit.  This is basically the
+     * same action as rolling the mouse wheel one notch.
+     */
+    void scroll(bool up);
+
     void resetToDefault();
 
 protected:
@@ -114,6 +128,7 @@
     float m_rectY;
     float m_rectWidth;
     float m_rectHeight;
+    float m_scrollUnit;
 
     float m_defaultCentreX;
     float m_defaultCentreY;
--- a/widgets/Thumbwheel.cpp	Wed Jun 13 09:19:33 2007 +0000
+++ b/widgets/Thumbwheel.cpp	Wed Jun 13 10:27:39 2007 +0000
@@ -233,6 +233,21 @@
 }
 
 void
+Thumbwheel::scroll(bool up)
+{
+    int step = lrintf(m_speed);
+    if (step == 0) step = 1;
+
+    if (up) {
+	setValue(m_value + step);
+    } else {
+	setValue(m_value - step);
+    }
+    
+    emit valueChanged(getValue());
+}
+
+void
 Thumbwheel::setSpeed(float speed)
 {
     m_speed = speed;
--- a/widgets/Thumbwheel.h	Wed Jun 13 09:19:33 2007 +0000
+++ b/widgets/Thumbwheel.h	Wed Jun 13 10:27:39 2007 +0000
@@ -59,6 +59,7 @@
     void setShowScale(bool show);
     void setValue(int value);
     void setMappedValue(float mappedValue);
+    void scroll(bool up);
     void resetToDefault();
 
 protected slots: