20 #include "base/AudioLevel.h" 21 #include "base/Strings.h" 22 #include "base/Debug.h" 24 #include <QPaintDevice> 32 double minVal,
double maxVal,
33 Scale scale,
int &mult,
36 static double meterdbs[] = { -40, -30, -20, -15, -10,
37 -5, -3, -2, -1, -0.5, 0 };
39 int h = rect.height(), w = rect.width();
40 int textHeight = paint.fontMetrics().height();
41 int toff = -textHeight/2 + paint.fontMetrics().ascent() + 1;
43 int lastLabelledY = -1;
51 step = (maxVal - minVal) / n;
52 int round = 0, limit = 10000000;
54 round = int(minVal + step * mult);
56 }
while (!round && mult < limit);
59 step = double(round) / mult;
60 n = int(lrint((maxVal - minVal) / step));
67 for (
int i = 0; i <= n; ++i) {
69 double val = 0.0, nval = 0.0;
75 val = (minVal + (i * step));
76 text = QString(
"%1").arg(mult * val);
80 val = AudioLevel::dB_to_multiplier(meterdbs[i]);
81 text = QString(
"%1").arg(meterdbs[i]);
82 if (i == n) text =
"0dB";
84 text = Strings::minus_infinity;
90 val = AudioLevel::dB_to_multiplier(-(10*n) + i * 10);
91 text = QString(
"%1").arg(-(10*n) + i * 10);
92 if (i == n) text =
"0dB";
94 text = Strings::minus_infinity;
100 if (val < minVal || val > maxVal)
continue;
102 int y =
getYForValue(scale, val, minVal, maxVal, rect.y(), h);
106 ny =
getYForValue(scale, nval, minVal, maxVal, rect.y(), h);
112 bool spaceForLabel = (i == 0 ||
113 abs(y - lastLabelledY) >= textHeight - 1);
120 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 123 if (paint.fontMetrics().width(text) < w - 10) {
124 tx = w - 10 - paint.fontMetrics().width(text);
129 if (ty < paint.fontMetrics().ascent()) {
130 ty = paint.fontMetrics().ascent();
135 paint.drawText(tx, ty, text);
137 lastLabelledY = ty - toff;
139 paint.drawLine(w - 7, y, w, y);
140 if (vy) vy->push_back(y);
143 paint.drawLine(w - 7, ny, w, ny);
144 if (vy) vy->push_back(ny);
149 paint.drawLine(w - 4, y, w, y);
150 if (vy) vy->push_back(y);
153 paint.drawLine(w - 4, ny, w, ny);
154 if (vy) vy->push_back(ny);
161 dBscale(
double sample,
int m,
double maxVal,
double minVal)
163 if (sample < 0.0)
return dBscale(-sample, m, maxVal, minVal);
164 double dB = AudioLevel::multiplier_to_dB(sample);
165 double mindB = AudioLevel::multiplier_to_dB(minVal);
166 double maxdB = AudioLevel::multiplier_to_dB(maxVal);
167 if (dB < mindB)
return 0;
168 if (dB > 0.0)
return m;
169 return int(((dB - mindB) * m) / (maxdB - mindB) + 0.1);
174 double minVal,
double maxVal,
175 int minY,
int height)
182 vy = minY + height - int(((value - minVal) / (maxVal - minVal)) * height);
186 vy = minY + height - AudioLevel::multiplier_to_preview
187 ((value - minVal) / (maxVal - minVal), height);
191 vy = minY + height -
dBscale(value, height, maxVal, minVal);
200 QPainter &paint,
int x,
int y,
208 QFont f(paint.font());
213 QColor penColour, surroundColour, boxColour;
217 boxColour = surroundColour;
218 boxColour.setAlpha(127);
220 paint.setPen(Qt::NoPen);
221 paint.setBrush(boxColour);
223 QRect r = paint.fontMetrics().boundingRect(text);
224 r.translate(QPoint(x, y));
226 paint.setBrush(Qt::NoBrush);
228 paint.setPen(surroundColour);
230 for (
int dx = -1; dx <= 1; ++dx) {
231 for (
int dy = -1; dy <= 1; ++dy) {
232 if (!(dx || dy))
continue;
233 paint.drawText(x + dx, y + dy, text);
237 paint.setPen(penColour);
239 paint.drawText(x, y, text);
245 std::cerr <<
"ERROR: PaintAssistant::drawVisibleText: Boxed style not yet implemented!" << std::endl;
virtual QColor getForeground() const =0
virtual QColor getBackground() const =0
static int getYForValue(Scale scale, double value, double minVal, double maxVal, int minY, int height)
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
static void paintVerticalLevelScale(QPainter &p, QRect rect, double minVal, double maxVal, Scale scale, int &multRtn, std::vector< int > *markCoordRtns=0)
static int dBscale(double sample, int m, double maxVal, double minVal)
static void drawVisibleText(const LayerGeometryProvider *, QPainter &p, int x, int y, QString text, TextStyle style)