Mercurial > hg > svgui
comparison layer/LogColourScale.cpp @ 946:36cddc3de023 alignment_view
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:19:52 +0100 |
parents | b66fb15de477 |
children | 4fe7a09be0fe |
comparison
equal
deleted
inserted
replaced
897:499b637f2a26 | 946:36cddc3de023 |
---|---|
34 void | 34 void |
35 LogColourScale::paintVertical(View *v, | 35 LogColourScale::paintVertical(View *v, |
36 const ColourScaleLayer *layer, | 36 const ColourScaleLayer *layer, |
37 QPainter &paint, | 37 QPainter &paint, |
38 int /* x0 */, | 38 int /* x0 */, |
39 float minlog, | 39 double minlog, |
40 float maxlog) | 40 double maxlog) |
41 { | 41 { |
42 int h = v->height(); | 42 int h = v->height(); |
43 | 43 |
44 int n = 10; | 44 int n = 10; |
45 | 45 |
46 float val = minlog; | 46 double val = minlog; |
47 float inc = (maxlog - val) / n; | 47 double inc = (maxlog - val) / n; |
48 | 48 |
49 const int buflen = 40; | 49 const int buflen = 40; |
50 char buffer[buflen]; | 50 char buffer[buflen]; |
51 | 51 |
52 int boxx = 5, boxy = 5; | 52 int boxx = 5, boxy = 5; |
58 int tx = 5 + boxx + boxw; | 58 int tx = 5 + boxx + boxw; |
59 paint.drawRect(boxx, boxy, boxw, boxh); | 59 paint.drawRect(boxx, boxy, boxw, boxh); |
60 | 60 |
61 paint.save(); | 61 paint.save(); |
62 for (int y = 0; y < boxh; ++y) { | 62 for (int y = 0; y < boxh; ++y) { |
63 float val = ((boxh - y) * (maxlog - minlog)) / boxh + minlog; | 63 double val = ((boxh - y) * (maxlog - minlog)) / boxh + minlog; |
64 paint.setPen(layer->getColourForValue(v, LogRange::unmap(val))); | 64 paint.setPen(layer->getColourForValue(v, LogRange::unmap(val))); |
65 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1); | 65 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1); |
66 } | 66 } |
67 paint.restore(); | 67 paint.restore(); |
68 | 68 |
69 int dp = 0; | 69 int dp = 0; |
70 if (inc > 0) { | 70 if (inc > 0) { |
71 int prec = trunc(log10f(inc)); | 71 int prec = int(trunc(log10(inc))); |
72 prec -= 1; | 72 prec -= 1; |
73 if (prec < 0) dp = -prec; | 73 if (prec < 0) dp = -prec; |
74 } | 74 } |
75 | 75 |
76 for (int i = 0; i < n; ++i) { | 76 for (int i = 0; i < n; ++i) { |
81 | 81 |
82 ty = y - paint.fontMetrics().height() + | 82 ty = y - paint.fontMetrics().height() + |
83 paint.fontMetrics().ascent() + 2; | 83 paint.fontMetrics().ascent() + 2; |
84 | 84 |
85 double dv = LogRange::unmap(val); | 85 double dv = LogRange::unmap(val); |
86 int digits = trunc(log10f(dv)); | 86 int digits = int(trunc(log10(dv))); |
87 int sf = dp + (digits > 0 ? digits : 0); | 87 int sf = dp + (digits > 0 ? digits : 0); |
88 if (sf < 2) sf = 2; | 88 if (sf < 2) sf = 2; |
89 snprintf(buffer, buflen, "%.*g", sf, dv); | 89 snprintf(buffer, buflen, "%.*g", sf, dv); |
90 | 90 |
91 QString label = QString(buffer); | 91 QString label = QString(buffer); |