comparison layer/LinearColourScale.cpp @ 1324:13d9b422f7fe zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:31 +0100
parents a34a2a25907c
children f2525e6cbdf1
comparison
equal deleted inserted replaced
1183:57d192e26331 1324:13d9b422f7fe
22 22
23 #include "LayerGeometryProvider.h" 23 #include "LayerGeometryProvider.h"
24 24
25 int 25 int
26 LinearColourScale::getWidth(LayerGeometryProvider *, 26 LinearColourScale::getWidth(LayerGeometryProvider *,
27 QPainter &paint) 27 QPainter &paint)
28 { 28 {
29 return paint.fontMetrics().width("-000.00") + 15; 29 return paint.fontMetrics().width("-000.00") + 15;
30 } 30 }
31 31
32 void 32 void
33 LinearColourScale::paintVertical(LayerGeometryProvider *v, 33 LinearColourScale::paintVertical(LayerGeometryProvider *v,
34 const ColourScaleLayer *layer, 34 const ColourScaleLayer *layer,
35 QPainter &paint, 35 QPainter &paint,
36 int /* x0 */, 36 int /* x0 */,
37 double min, 37 double min,
38 double max) 38 double max)
39 { 39 {
40 int h = v->getPaintHeight(); 40 int h = v->getPaintHeight();
41 41
42 int n = 10; 42 int n = 10;
43 43
56 int tx = 5 + boxx + boxw; 56 int tx = 5 + boxx + boxw;
57 paint.drawRect(boxx, boxy, boxw, boxh); 57 paint.drawRect(boxx, boxy, boxw, boxh);
58 58
59 paint.save(); 59 paint.save();
60 for (int y = 0; y < boxh; ++y) { 60 for (int y = 0; y < boxh; ++y) {
61 double val = ((boxh - y) * (max - min)) / boxh + min; 61 double val = ((boxh - y) * (max - min)) / boxh + min;
62 paint.setPen(layer->getColourForValue(v, val)); 62 paint.setPen(layer->getColourForValue(v, val));
63 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1); 63 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1);
64 } 64 }
65 paint.restore(); 65 paint.restore();
66 66
67 // double round = 1.f; 67 // double round = 1.f;
68 int dp = 0; 68 int dp = 0;
76 //#endif 76 //#endif
77 } 77 }
78 78
79 for (int i = 0; i < n; ++i) { 79 for (int i = 0; i < n; ++i) {
80 80
81 int y, ty; 81 int y, ty;
82 82
83 y = boxy + int(boxh - ((val - min) * boxh) / (max - min)); 83 y = boxy + int(boxh - ((val - min) * boxh) / (max - min));
84 84
85 ty = y - paint.fontMetrics().height() + 85 ty = y - paint.fontMetrics().height() +
86 paint.fontMetrics().ascent() + 2; 86 paint.fontMetrics().ascent() + 2;
87 87
88 snprintf(buffer, buflen, "%.*f", dp, val); 88 snprintf(buffer, buflen, "%.*f", dp, val);
89 QString label = QString(buffer); 89 QString label = QString(buffer);
90 90
91 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y); 91 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y);
92 paint.drawText(tx, ty, label); 92 paint.drawText(tx, ty, label);
93 93
94 val += inc; 94 val += inc;
95 } 95 }
96 } 96 }