Mercurial > hg > svgui
comparison layer/TimeValueLayer.cpp @ 696:e77b1673e17e tonioni
Pull out log and linear vertical scales into their own classes, make some improvements to log numbering
author | Chris Cannam |
---|---|
date | Wed, 04 Dec 2013 11:35:08 +0000 |
parents | 5674950ed82a |
children | ceb9a2992d96 |
comparison
equal
deleted
inserted
replaced
695:6d9624e0ac55 | 696:e77b1673e17e |
---|---|
29 #include "widgets/ItemEditDialog.h" | 29 #include "widgets/ItemEditDialog.h" |
30 #include "widgets/ListInputDialog.h" | 30 #include "widgets/ListInputDialog.h" |
31 | 31 |
32 #include "ColourMapper.h" | 32 #include "ColourMapper.h" |
33 #include "PianoScale.h" | 33 #include "PianoScale.h" |
34 #include "LinearNumericalScale.h" | |
35 #include "LogNumericalScale.h" | |
34 | 36 |
35 #include <QPainter> | 37 #include <QPainter> |
36 #include <QPainterPath> | 38 #include <QPainterPath> |
37 #include <QMouseEvent> | 39 #include <QMouseEvent> |
38 #include <QRegExp> | 40 #include <QRegExp> |
142 return tr("Plot Type"); | 144 return tr("Plot Type"); |
143 } | 145 } |
144 return SingleColourLayer::getPropertyGroupName(name); | 146 return SingleColourLayer::getPropertyGroupName(name); |
145 } | 147 } |
146 | 148 |
149 QString | |
150 TimeValueLayer::getScaleUnits() const | |
151 { | |
152 if (m_model) return m_model->getScaleUnits(); | |
153 else return ""; | |
154 } | |
155 | |
147 int | 156 int |
148 TimeValueLayer::getPropertyRangeAndValue(const PropertyName &name, | 157 TimeValueLayer::getPropertyRangeAndValue(const PropertyName &name, |
149 int *min, int *max, int *deflt) const | 158 int *min, int *max, int *deflt) const |
150 { | 159 { |
151 int val = 0; | 160 int val = 0; |
177 } else if (name == "Scale Units") { | 186 } else if (name == "Scale Units") { |
178 | 187 |
179 if (deflt) *deflt = 0; | 188 if (deflt) *deflt = 0; |
180 if (m_model) { | 189 if (m_model) { |
181 val = UnitDatabase::getInstance()->getUnitId | 190 val = UnitDatabase::getInstance()->getUnitId |
182 (m_model->getScaleUnits()); | 191 (getScaleUnits()); |
183 } | 192 } |
184 | 193 |
185 } else if (name == "Draw Segment Division Lines") { | 194 } else if (name == "Draw Segment Division Lines") { |
186 | 195 |
187 if (min) *min = 0; | 196 if (min) *min = 0; |
325 min = m_model->getValueMinimum(); | 334 min = m_model->getValueMinimum(); |
326 max = m_model->getValueMaximum(); | 335 max = m_model->getValueMaximum(); |
327 | 336 |
328 logarithmic = (m_verticalScale == LogScale); | 337 logarithmic = (m_verticalScale == LogScale); |
329 | 338 |
330 unit = m_model->getScaleUnits(); | 339 unit = getScaleUnits(); |
331 | 340 |
332 if (m_derivative) { | 341 if (m_derivative) { |
333 max = std::max(fabsf(min), fabsf(max)); | 342 max = std::max(fabsf(min), fabsf(max)); |
334 min = -max; | 343 min = -max; |
335 } | 344 } |
593 long useFrame = points.begin()->frame; | 602 long useFrame = points.begin()->frame; |
594 | 603 |
595 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); | 604 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); |
596 | 605 |
597 QString text; | 606 QString text; |
598 QString unit = m_model->getScaleUnits(); | 607 QString unit = getScaleUnits(); |
599 if (unit != "") unit = " " + unit; | 608 if (unit != "") unit = " " + unit; |
600 | 609 |
601 if (points.begin()->label == "") { | 610 if (points.begin()->label == "") { |
602 text = QString(tr("Time:\t%1\nValue:\t%2%3\nNo label")) | 611 text = QString(tr("Time:\t%1\nValue:\t%2%3\nNo label")) |
603 .arg(rt.toText(true).c_str()) | 612 .arg(rt.toText(true).c_str()) |
768 max = 0.0; | 777 max = 0.0; |
769 log = false; | 778 log = false; |
770 | 779 |
771 if (shouldAutoAlign()) { | 780 if (shouldAutoAlign()) { |
772 | 781 |
773 if (!v->getValueExtents(m_model->getScaleUnits(), min, max, log)) { | 782 if (!v->getValueExtents(getScaleUnits(), min, max, log)) { |
774 min = m_model->getValueMinimum(); | 783 min = m_model->getValueMinimum(); |
775 max = m_model->getValueMaximum(); | 784 max = m_model->getValueMaximum(); |
776 } else if (log) { | 785 } else if (log) { |
777 LogRange::mapRange(min, max); | 786 LogRange::mapRange(min, max); |
778 } | 787 } |
838 | 847 |
839 bool | 848 bool |
840 TimeValueLayer::shouldAutoAlign() const | 849 TimeValueLayer::shouldAutoAlign() const |
841 { | 850 { |
842 if (!m_model) return false; | 851 if (!m_model) return false; |
843 QString unit = m_model->getScaleUnits(); | 852 QString unit = getScaleUnits(); |
844 return (m_verticalScale == AutoAlignScale && unit != ""); | 853 return (m_verticalScale == AutoAlignScale && unit != ""); |
845 } | 854 } |
846 | 855 |
847 QColor | 856 QColor |
848 TimeValueLayer::getColourForValue(View *v, float val) const | 857 TimeValueLayer::getColourForValue(View *v, float val) const |
1194 // looks like save/restore doesn't deal with this: | 1203 // looks like save/restore doesn't deal with this: |
1195 paint.setRenderHint(QPainter::Antialiasing, false); | 1204 paint.setRenderHint(QPainter::Antialiasing, false); |
1196 } | 1205 } |
1197 | 1206 |
1198 int | 1207 int |
1199 TimeValueLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const | 1208 TimeValueLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const |
1200 { | 1209 { |
1201 int w = paint.fontMetrics().width("-000.000"); | 1210 int w = 0; |
1211 if (m_verticalScale == LogScale) { | |
1212 w = LogNumericalScale().getWidth(v, paint); | |
1213 } else { | |
1214 w = LinearNumericalScale().getWidth(v, paint); | |
1215 } | |
1202 if (m_plotStyle == PlotSegmentation) return w + 20; | 1216 if (m_plotStyle == PlotSegmentation) return w + 20; |
1203 else return w + 10; | 1217 else return w + 10; |
1204 } | 1218 } |
1205 | 1219 |
1206 void | 1220 void |
1207 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const | 1221 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const |
1208 { | 1222 { |
1209 if (!m_model) return; | 1223 if (!m_model) return; |
1210 | 1224 |
1225 /* | |
1211 int h = v->height(); | 1226 int h = v->height(); |
1212 | 1227 |
1213 int n = 10; | 1228 int n = 10; |
1214 | 1229 |
1215 float min, max; | 1230 float min, max; |
1232 int w = getVerticalScaleWidth(v, false, paint); | 1247 int w = getVerticalScaleWidth(v, false, paint); |
1233 | 1248 |
1234 int tx = 5; | 1249 int tx = 5; |
1235 | 1250 |
1236 int boxx = 5, boxy = 5; | 1251 int boxx = 5, boxy = 5; |
1237 if (m_model->getScaleUnits() != "") { | 1252 if (getScaleUnits() != "") { |
1238 boxy += paint.fontMetrics().height(); | 1253 boxy += paint.fontMetrics().height(); |
1239 } | 1254 } |
1240 int boxw = 10, boxh = h - boxy - 5; | 1255 int boxw = 10, boxh = h - boxy - 5; |
1241 | 1256 |
1242 if (m_plotStyle == PlotSegmentation) { | 1257 if (m_plotStyle == PlotSegmentation) { |
1283 y = boxy + int(boxh - ((val - min) * boxh) / (max - min)); | 1298 y = boxy + int(boxh - ((val - min) * boxh) / (max - min)); |
1284 ty = y; | 1299 ty = y; |
1285 } else { | 1300 } else { |
1286 if (i == n-1 && | 1301 if (i == n-1 && |
1287 v->height() < paint.fontMetrics().height() * (n*2)) { | 1302 v->height() < paint.fontMetrics().height() * (n*2)) { |
1288 if (m_model->getScaleUnits() != "") drawText = false; | 1303 if (getScaleUnits() != "") drawText = false; |
1289 } | 1304 } |
1290 dispval = lrintf(val / round) * round; | 1305 dispval = lrintf(val / round) * round; |
1291 #ifdef DEBUG_TIME_VALUE_LAYER | 1306 #ifdef DEBUG_TIME_VALUE_LAYER |
1292 cerr << "val = " << val << ", dispval = " << dispval << endl; | 1307 cerr << "val = " << val << ", dispval = " << dispval << endl; |
1293 #endif | 1308 #endif |
1332 } | 1347 } |
1333 | 1348 |
1334 prevy = y; | 1349 prevy = y; |
1335 val += inc; | 1350 val += inc; |
1336 } | 1351 } |
1337 | 1352 */ |
1338 if (m_model->getScaleUnits() != "") { | 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 | |
1364 } else { | |
1365 | |
1366 if (logarithmic) { | |
1367 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); | |
1368 } else { | |
1369 LinearNumericalScale().paintVertical(v, this, paint, 0, min, max); | |
1370 } | |
1371 | |
1372 if (logarithmic && (getScaleUnits() == "Hz")) { | |
1373 PianoScale().paintPianoVertical | |
1374 (v, paint, QRect(w - 10, 0, 10, h), | |
1375 LogRange::unmap(min), | |
1376 LogRange::unmap(max)); | |
1377 paint.drawLine(w, 0, w, h); | |
1378 } | |
1379 } | |
1380 | |
1381 if (getScaleUnits() != "") { | |
1339 paint.drawText(5, 5 + paint.fontMetrics().ascent(), | 1382 paint.drawText(5, 5 + paint.fontMetrics().ascent(), |
1340 m_model->getScaleUnits()); | 1383 getScaleUnits()); |
1341 } | |
1342 | |
1343 if (logarithmic && | |
1344 (m_model->getScaleUnits() == "Hz") && | |
1345 (m_plotStyle != PlotSegmentation)) { | |
1346 float fmin, fmax; | |
1347 getDisplayExtents(fmin, fmax); | |
1348 PianoScale().paintPianoVertical | |
1349 (v, paint, QRect(w, 0, 10, h), fmin, fmax); | |
1350 paint.drawLine(w + 10, 0, w + 10, h); | |
1351 } | 1384 } |
1352 } | 1385 } |
1353 | 1386 |
1354 void | 1387 void |
1355 TimeValueLayer::drawStart(View *v, QMouseEvent *e) | 1388 TimeValueLayer::drawStart(View *v, QMouseEvent *e) |
1612 ItemEditDialog *dialog = new ItemEditDialog | 1645 ItemEditDialog *dialog = new ItemEditDialog |
1613 (m_model->getSampleRate(), | 1646 (m_model->getSampleRate(), |
1614 ItemEditDialog::ShowTime | | 1647 ItemEditDialog::ShowTime | |
1615 ItemEditDialog::ShowValue | | 1648 ItemEditDialog::ShowValue | |
1616 ItemEditDialog::ShowText, | 1649 ItemEditDialog::ShowText, |
1617 m_model->getScaleUnits()); | 1650 getScaleUnits()); |
1618 | 1651 |
1619 dialog->setFrameTime(point.frame); | 1652 dialog->setFrameTime(point.frame); |
1620 dialog->setValue(point.value); | 1653 dialog->setValue(point.value); |
1621 dialog->setText(point.label); | 1654 dialog->setText(point.label); |
1622 | 1655 |