changeset 930:86df7de08e03 tonioni

A number of fixes to level-pan button (including mute toggle)
author Chris Cannam
date Wed, 25 Mar 2015 10:55:09 +0000
parents 20698aa6a517
children 7cf497b72da3
files widgets/LevelPanToolButton.cpp widgets/LevelPanToolButton.h widgets/LevelPanWidget.cpp
diffstat 3 files changed, 46 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/LevelPanToolButton.cpp	Wed Mar 25 10:33:19 2015 +0000
+++ b/widgets/LevelPanToolButton.cpp	Wed Mar 25 10:55:09 2015 +0000
@@ -25,15 +25,19 @@
 
 LevelPanToolButton::LevelPanToolButton(QWidget *parent) :
     QToolButton(parent),
-    m_pixels(32)
+    m_pixels(32),
+    m_muted(false),
+    m_savedLevel(1.f)
 {
     m_lpw = new LevelPanWidget();
 
     connect(m_lpw, SIGNAL(levelChanged(float)), this, SIGNAL(levelChanged(float)));
-    connect(m_lpw, SIGNAL(levelChanged(float)), this, SLOT(redraw()));
+    connect(m_lpw, SIGNAL(levelChanged(float)), this, SLOT(selfLevelChanged(float)));
 
     connect(m_lpw, SIGNAL(panChanged(float)), this, SIGNAL(panChanged(float)));
     connect(m_lpw, SIGNAL(panChanged(float)), this, SLOT(redraw()));
+
+    connect(this, SIGNAL(clicked(bool)), this, SLOT(selfClicked()));
     
     QMenu *menu = new QMenu();
     QWidgetAction *wa = new QWidgetAction(menu);
@@ -42,7 +46,6 @@
 
     setPopupMode(MenuButtonPopup);
     setMenu(menu);
-    setCheckable(true);
 
     redraw();
 }
@@ -74,12 +77,42 @@
 LevelPanToolButton::setLevel(float level)
 {
     m_lpw->setLevel(level);
+    redraw();
 }
 
 void
 LevelPanToolButton::setPan(float pan)
 {
     m_lpw->setPan(pan);
+    redraw();
+}
+
+void
+LevelPanToolButton::selfLevelChanged(float level)
+{
+    if (level > 0.f) {
+	m_muted = false;
+    } else {
+	m_muted = true;
+	m_savedLevel = 1.f;
+    }
+    redraw();
+}
+
+void
+LevelPanToolButton::selfClicked()
+{
+    cerr << "selfClicked" << endl;
+    
+    if (m_muted) {
+	m_muted = false;
+	m_lpw->setLevel(m_savedLevel);
+    } else {
+	m_savedLevel = m_lpw->getLevel();
+	m_muted = true;
+	m_lpw->setLevel(0.f);
+    }
+    redraw();
 }
 
 void
--- a/widgets/LevelPanToolButton.h	Wed Mar 25 10:33:19 2015 +0000
+++ b/widgets/LevelPanToolButton.h	Wed Mar 25 10:55:09 2015 +0000
@@ -49,9 +49,15 @@
     void levelChanged(float);
     void panChanged(float);
 
+private slots:
+    void selfLevelChanged(float);
+    void selfClicked();
+    
 protected:
     LevelPanWidget *m_lpw;
     int m_pixels;
+    bool m_muted;
+    float m_savedLevel;
 };
 
 #endif
--- a/widgets/LevelPanWidget.cpp	Wed Mar 25 10:33:19 2015 +0000
+++ b/widgets/LevelPanWidget.cpp	Wed Mar 25 10:55:09 2015 +0000
@@ -286,8 +286,10 @@
         pen.setWidthF(thin * 2);
         pen.setCapStyle(Qt::RoundCap);
         paint.setPen(pen);
-        paint.drawLine(rect.topLeft(), rect.bottomRight());
-        paint.drawLine(rect.bottomLeft(), rect.topRight());
+        paint.drawLine(cellCentre(rect, 0, -maxPan),
+                       cellCentre(rect, maxLevel, maxPan));
+        paint.drawLine(cellCentre(rect, maxLevel, -maxPan),
+                       cellCentre(rect, 0, maxPan));
         return;
     }