comparison layer/TimeValueLayer.cpp @ 700:7846175403f1

And tidy up
author Chris Cannam
date Wed, 04 Dec 2013 13:12:09 +0000
parents 1a1448f7beb2
children 084f65094203
comparison
equal deleted inserted replaced
699:1a1448f7beb2 700:7846175403f1
1228 void 1228 void
1229 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const 1229 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const
1230 { 1230 {
1231 if (!m_model) return; 1231 if (!m_model) return;
1232 1232
1233 /*
1234 int h = v->height();
1235
1236 int n = 10;
1237
1238 float min, max;
1239 bool logarithmic;
1240 getScaleExtents(v, min, max, logarithmic);
1241
1242 if (m_plotStyle == PlotSegmentation) {
1243 QString unit;
1244 getValueExtents(min, max, logarithmic, unit);
1245 if (logarithmic) {
1246 LogRange::mapRange(min, max);
1247 }
1248 }
1249
1250 float val = min;
1251 float inc = (max - val) / n;
1252
1253 char buffer[40];
1254
1255 int w = getVerticalScaleWidth(v, false, paint);
1256
1257 int tx = 5;
1258
1259 int boxx = 5, boxy = 5;
1260 if (getScaleUnits() != "") {
1261 boxy += paint.fontMetrics().height();
1262 }
1263 int boxw = 10, boxh = h - boxy - 5;
1264
1265 if (m_plotStyle == PlotSegmentation) {
1266 tx += boxx + boxw;
1267 paint.drawRect(boxx, boxy, boxw, boxh);
1268 }
1269
1270 if (m_plotStyle == PlotSegmentation) {
1271 paint.save();
1272 for (int y = 0; y < boxh; ++y) {
1273 float val = ((boxh - y) * (max - min)) / boxh + min;
1274 if (logarithmic) {
1275 paint.setPen(getColourForValue(v, LogRange::unmap(val)));
1276 } else {
1277 paint.setPen(getColourForValue(v, val));
1278 }
1279 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1);
1280 }
1281 paint.restore();
1282 }
1283
1284 float round = 1.f;
1285 int dp = 0;
1286 if (inc > 0) {
1287 int prec = trunc(log10f(inc));
1288 prec -= 1;
1289 if (prec < 0) dp = -prec;
1290 round = powf(10.f, prec);
1291 #ifdef DEBUG_TIME_VALUE_LAYER
1292 cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << endl;
1293 #endif
1294 }
1295
1296 int prevy = -1;
1297
1298 for (int i = 0; i < n; ++i) {
1299
1300 int y, ty;
1301 bool drawText = true;
1302
1303 float dispval = val;
1304
1305 if (m_plotStyle == PlotSegmentation) {
1306 y = boxy + int(boxh - ((val - min) * boxh) / (max - min));
1307 ty = y;
1308 } else {
1309 if (i == n-1 &&
1310 v->height() < paint.fontMetrics().height() * (n*2)) {
1311 if (getScaleUnits() != "") drawText = false;
1312 }
1313 dispval = lrintf(val / round) * round;
1314 #ifdef DEBUG_TIME_VALUE_LAYER
1315 cerr << "val = " << val << ", dispval = " << dispval << endl;
1316 #endif
1317 if (logarithmic) {
1318 y = getYForValue(v, LogRange::unmap(dispval));
1319 } else {
1320 y = getYForValue(v, dispval);
1321 }
1322 ty = y - paint.fontMetrics().height() +
1323 paint.fontMetrics().ascent() + 2;
1324
1325 if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) {
1326 val += inc;
1327 continue;
1328 }
1329 }
1330
1331 if (logarithmic) {
1332 double dv = LogRange::unmap(dispval);
1333 int digits = trunc(log10f(dv));
1334 int sf = dp + (digits > 0 ? digits : 0);
1335 if (sf < 2) sf = 2;
1336 sprintf(buffer, "%.*g", sf, dv);
1337 } else {
1338 sprintf(buffer, "%.*f", dp, dispval);
1339 }
1340 QString label = QString(buffer);
1341
1342 if (m_plotStyle != PlotSegmentation) {
1343 paint.drawLine(w - 5, y, w, y);
1344 } else {
1345 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y);
1346 }
1347
1348 if (drawText) {
1349 if (m_plotStyle != PlotSegmentation) {
1350 paint.drawText(tx + w - paint.fontMetrics().width(label) - 8,
1351 ty, label);
1352 } else {
1353 paint.drawText(tx, ty, label);
1354 }
1355 }
1356
1357 prevy = y;
1358 val += inc;
1359 }
1360 */
1361 QString unit; 1233 QString unit;
1362 float min, max; 1234 float min, max;
1363 bool logarithmic; 1235 bool logarithmic;
1364 1236
1365 int w = getVerticalScaleWidth(v, false, paint); 1237 int w = getVerticalScaleWidth(v, false, paint);
1368 if (m_plotStyle == PlotSegmentation) { 1240 if (m_plotStyle == PlotSegmentation) {
1369 1241
1370 getValueExtents(min, max, logarithmic, unit); 1242 getValueExtents(min, max, logarithmic, unit);
1371 1243
1372 if (logarithmic) { 1244 if (logarithmic) {
1373
1374 LogRange::mapRange(min, max); 1245 LogRange::mapRange(min, max);
1375 LogColourScale().paintVertical(v, this, paint, 0, min, max); 1246 LogColourScale().paintVertical(v, this, paint, 0, min, max);
1376
1377 } else { 1247 } else {
1378 LinearColourScale().paintVertical(v, this, paint, 0, min, max); 1248 LinearColourScale().paintVertical(v, this, paint, 0, min, max);
1379 } 1249 }
1380 1250
1381 } else { 1251 } else {