changeset 1199:73d43e410a6b levelpanwidget

Add swatches to colour map combo (optionally, as it turns out they are quite visually distracting)
author Chris Cannam
date Fri, 16 Dec 2016 15:55:59 +0000
parents 69ff93e0c624
children 808d375a3b12
files layer/ColourMapper.cpp layer/ColourMapper.h widgets/ColourMapComboBox.cpp widgets/ColourMapComboBox.h widgets/PropertyBox.cpp
diffstat 5 files changed, 50 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/layer/ColourMapper.cpp	Fri Dec 16 14:16:05 2016 +0000
+++ b/layer/ColourMapper.cpp	Fri Dec 16 15:55:59 2016 +0000
@@ -4,7 +4,7 @@
     Sonic Visualiser
     An audio file viewer and annotation editor.
     Centre for Digital Music, Queen Mary, University of London.
-    This file copyright 2006-2007 Chris Cannam and QMUL.
+    This file copyright 2006-2016 Chris Cannam and QMUL.
     
     This program is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License as
@@ -23,6 +23,8 @@
 
 #include <vector>
 
+#include <QPainter>
+
 using namespace std;
 
 static vector<QColor> convertStrings(const vector<QString> &strs)
@@ -320,4 +322,29 @@
     }
 }
 
+QPixmap
+ColourMapper::getExamplePixmap(QSize size) const
+{
+    QPixmap pmap(size);
+    pmap.fill(Qt::white);
+    QPainter paint(&pmap);
 
+    int w = size.width(), h = size.height();
+    
+    int margin = 2;
+    if (w < 4 || h < 4) margin = 0;
+    else if (w < 8 || h < 8) margin = 1;
+
+    int n = w - margin*2;
+    
+    for (int x = 0; x < n; ++x) {
+        double value = m_min + ((m_max - m_min) * x) / (n-1);
+        QColor colour(map(value));
+        paint.setPen(colour);
+        paint.drawLine(x + margin, margin, x + margin, h - margin);
+    }
+    
+    return pmap;
+}
+
+
--- a/layer/ColourMapper.h	Fri Dec 16 14:16:05 2016 +0000
+++ b/layer/ColourMapper.h	Fri Dec 16 15:55:59 2016 +0000
@@ -13,12 +13,13 @@
     COPYING included with this distribution for more information.
 */
 
-#ifndef _COLOUR_MAPPER_H_
-#define _COLOUR_MAPPER_H_
+#ifndef SV_COLOUR_MAPPER_H
+#define SV_COLOUR_MAPPER_H
 
 #include <QObject>
 #include <QColor>
 #include <QString>
+#include <QPixmap>
 
 /**
  * A class for mapping intensity values onto various colour maps.
@@ -59,6 +60,8 @@
     QColor getContrastingColour() const; // for cursors etc
     bool hasLightBackground() const;
 
+    QPixmap getExamplePixmap(QSize size) const;
+    
 protected:
     int m_map;
     double m_min;
--- a/widgets/ColourMapComboBox.cpp	Fri Dec 16 14:16:05 2016 +0000
+++ b/widgets/ColourMapComboBox.cpp	Fri Dec 16 15:55:59 2016 +0000
@@ -25,8 +25,9 @@
 
 using namespace std;
 
-ColourMapComboBox::ColourMapComboBox(QWidget *parent) :
-    NotifyingComboBox(parent)
+ColourMapComboBox::ColourMapComboBox(bool includeSwatches, QWidget *parent) :
+    NotifyingComboBox(parent),
+    m_includeSwatches(includeSwatches)
 {
     setEditable(false);
     rebuild();
@@ -57,9 +58,13 @@
     if (size < 12) size = 12;
 
     for (int i = 0; i < ColourMapper::getColourMapCount(); ++i) {
-	QString name = ColourMapper::getColourMapName(i);
-//	addItem(db->getExamplePixmap(i, QSize(size, size)), name);
-        addItem(name);
+        QString name = ColourMapper::getColourMapName(i);
+        if (m_includeSwatches) {
+            ColourMapper mapper(i, 0.0, 1.0);
+            addItem(mapper.getExamplePixmap(QSize(size * 2, size)), name);
+        } else {
+            addItem(name);
+        }
     }
 
     setCurrentIndex(ix);
--- a/widgets/ColourMapComboBox.h	Fri Dec 16 14:16:05 2016 +0000
+++ b/widgets/ColourMapComboBox.h	Fri Dec 16 15:55:59 2016 +0000
@@ -19,14 +19,14 @@
 #include "NotifyingComboBox.h"
 
 /**
- * Colour map picker combo box with swatches
+ * Colour map picker combo box with optional swatches
  */
 class ColourMapComboBox : public NotifyingComboBox
 {
     Q_OBJECT
 
 public:
-    ColourMapComboBox(QWidget *parent = 0);
+    ColourMapComboBox(bool includeSwatches, QWidget *parent = 0);
 
 signals:
     void colourMapChanged(int index);
@@ -34,6 +34,9 @@
 private slots:
     void rebuild();
     void comboActivated(int);
+
+private:
+    bool m_includeSwatches;
 };
 
 #endif
--- a/widgets/PropertyBox.cpp	Fri Dec 16 14:16:05 2016 +0000
+++ b/widgets/PropertyBox.cpp	Fri Dec 16 15:55:59 2016 +0000
@@ -219,7 +219,7 @@
 	QLabel *showLabel = new QLabel(tr("Show"));
 	layout->addWidget(showLabel, 0, col++, Qt::AlignVCenter | Qt::AlignRight);
 
-	m_showButton = new LEDButton(Qt::blue);
+	m_showButton = new LEDButton(palette().highlight().color());
 	layout->addWidget(m_showButton, 0, col++, Qt::AlignVCenter | Qt::AlignLeft);
 	connect(m_showButton, SIGNAL(stateChanged(bool)),
 		this, SIGNAL(showLayer(bool)));
@@ -420,7 +420,6 @@
             cb->blockSignals(false);
         }
 
-	cb->setMinimumSize(QSize(10, cb->font().pixelSize() * 2));
         break;
     }        
 
@@ -435,7 +434,7 @@
 #ifdef DEBUG_PROPERTY_BOX 
 	    cerr << "PropertyBox: creating new colourmap combobox" << endl;
 #endif
-            cb = new ColourMapComboBox();
+            cb = new ColourMapComboBox(false);
             cb->setObjectName(name);
 
 	    connect(cb, SIGNAL(colourMapChanged(int)),
@@ -457,7 +456,6 @@
             cb->blockSignals(false);
         }
 
-	cb->setMinimumSize(QSize(10, cb->font().pixelSize() * 2));
         break;
     }        
 
@@ -543,13 +541,6 @@
         }
         cb->blockSignals(false);
 
-#ifdef Q_OS_MAC
-	// Crashes on startup without this, for some reason; also
-	// prevents combo boxes from getting weirdly squished
-	// vertically
-	cb->setMinimumSize(QSize(10, cb->font().pixelSize() * 2));
-#endif
-
 	break;
     }