changeset 932:37bb4b416c52 tonioni

Render direct to widget (necessary to avoid pixel doubling on OS/X)
author Chris Cannam
date Wed, 25 Mar 2015 11:27:46 +0000
parents 7cf497b72da3
children 9022635c615a
files widgets/LevelPanToolButton.cpp widgets/LevelPanToolButton.h widgets/LevelPanWidget.cpp
diffstat 3 files changed, 24 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/LevelPanToolButton.cpp	Wed Mar 25 11:09:33 2015 +0000
+++ b/widgets/LevelPanToolButton.cpp	Wed Mar 25 11:27:46 2015 +0000
@@ -35,7 +35,7 @@
     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(m_lpw, SIGNAL(panChanged(float)), this, SLOT(update()));
 
     connect(this, SIGNAL(clicked(bool)), this, SLOT(selfClicked()));
     
@@ -47,7 +47,7 @@
     setPopupMode(MenuButtonPopup);
     setMenu(menu);
 
-    redraw();
+    setImageSize(m_pixels);
 }
 
 LevelPanToolButton::~LevelPanToolButton()
@@ -70,21 +70,27 @@
 LevelPanToolButton::setImageSize(int pixels)
 {
     m_pixels = pixels;
-    redraw();
+
+    QPixmap px(m_pixels, m_pixels);
+    px.fill(Qt::transparent);
+    setIcon(px);
+
+    m_lpw->setFixedWidth(m_pixels * 4);
+    m_lpw->setFixedHeight(m_pixels * 4);
 }
 
 void
 LevelPanToolButton::setLevel(float level)
 {
     m_lpw->setLevel(level);
-    redraw();
+    update();
 }
 
 void
 LevelPanToolButton::setPan(float pan)
 {
     m_lpw->setPan(pan);
-    redraw();
+    update();
 }
 
 void
@@ -96,7 +102,7 @@
 	m_muted = true;
 	m_savedLevel = 1.f;
     }
-    redraw();
+    update();
 }
 
 void
@@ -114,20 +120,15 @@
 	m_lpw->setLevel(0.f);
 	emit levelChanged(0.f);
     }
-    redraw();
+    update();
 }
 
 void
-LevelPanToolButton::redraw()
+LevelPanToolButton::paintEvent(QPaintEvent *e)
 {
-    QSize sz(m_pixels, m_pixels);
-
-    m_lpw->setFixedWidth(m_pixels * 4);
-    m_lpw->setFixedHeight(m_pixels * 4);
-    
-    QPixmap px(sz);
-    px.fill(Qt::transparent);
-    m_lpw->renderTo(&px, QRectF(QPointF(), sz), false);
-    setIcon(px);
+    QToolButton::paintEvent(e);
+    double margin = (double(height()) - m_pixels) / 2.0;
+    m_lpw->renderTo(this, QRectF(margin, margin, m_pixels, m_pixels), false);
 }
 
+
--- a/widgets/LevelPanToolButton.h	Wed Mar 25 11:09:33 2015 +0000
+++ b/widgets/LevelPanToolButton.h	Wed Mar 25 11:27:46 2015 +0000
@@ -42,9 +42,6 @@
     /// Set pan in the range [-1,1] -- will be rounded
     void setPan(float);
 
-    /// Redraw icon for toolbar button based on level-pan widget contents
-    void redraw();
-
 signals:
     void levelChanged(float);
     void panChanged(float);
@@ -54,6 +51,8 @@
     void selfClicked();
     
 protected:
+    void paintEvent(QPaintEvent *);
+    
     LevelPanWidget *m_lpw;
     int m_pixels;
     bool m_muted;
--- a/widgets/LevelPanWidget.cpp	Wed Mar 25 11:09:33 2015 +0000
+++ b/widgets/LevelPanWidget.cpp	Wed Mar 25 11:27:46 2015 +0000
@@ -200,11 +200,11 @@
 
     double wcell = w / npan, hcell = h / nlevel;
 
-    level = int((h - loc.y()) / hcell);
+    level = int((h - (loc.y() - rect.y())) / hcell);
     if (level < 0) level = 0;
     if (level > maxLevel) level = maxLevel;
 
-    pan = int(loc.x() / wcell) - maxPan;
+    pan = int((loc.x() - rect.x()) / wcell) - maxPan;
     if (pan < -maxPan) pan = -maxPan;
     if (pan > maxPan) pan = maxPan;
 }
@@ -223,8 +223,8 @@
 LevelPanWidget::cellCentre(QRectF rect, int level, int pan) const
 {
     QSizeF cs = cellSize(rect);
-    return QPointF(cs.width() * (pan + maxPan) + cs.width() / 2.,
-		   rect.height() - cs.height() * (level + 1) + cs.height() / 2.);
+    return QPointF(rect.x() + cs.width() * (pan + maxPan) + cs.width() / 2.,
+		   rect.y() + rect.height() - cs.height() * (level + 1) + cs.height() / 2.);
 }
 
 QSizeF