comparison layer/TimeValueLayer.cpp @ 918:4fe7a09be0fe osx-retina

Many fixes for the previous stuff
author Chris Cannam
date Tue, 17 Mar 2015 16:56:03 +0000
parents 94e4952a6774
children a5488775f880
comparison
equal deleted inserted replaced
917:77a1d42353ce 918:4fe7a09be0fe
313 m_derivative = show; 313 m_derivative = show;
314 emit layerParametersChanged(); 314 emit layerParametersChanged();
315 } 315 }
316 316
317 bool 317 bool
318 TimeValueLayer::isLayerScrollable(const View *v) const 318 TimeValueLayer::isLayerScrollable(const LayerGeometryProvider *v) const
319 { 319 {
320 // We don't illuminate sections in the line or curve modes, so 320 // We don't illuminate sections in the line or curve modes, so
321 // they're always scrollable 321 // they're always scrollable
322 322
323 if (m_plotStyle == PlotLines || 323 if (m_plotStyle == PlotLines ||
527 527
528 return mapper; 528 return mapper;
529 } 529 }
530 530
531 SparseTimeValueModel::PointList 531 SparseTimeValueModel::PointList
532 TimeValueLayer::getLocalPoints(View *v, int x) const 532 TimeValueLayer::getLocalPoints(LayerGeometryProvider *v, int x) const
533 { 533 {
534 if (!m_model) return SparseTimeValueModel::PointList(); 534 if (!m_model) return SparseTimeValueModel::PointList();
535 535
536 sv_frame_t frame = v->getFrameForX(x); 536 sv_frame_t frame = v->getFrameForX(x);
537 537
584 } 584 }
585 return ""; 585 return "";
586 } 586 }
587 587
588 QString 588 QString
589 TimeValueLayer::getFeatureDescription(View *v, QPoint &pos) const 589 TimeValueLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
590 { 590 {
591 int x = pos.x(); 591 int x = pos.x();
592 592
593 if (!m_model || !m_model->getSampleRate()) return ""; 593 if (!m_model || !m_model->getSampleRate()) return "";
594 594
627 getYForValue(v, points.begin()->value)); 627 getYForValue(v, points.begin()->value));
628 return text; 628 return text;
629 } 629 }
630 630
631 bool 631 bool
632 TimeValueLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, 632 TimeValueLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
633 int &resolution, 633 int &resolution,
634 SnapType snap) const 634 SnapType snap) const
635 { 635 {
636 if (!m_model) { 636 if (!m_model) {
637 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 637 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
699 frame = snapped; 699 frame = snapped;
700 return found; 700 return found;
701 } 701 }
702 702
703 bool 703 bool
704 TimeValueLayer::snapToSimilarFeature(View *v, sv_frame_t &frame, 704 TimeValueLayer::snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame,
705 int &resolution, 705 int &resolution,
706 SnapType snap) const 706 SnapType snap) const
707 { 707 {
708 if (!m_model) { 708 if (!m_model) {
709 return Layer::snapToSimilarFeature(v, frame, resolution, snap); 709 return Layer::snapToSimilarFeature(v, frame, resolution, snap);
780 frame = snapped; 780 frame = snapped;
781 return found; 781 return found;
782 } 782 }
783 783
784 void 784 void
785 TimeValueLayer::getScaleExtents(View *v, double &min, double &max, bool &log) const 785 TimeValueLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const
786 { 786 {
787 min = 0.0; 787 min = 0.0;
788 max = 0.0; 788 max = 0.0;
789 log = false; 789 log = false;
790 790
816 cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << endl; 816 cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << endl;
817 #endif 817 #endif
818 } 818 }
819 819
820 int 820 int
821 TimeValueLayer::getYForValue(View *v, double val) const 821 TimeValueLayer::getYForValue(LayerGeometryProvider *v, double val) const
822 { 822 {
823 double min = 0.0, max = 0.0; 823 double min = 0.0, max = 0.0;
824 bool logarithmic = false; 824 bool logarithmic = false;
825 int h = v->height(); 825 int h = v->getPaintHeight();
826 826
827 getScaleExtents(v, min, max, logarithmic); 827 getScaleExtents(v, min, max, logarithmic);
828 828
829 #ifdef DEBUG_TIME_VALUE_LAYER 829 #ifdef DEBUG_TIME_VALUE_LAYER
830 cerr << "getYForValue(" << val << "): min " << min << ", max " 830 cerr << "getYForValue(" << val << "): min " << min << ", max "
837 837
838 return int(h - ((val - min) * h) / (max - min)); 838 return int(h - ((val - min) * h) / (max - min));
839 } 839 }
840 840
841 double 841 double
842 TimeValueLayer::getValueForY(View *v, int y) const 842 TimeValueLayer::getValueForY(LayerGeometryProvider *v, int y) const
843 { 843 {
844 double min = 0.0, max = 0.0; 844 double min = 0.0, max = 0.0;
845 bool logarithmic = false; 845 bool logarithmic = false;
846 int h = v->height(); 846 int h = v->getPaintHeight();
847 847
848 getScaleExtents(v, min, max, logarithmic); 848 getScaleExtents(v, min, max, logarithmic);
849 849
850 double val = min + (double(h - y) * double(max - min)) / h; 850 double val = min + (double(h - y) * double(max - min)) / h;
851 851
863 QString unit = getScaleUnits(); 863 QString unit = getScaleUnits();
864 return (m_verticalScale == AutoAlignScale && unit != ""); 864 return (m_verticalScale == AutoAlignScale && unit != "");
865 } 865 }
866 866
867 QColor 867 QColor
868 TimeValueLayer::getColourForValue(View *v, double val) const 868 TimeValueLayer::getColourForValue(LayerGeometryProvider *v, double val) const
869 { 869 {
870 double min, max; 870 double min, max;
871 bool log; 871 bool log;
872 getScaleExtents(v, min, max, log); 872 getScaleExtents(v, min, max, log);
873 873
929 929
930 double min = m_model->getValueMinimum(); 930 double min = m_model->getValueMinimum();
931 double max = m_model->getValueMaximum(); 931 double max = m_model->getValueMaximum();
932 if (max == min) max = min + 1.0; 932 if (max == min) max = min + 1.0;
933 933
934 int origin = int(nearbyint(v->height() - 934 int origin = int(nearbyint(v->getPaintHeight() -
935 (-min * v->height()) / (max - min))); 935 (-min * v->getPaintHeight()) / (max - min)));
936 936
937 QPoint localPos; 937 QPoint localPos;
938 sv_frame_t illuminateFrame = -1; 938 sv_frame_t illuminateFrame = -1;
939 939
940 if (v->shouldIlluminateLocalFeatures(this, localPos)) { 940 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
964 int textY = 0; 964 int textY = 0;
965 if (m_plotStyle == PlotSegmentation) { 965 if (m_plotStyle == PlotSegmentation) {
966 textY = v->getTextLabelHeight(this, paint); 966 textY = v->getTextLabelHeight(this, paint);
967 } else { 967 } else {
968 int originY = getYForValue(v, 0.f); 968 int originY = getYForValue(v, 0.f);
969 if (originY > 0 && originY < v->height()) { 969 if (originY > 0 && originY < v->getPaintHeight()) {
970 paint.save(); 970 paint.save();
971 paint.setPen(getPartialShades(v)[1]); 971 paint.setPen(getPartialShades(v)[1]);
972 paint.drawLine(x0, originY, x1, originY); 972 paint.drawLine(x0, originY, x1, originY);
973 paint.restore(); 973 paint.restore();
974 } 974 }
1169 paint.setPen(QPen(getForegroundQColor(v), 2)); 1169 paint.setPen(QPen(getForegroundQColor(v), 2));
1170 1170
1171 if (!illuminate) { 1171 if (!illuminate) {
1172 if (!m_drawSegmentDivisions || 1172 if (!m_drawSegmentDivisions ||
1173 nx < x + 5 || 1173 nx < x + 5 ||
1174 x >= v->width() - 1) { 1174 x >= v->getPaintWidth() - 1) {
1175 paint.setPen(Qt::NoPen); 1175 paint.setPen(Qt::NoPen);
1176 } 1176 }
1177 } 1177 }
1178 1178
1179 paint.drawRect(x, -1, nx - x, v->height() + 1); 1179 paint.drawRect(x, -1, nx - x, v->getPaintHeight() + 1);
1180 } 1180 }
1181 1181
1182 if (v->shouldShowFeatureLabels()) { 1182 if (v->shouldShowFeatureLabels()) {
1183 1183
1184 QString label = p.label; 1184 QString label = p.label;
1217 if (m_plotStyle == PlotDiscreteCurves) { 1217 if (m_plotStyle == PlotDiscreteCurves) {
1218 paint.setRenderHint(QPainter::Antialiasing, true); 1218 paint.setRenderHint(QPainter::Antialiasing, true);
1219 paint.drawPath(path); 1219 paint.drawPath(path);
1220 } else if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines) 1220 } else if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines)
1221 && !path.isEmpty()) { 1221 && !path.isEmpty()) {
1222 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width()); 1222 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->getPaintWidth());
1223 paint.drawPath(path); 1223 paint.drawPath(path);
1224 } 1224 }
1225 1225
1226 paint.restore(); 1226 paint.restore();
1227 1227
1228 // looks like save/restore doesn't deal with this: 1228 // looks like save/restore doesn't deal with this:
1229 paint.setRenderHint(QPainter::Antialiasing, false); 1229 paint.setRenderHint(QPainter::Antialiasing, false);
1230 } 1230 }
1231 1231
1232 int 1232 int
1233 TimeValueLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const 1233 TimeValueLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const
1234 { 1234 {
1235 if (!m_model || shouldAutoAlign()) { 1235 if (!m_model || shouldAutoAlign()) {
1236 return 0; 1236 return 0;
1237 } else if (m_plotStyle == PlotSegmentation) { 1237 } else if (m_plotStyle == PlotSegmentation) {
1238 if (m_verticalScale == LogScale) { 1238 if (m_verticalScale == LogScale) {
1248 } 1248 }
1249 } 1249 }
1250 } 1250 }
1251 1251
1252 void 1252 void
1253 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const 1253 TimeValueLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const
1254 { 1254 {
1255 if (!m_model || m_model->getPoints().empty()) return; 1255 if (!m_model || m_model->getPoints().empty()) return;
1256 1256
1257 QString unit; 1257 QString unit;
1258 double min, max; 1258 double min, max;
1259 bool logarithmic; 1259 bool logarithmic;
1260 1260
1261 int w = getVerticalScaleWidth(v, false, paint); 1261 int w = getVerticalScaleWidth(v, false, paint);
1262 int h = v->height(); 1262 int h = v->getPaintHeight();
1263 1263
1264 if (m_plotStyle == PlotSegmentation) { 1264 if (m_plotStyle == PlotSegmentation) {
1265 1265
1266 getValueExtents(min, max, logarithmic, unit); 1266 getValueExtents(min, max, logarithmic, unit);
1267 1267
1300 mw)); 1300 mw));
1301 } 1301 }
1302 } 1302 }
1303 1303
1304 void 1304 void
1305 TimeValueLayer::drawStart(View *v, QMouseEvent *e) 1305 TimeValueLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e)
1306 { 1306 {
1307 #ifdef DEBUG_TIME_VALUE_LAYER 1307 #ifdef DEBUG_TIME_VALUE_LAYER
1308 cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; 1308 cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl;
1309 #endif 1309 #endif
1310 1310
1350 1350
1351 m_editing = true; 1351 m_editing = true;
1352 } 1352 }
1353 1353
1354 void 1354 void
1355 TimeValueLayer::drawDrag(View *v, QMouseEvent *e) 1355 TimeValueLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e)
1356 { 1356 {
1357 #ifdef DEBUG_TIME_VALUE_LAYER 1357 #ifdef DEBUG_TIME_VALUE_LAYER
1358 cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; 1358 cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl;
1359 #endif 1359 #endif
1360 1360
1412 m_editingPoint.value = float(value); 1412 m_editingPoint.value = float(value);
1413 m_editingCommand->addPoint(m_editingPoint); 1413 m_editingCommand->addPoint(m_editingPoint);
1414 } 1414 }
1415 1415
1416 void 1416 void
1417 TimeValueLayer::drawEnd(View *, QMouseEvent *) 1417 TimeValueLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *)
1418 { 1418 {
1419 #ifdef DEBUG_TIME_VALUE_LAYER 1419 #ifdef DEBUG_TIME_VALUE_LAYER
1420 cerr << "TimeValueLayer::drawEnd" << endl; 1420 cerr << "TimeValueLayer::drawEnd" << endl;
1421 #endif 1421 #endif
1422 if (!m_model || !m_editing) return; 1422 if (!m_model || !m_editing) return;
1424 m_editingCommand = 0; 1424 m_editingCommand = 0;
1425 m_editing = false; 1425 m_editing = false;
1426 } 1426 }
1427 1427
1428 void 1428 void
1429 TimeValueLayer::eraseStart(View *v, QMouseEvent *e) 1429 TimeValueLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e)
1430 { 1430 {
1431 if (!m_model) return; 1431 if (!m_model) return;
1432 1432
1433 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); 1433 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
1434 if (points.empty()) return; 1434 if (points.empty()) return;
1442 1442
1443 m_editing = true; 1443 m_editing = true;
1444 } 1444 }
1445 1445
1446 void 1446 void
1447 TimeValueLayer::eraseDrag(View *, QMouseEvent *) 1447 TimeValueLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *)
1448 { 1448 {
1449 } 1449 }
1450 1450
1451 void 1451 void
1452 TimeValueLayer::eraseEnd(View *v, QMouseEvent *e) 1452 TimeValueLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e)
1453 { 1453 {
1454 if (!m_model || !m_editing) return; 1454 if (!m_model || !m_editing) return;
1455 1455
1456 m_editing = false; 1456 m_editing = false;
1457 1457
1469 m_editingCommand = 0; 1469 m_editingCommand = 0;
1470 m_editing = false; 1470 m_editing = false;
1471 } 1471 }
1472 1472
1473 void 1473 void
1474 TimeValueLayer::editStart(View *v, QMouseEvent *e) 1474 TimeValueLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e)
1475 { 1475 {
1476 #ifdef DEBUG_TIME_VALUE_LAYER 1476 #ifdef DEBUG_TIME_VALUE_LAYER
1477 cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; 1477 cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << endl;
1478 #endif 1478 #endif
1479 1479
1492 1492
1493 m_editing = true; 1493 m_editing = true;
1494 } 1494 }
1495 1495
1496 void 1496 void
1497 TimeValueLayer::editDrag(View *v, QMouseEvent *e) 1497 TimeValueLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e)
1498 { 1498 {
1499 #ifdef DEBUG_TIME_VALUE_LAYER 1499 #ifdef DEBUG_TIME_VALUE_LAYER
1500 cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; 1500 cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl;
1501 #endif 1501 #endif
1502 1502
1518 m_editingPoint.value = float(value); 1518 m_editingPoint.value = float(value);
1519 m_editingCommand->addPoint(m_editingPoint); 1519 m_editingCommand->addPoint(m_editingPoint);
1520 } 1520 }
1521 1521
1522 void 1522 void
1523 TimeValueLayer::editEnd(View *, QMouseEvent *) 1523 TimeValueLayer::editEnd(LayerGeometryProvider *, QMouseEvent *)
1524 { 1524 {
1525 #ifdef DEBUG_TIME_VALUE_LAYER 1525 #ifdef DEBUG_TIME_VALUE_LAYER
1526 cerr << "TimeValueLayer::editEnd" << endl; 1526 cerr << "TimeValueLayer::editEnd" << endl;
1527 #endif 1527 #endif
1528 if (!m_model || !m_editing) return; 1528 if (!m_model || !m_editing) return;
1548 m_editingCommand = 0; 1548 m_editingCommand = 0;
1549 m_editing = false; 1549 m_editing = false;
1550 } 1550 }
1551 1551
1552 bool 1552 bool
1553 TimeValueLayer::editOpen(View *v, QMouseEvent *e) 1553 TimeValueLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e)
1554 { 1554 {
1555 if (!m_model) return false; 1555 if (!m_model) return false;
1556 1556
1557 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); 1557 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
1558 if (points.empty()) return false; 1558 if (points.empty()) return false;
1671 1671
1672 finish(command); 1672 finish(command);
1673 } 1673 }
1674 1674
1675 void 1675 void
1676 TimeValueLayer::copy(View *v, Selection s, Clipboard &to) 1676 TimeValueLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to)
1677 { 1677 {
1678 if (!m_model) return; 1678 if (!m_model) return;
1679 1679
1680 SparseTimeValueModel::PointList points = 1680 SparseTimeValueModel::PointList points =
1681 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1681 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1689 } 1689 }
1690 } 1690 }
1691 } 1691 }
1692 1692
1693 bool 1693 bool
1694 TimeValueLayer::paste(View *v, const Clipboard &from, sv_frame_t /* frameOffset */, 1694 TimeValueLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */,
1695 bool interactive) 1695 bool interactive)
1696 { 1696 {
1697 if (!m_model) return false; 1697 if (!m_model) return false;
1698 1698
1699 const Clipboard::PointList &points = from.getPoints(); 1699 const Clipboard::PointList &points = from.getPoints();