Mercurial > hg > svgui
comparison 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 |
comparison
equal
deleted
inserted
replaced
1183:57d192e26331 | 1324:13d9b422f7fe |
---|---|
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 { |
63 m_map(map), | 65 m_map(map), |
64 m_min(min), | 66 m_min(min), |
65 m_max(max) | 67 m_max(max) |
66 { | 68 { |
67 if (m_min == m_max) { | 69 if (m_min == m_max) { |
68 cerr << "WARNING: ColourMapper: min == max (== " << m_min | 70 SVCERR << "WARNING: ColourMapper: min == max (== " << m_min |
69 << "), adjusting" << endl; | 71 << "), adjusting" << endl; |
70 m_max = m_min + 1; | 72 m_max = m_min + 1; |
71 } | 73 } |
72 } | 74 } |
73 | 75 |
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 |