diff layer/ColourMapper.cpp @ 1324:13d9b422f7fe zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:31 +0100
parents 6e724c81f18f
children d79e21855aef
line wrap: on
line diff
--- a/layer/ColourMapper.cpp	Mon Dec 12 15:18:52 2016 +0000
+++ b/layer/ColourMapper.cpp	Mon Sep 17 13:51:31 2018 +0100
@@ -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)
@@ -65,7 +67,7 @@
     m_max(max)
 {
     if (m_min == m_max) {
-        cerr << "WARNING: ColourMapper: min == max (== " << m_min
+        SVCERR << "WARNING: ColourMapper: min == max (== " << m_min
                   << "), adjusting" << endl;
         m_max = m_min + 1;
     }
@@ -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;
+}
+
+