changeset 1198:69ff93e0c624 levelpanwidget

Introduce a colour map combo too. Doesn't yet have swatches
author Chris Cannam
date Fri, 16 Dec 2016 14:16:05 +0000
parents ff77b7707c95
children 73d43e410a6b
files files.pri layer/Colour3DPlotLayer.cpp layer/SpectrogramLayer.cpp layer/TimeValueLayer.cpp widgets/ColourMapComboBox.cpp widgets/ColourMapComboBox.h widgets/PropertyBox.cpp
diffstat 7 files changed, 150 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/files.pri	Fri Dec 16 13:10:21 2016 +0000
+++ b/files.pri	Fri Dec 16 14:16:05 2016 +0000
@@ -45,6 +45,7 @@
            widgets/AudioDial.h \
            widgets/ClickableLabel.h \
            widgets/ColourComboBox.h \
+           widgets/ColourMapComboBox.h \
            widgets/ColourNameDialog.h \
            widgets/CommandHistory.h \
            widgets/CSVFormatDialog.h \
@@ -125,6 +126,7 @@
 	   widgets/ActivityLog.cpp \
            widgets/AudioDial.cpp \
            widgets/ColourComboBox.cpp \
+           widgets/ColourMapComboBox.cpp \
            widgets/ColourNameDialog.cpp \
            widgets/CommandHistory.cpp \
            widgets/CSVFormatDialog.cpp \
--- a/layer/Colour3DPlotLayer.cpp	Fri Dec 16 13:10:21 2016 +0000
+++ b/layer/Colour3DPlotLayer.cpp	Fri Dec 16 14:16:05 2016 +0000
@@ -275,6 +275,7 @@
     if (name == "Invert Vertical Scale") return ToggleProperty;
     if (name == "Opaque") return ToggleProperty;
     if (name == "Smooth") return ToggleProperty;
+    if (name == "Colour") return ColourMapProperty;
     return ValueProperty;
 }
 
--- a/layer/SpectrogramLayer.cpp	Fri Dec 16 13:10:21 2016 +0000
+++ b/layer/SpectrogramLayer.cpp	Fri Dec 16 14:16:05 2016 +0000
@@ -255,6 +255,7 @@
     if (name == "Gain") return RangeProperty;
     if (name == "Colour Rotation") return RangeProperty;
     if (name == "Threshold") return RangeProperty;
+    if (name == "Colour") return ColourMapProperty;
     return ValueProperty;
 }
 
--- a/layer/TimeValueLayer.cpp	Fri Dec 16 13:10:21 2016 +0000
+++ b/layer/TimeValueLayer.cpp	Fri Dec 16 14:16:05 2016 +0000
@@ -132,7 +132,7 @@
     if (name == "Plot Type") return ValueProperty;
     if (name == "Vertical Scale") return ValueProperty;
     if (name == "Scale Units") return UnitsProperty;
-    if (name == "Colour" && m_plotStyle == PlotSegmentation) return ValueProperty;
+    if (name == "Colour" && m_plotStyle == PlotSegmentation) return ColourMapProperty;
     if (name == "Draw Segment Division Lines") return ToggleProperty;
     if (name == "Show Derivative") return ToggleProperty;
     return SingleColourLayer::getPropertyType(name);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/ColourMapComboBox.cpp	Fri Dec 16 14:16:05 2016 +0000
@@ -0,0 +1,69 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2007-2016 QMUL.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#include "ColourMapComboBox.h"
+
+#include "layer/ColourMapper.h"
+
+#include "base/Debug.h"
+
+#include <QFontMetrics>
+
+#include <iostream>
+
+using namespace std;
+
+ColourMapComboBox::ColourMapComboBox(QWidget *parent) :
+    NotifyingComboBox(parent)
+{
+    setEditable(false);
+    rebuild();
+
+    connect(this, SIGNAL(activated(int)), this, SLOT(comboActivated(int)));
+
+    if (count() < 20 && count() > maxVisibleItems()) {
+	setMaxVisibleItems(count());
+    }
+}
+
+void
+ColourMapComboBox::comboActivated(int index)
+{
+    emit colourMapChanged(index);
+}
+
+void
+ColourMapComboBox::rebuild()
+{
+    blockSignals(true);
+
+    int ix = currentIndex();
+    
+    clear();
+
+    int size = (QFontMetrics(QFont()).height() * 2) / 3;
+    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);
+    }
+
+    setCurrentIndex(ix);
+    
+    blockSignals(false);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/ColourMapComboBox.h	Fri Dec 16 14:16:05 2016 +0000
@@ -0,0 +1,40 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2007-2016 QMUL.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef SV_COLOURMAP_COMBO_BOX_H
+#define SV_COLOURMAP_COMBO_BOX_H
+
+#include "NotifyingComboBox.h"
+
+/**
+ * Colour map picker combo box with swatches
+ */
+class ColourMapComboBox : public NotifyingComboBox
+{
+    Q_OBJECT
+
+public:
+    ColourMapComboBox(QWidget *parent = 0);
+
+signals:
+    void colourMapChanged(int index);
+
+private slots:
+    void rebuild();
+    void comboActivated(int);
+};
+
+#endif
+
--- a/widgets/PropertyBox.cpp	Fri Dec 16 13:10:21 2016 +0000
+++ b/widgets/PropertyBox.cpp	Fri Dec 16 14:16:05 2016 +0000
@@ -35,6 +35,7 @@
 #include "NotifyingPushButton.h"
 #include "NotifyingToolButton.h"
 #include "ColourComboBox.h"
+#include "ColourMapComboBox.h"
 
 #include <QGridLayout>
 #include <QHBoxLayout>
@@ -419,13 +420,44 @@
             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));
+        break;
+    }        
+
+    case PropertyContainer::ColourMapProperty:
+    {
+        ColourMapComboBox *cb;
+        
+	if (have) {
+	    cb = qobject_cast<ColourMapComboBox *>(m_propertyControllers[name]);
+	    assert(cb);
+	} else {
+#ifdef DEBUG_PROPERTY_BOX 
+	    cerr << "PropertyBox: creating new colourmap combobox" << endl;
 #endif
+            cb = new ColourMapComboBox();
+            cb->setObjectName(name);
 
+	    connect(cb, SIGNAL(colourMapChanged(int)),
+		    this, SLOT(propertyControllerChanged(int)));
+            connect(cb, SIGNAL(mouseEntered()),
+                    this, SLOT(mouseEnteredWidget()));
+            connect(cb, SIGNAL(mouseLeft()),
+                    this, SLOT(mouseLeftWidget()));
+
+            cb->setToolTip(propertyLabel);
+            m_groupLayouts[groupName]->addWidget
+                (cb, 0, m_groupLayouts[groupName]->columnCount());
+	    m_propertyControllers[name] = cb;
+	}
+
+        if (cb->currentIndex() != value) {
+            cb->blockSignals(true);
+            cb->setCurrentIndex(value);
+            cb->blockSignals(false);
+        }
+
+	cb->setMinimumSize(QSize(10, cb->font().pixelSize() * 2));
         break;
     }