Mercurial > hg > svgui
comparison layer/TimeValueLayer.cpp @ 702:ceb9a2992d96 tonioni
Merge from default branch
author | Chris Cannam |
---|---|
date | Wed, 04 Dec 2013 13:46:29 +0000 |
parents | e77b1673e17e 084f65094203 |
children | 137d3ff48f73 |
comparison
equal
deleted
inserted
replaced
696:e77b1673e17e | 702:ceb9a2992d96 |
---|---|
26 #include "data/model/SparseTimeValueModel.h" | 26 #include "data/model/SparseTimeValueModel.h" |
27 #include "data/model/Labeller.h" | 27 #include "data/model/Labeller.h" |
28 | 28 |
29 #include "widgets/ItemEditDialog.h" | 29 #include "widgets/ItemEditDialog.h" |
30 #include "widgets/ListInputDialog.h" | 30 #include "widgets/ListInputDialog.h" |
31 #include "widgets/TextAbbrev.h" | |
31 | 32 |
32 #include "ColourMapper.h" | 33 #include "ColourMapper.h" |
33 #include "PianoScale.h" | 34 #include "PianoScale.h" |
34 #include "LinearNumericalScale.h" | 35 #include "LinearNumericalScale.h" |
35 #include "LogNumericalScale.h" | 36 #include "LogNumericalScale.h" |
37 #include "LinearColourScale.h" | |
38 #include "LogColourScale.h" | |
36 | 39 |
37 #include <QPainter> | 40 #include <QPainter> |
38 #include <QPainterPath> | 41 #include <QPainterPath> |
39 #include <QMouseEvent> | 42 #include <QMouseEvent> |
40 #include <QRegExp> | 43 #include <QRegExp> |
1205 } | 1208 } |
1206 | 1209 |
1207 int | 1210 int |
1208 TimeValueLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const | 1211 TimeValueLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const |
1209 { | 1212 { |
1210 int w = 0; | 1213 if (!m_model || shouldAutoAlign()) { |
1211 if (m_verticalScale == LogScale) { | 1214 return 0; |
1212 w = LogNumericalScale().getWidth(v, paint); | 1215 } else if (m_plotStyle == PlotSegmentation) { |
1216 if (m_verticalScale == LogScale) { | |
1217 return LogColourScale().getWidth(v, paint); | |
1218 } else { | |
1219 return LinearColourScale().getWidth(v, paint); | |
1220 } | |
1213 } else { | 1221 } else { |
1214 w = LinearNumericalScale().getWidth(v, paint); | 1222 if (m_verticalScale == LogScale) { |
1215 } | 1223 return LogNumericalScale().getWidth(v, paint) + 10; // for piano |
1216 if (m_plotStyle == PlotSegmentation) return w + 20; | 1224 } else { |
1217 else return w + 10; | 1225 return LinearNumericalScale().getWidth(v, paint); |
1226 } | |
1227 } | |
1218 } | 1228 } |
1219 | 1229 |
1220 void | 1230 void |
1221 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const | 1231 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const |
1222 { | 1232 { |
1223 if (!m_model) return; | 1233 if (!m_model) return; |
1224 | 1234 |
1225 /* | 1235 QString unit; |
1226 int h = v->height(); | |
1227 | |
1228 int n = 10; | |
1229 | |
1230 float min, max; | 1236 float min, max; |
1231 bool logarithmic; | 1237 bool logarithmic; |
1232 getScaleExtents(v, min, max, logarithmic); | 1238 |
1239 int w = getVerticalScaleWidth(v, false, paint); | |
1240 int h = v->height(); | |
1233 | 1241 |
1234 if (m_plotStyle == PlotSegmentation) { | 1242 if (m_plotStyle == PlotSegmentation) { |
1235 QString unit; | 1243 |
1236 getValueExtents(min, max, logarithmic, unit); | 1244 getValueExtents(min, max, logarithmic, unit); |
1245 | |
1237 if (logarithmic) { | 1246 if (logarithmic) { |
1238 LogRange::mapRange(min, max); | 1247 LogRange::mapRange(min, max); |
1239 } | 1248 LogColourScale().paintVertical(v, this, paint, 0, min, max); |
1240 } | |
1241 | |
1242 float val = min; | |
1243 float inc = (max - val) / n; | |
1244 | |
1245 char buffer[40]; | |
1246 | |
1247 int w = getVerticalScaleWidth(v, false, paint); | |
1248 | |
1249 int tx = 5; | |
1250 | |
1251 int boxx = 5, boxy = 5; | |
1252 if (getScaleUnits() != "") { | |
1253 boxy += paint.fontMetrics().height(); | |
1254 } | |
1255 int boxw = 10, boxh = h - boxy - 5; | |
1256 | |
1257 if (m_plotStyle == PlotSegmentation) { | |
1258 tx += boxx + boxw; | |
1259 paint.drawRect(boxx, boxy, boxw, boxh); | |
1260 } | |
1261 | |
1262 if (m_plotStyle == PlotSegmentation) { | |
1263 paint.save(); | |
1264 for (int y = 0; y < boxh; ++y) { | |
1265 float val = ((boxh - y) * (max - min)) / boxh + min; | |
1266 if (logarithmic) { | |
1267 paint.setPen(getColourForValue(v, LogRange::unmap(val))); | |
1268 } else { | |
1269 paint.setPen(getColourForValue(v, val)); | |
1270 } | |
1271 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1); | |
1272 } | |
1273 paint.restore(); | |
1274 } | |
1275 | |
1276 float round = 1.f; | |
1277 int dp = 0; | |
1278 if (inc > 0) { | |
1279 int prec = trunc(log10f(inc)); | |
1280 prec -= 1; | |
1281 if (prec < 0) dp = -prec; | |
1282 round = powf(10.f, prec); | |
1283 #ifdef DEBUG_TIME_VALUE_LAYER | |
1284 cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << endl; | |
1285 #endif | |
1286 } | |
1287 | |
1288 int prevy = -1; | |
1289 | |
1290 for (int i = 0; i < n; ++i) { | |
1291 | |
1292 int y, ty; | |
1293 bool drawText = true; | |
1294 | |
1295 float dispval = val; | |
1296 | |
1297 if (m_plotStyle == PlotSegmentation) { | |
1298 y = boxy + int(boxh - ((val - min) * boxh) / (max - min)); | |
1299 ty = y; | |
1300 } else { | 1249 } else { |
1301 if (i == n-1 && | 1250 LinearColourScale().paintVertical(v, this, paint, 0, min, max); |
1302 v->height() < paint.fontMetrics().height() * (n*2)) { | 1251 } |
1303 if (getScaleUnits() != "") drawText = false; | |
1304 } | |
1305 dispval = lrintf(val / round) * round; | |
1306 #ifdef DEBUG_TIME_VALUE_LAYER | |
1307 cerr << "val = " << val << ", dispval = " << dispval << endl; | |
1308 #endif | |
1309 if (logarithmic) { | |
1310 y = getYForValue(v, LogRange::unmap(dispval)); | |
1311 } else { | |
1312 y = getYForValue(v, dispval); | |
1313 } | |
1314 ty = y - paint.fontMetrics().height() + | |
1315 paint.fontMetrics().ascent() + 2; | |
1316 | |
1317 if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) { | |
1318 val += inc; | |
1319 continue; | |
1320 } | |
1321 } | |
1322 | |
1323 if (logarithmic) { | |
1324 double dv = LogRange::unmap(dispval); | |
1325 int digits = trunc(log10f(dv)); | |
1326 int sf = dp + (digits > 0 ? digits : 0); | |
1327 if (sf < 2) sf = 2; | |
1328 sprintf(buffer, "%.*g", sf, dv); | |
1329 } else { | |
1330 sprintf(buffer, "%.*f", dp, dispval); | |
1331 } | |
1332 QString label = QString(buffer); | |
1333 | |
1334 if (m_plotStyle != PlotSegmentation) { | |
1335 paint.drawLine(w - 5, y, w, y); | |
1336 } else { | |
1337 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y); | |
1338 } | |
1339 | |
1340 if (drawText) { | |
1341 if (m_plotStyle != PlotSegmentation) { | |
1342 paint.drawText(tx + w - paint.fontMetrics().width(label) - 8, | |
1343 ty, label); | |
1344 } else { | |
1345 paint.drawText(tx, ty, label); | |
1346 } | |
1347 } | |
1348 | |
1349 prevy = y; | |
1350 val += inc; | |
1351 } | |
1352 */ | |
1353 float min, max; | |
1354 bool logarithmic; | |
1355 getScaleExtents(v, min, max, logarithmic); | |
1356 | |
1357 int w = getVerticalScaleWidth(v, false, paint); | |
1358 int h = v->height(); | |
1359 | |
1360 if (m_plotStyle == PlotSegmentation) { | |
1361 | |
1362 //!!! todo! | |
1363 | 1252 |
1364 } else { | 1253 } else { |
1254 | |
1255 getScaleExtents(v, min, max, logarithmic); | |
1365 | 1256 |
1366 if (logarithmic) { | 1257 if (logarithmic) { |
1367 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); | 1258 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); |
1368 } else { | 1259 } else { |
1369 LinearNumericalScale().paintVertical(v, this, paint, 0, min, max); | 1260 LinearNumericalScale().paintVertical(v, this, paint, 0, min, max); |
1377 paint.drawLine(w, 0, w, h); | 1268 paint.drawLine(w, 0, w, h); |
1378 } | 1269 } |
1379 } | 1270 } |
1380 | 1271 |
1381 if (getScaleUnits() != "") { | 1272 if (getScaleUnits() != "") { |
1382 paint.drawText(5, 5 + paint.fontMetrics().ascent(), | 1273 int mw = w - 5; |
1383 getScaleUnits()); | 1274 paint.drawText(5, |
1275 5 + paint.fontMetrics().ascent(), | |
1276 TextAbbrev::abbreviate(getScaleUnits(), | |
1277 paint.fontMetrics(), | |
1278 mw)); | |
1384 } | 1279 } |
1385 } | 1280 } |
1386 | 1281 |
1387 void | 1282 void |
1388 TimeValueLayer::drawStart(View *v, QMouseEvent *e) | 1283 TimeValueLayer::drawStart(View *v, QMouseEvent *e) |