comparison layer/ColourMapper.cpp @ 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 65b183494331
children 6e724c81f18f
comparison
equal deleted inserted replaced
1198:69ff93e0c624 1199:73d43e410a6b
2 2
3 /* 3 /*
4 Sonic Visualiser 4 Sonic Visualiser
5 An audio file viewer and annotation editor. 5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London. 6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006-2007 Chris Cannam and QMUL. 7 This file copyright 2006-2016 Chris Cannam and QMUL.
8 8
9 This program is free software; you can redistribute it and/or 9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as 10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
20 #include <cmath> 20 #include <cmath>
21 21
22 #include "base/Debug.h" 22 #include "base/Debug.h"
23 23
24 #include <vector> 24 #include <vector>
25
26 #include <QPainter>
25 27
26 using namespace std; 28 using namespace std;
27 29
28 static vector<QColor> convertStrings(const vector<QString> &strs) 30 static vector<QColor> convertStrings(const vector<QString> &strs)
29 { 31 {
318 default: 320 default:
319 return false; 321 return false;
320 } 322 }
321 } 323 }
322 324
323 325 QPixmap
326 ColourMapper::getExamplePixmap(QSize size) const
327 {
328 QPixmap pmap(size);
329 pmap.fill(Qt::white);
330 QPainter paint(&pmap);
331
332 int w = size.width(), h = size.height();
333
334 int margin = 2;
335 if (w < 4 || h < 4) margin = 0;
336 else if (w < 8 || h < 8) margin = 1;
337
338 int n = w - margin*2;
339
340 for (int x = 0; x < n; ++x) {
341 double value = m_min + ((m_max - m_min) * x) / (n-1);
342 QColor colour(map(value));
343 paint.setPen(colour);
344 paint.drawLine(x + margin, margin, x + margin, h - margin);
345 }
346
347 return pmap;
348 }
349
350