comparison layer/TimeValueLayer.cpp @ 978:64c2b3a4435a 3.0-integration

Merge from branch osx-retina
author Chris Cannam
date Fri, 26 Jun 2015 14:10:40 +0100
parents fa96108d552d
children ee01a4062747
comparison
equal deleted inserted replaced
977:f40ccbf228c2 978:64c2b3a4435a
314 m_derivative = show; 314 m_derivative = show;
315 emit layerParametersChanged(); 315 emit layerParametersChanged();
316 } 316 }
317 317
318 bool 318 bool
319 TimeValueLayer::isLayerScrollable(const View *v) const 319 TimeValueLayer::isLayerScrollable(const LayerGeometryProvider *v) const
320 { 320 {
321 // We don't illuminate sections in the line or curve modes, so 321 // We don't illuminate sections in the line or curve modes, so
322 // they're always scrollable 322 // they're always scrollable
323 323
324 if (m_plotStyle == PlotLines || 324 if (m_plotStyle == PlotLines ||
528 528
529 return mapper; 529 return mapper;
530 } 530 }
531 531
532 SparseTimeValueModel::PointList 532 SparseTimeValueModel::PointList
533 TimeValueLayer::getLocalPoints(View *v, int x) const 533 TimeValueLayer::getLocalPoints(LayerGeometryProvider *v, int x) const
534 { 534 {
535 if (!m_model) return SparseTimeValueModel::PointList(); 535 if (!m_model) return SparseTimeValueModel::PointList();
536 536
537 sv_frame_t frame = v->getFrameForX(x); 537 sv_frame_t frame = v->getFrameForX(x);
538 538
585 } 585 }
586 return ""; 586 return "";
587 } 587 }
588 588
589 QString 589 QString
590 TimeValueLayer::getFeatureDescription(View *v, QPoint &pos) const 590 TimeValueLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
591 { 591 {
592 int x = pos.x(); 592 int x = pos.x();
593 593
594 if (!m_model || !m_model->getSampleRate()) return ""; 594 if (!m_model || !m_model->getSampleRate()) return "";
595 595
639 getYForValue(v, points.begin()->value)); 639 getYForValue(v, points.begin()->value));
640 return text; 640 return text;
641 } 641 }
642 642
643 bool 643 bool
644 TimeValueLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, 644 TimeValueLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
645 int &resolution, 645 int &resolution,
646 SnapType snap) const 646 SnapType snap) const
647 { 647 {
648 if (!m_model) { 648 if (!m_model) {
649 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 649 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
711 frame = snapped; 711 frame = snapped;
712 return found; 712 return found;
713 } 713 }
714 714
715 bool 715 bool
716 TimeValueLayer::snapToSimilarFeature(View *v, sv_frame_t &frame, 716 TimeValueLayer::snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame,
717 int &resolution, 717 int &resolution,
718 SnapType snap) const 718 SnapType snap) const
719 { 719 {
720 if (!m_model) { 720 if (!m_model) {
721 return Layer::snapToSimilarFeature(v, frame, resolution, snap); 721 return Layer::snapToSimilarFeature(v, frame, resolution, snap);
792 frame = snapped; 792 frame = snapped;
793 return found; 793 return found;
794 } 794 }
795 795
796 void 796 void
797 TimeValueLayer::getScaleExtents(View *v, double &min, double &max, bool &log) const 797 TimeValueLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const
798 { 798 {
799 min = 0.0; 799 min = 0.0;
800 max = 0.0; 800 max = 0.0;
801 log = false; 801 log = false;
802 802
828 cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << endl; 828 cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << endl;
829 #endif 829 #endif
830 } 830 }
831 831
832 int 832 int
833 TimeValueLayer::getYForValue(View *v, double val) const 833 TimeValueLayer::getYForValue(LayerGeometryProvider *v, double val) const
834 { 834 {
835 double min = 0.0, max = 0.0; 835 double min = 0.0, max = 0.0;
836 bool logarithmic = false; 836 bool logarithmic = false;
837 int h = v->height(); 837 int h = v->getPaintHeight();
838 838
839 getScaleExtents(v, min, max, logarithmic); 839 getScaleExtents(v, min, max, logarithmic);
840 840
841 #ifdef DEBUG_TIME_VALUE_LAYER 841 #ifdef DEBUG_TIME_VALUE_LAYER
842 cerr << "getYForValue(" << val << "): min " << min << ", max " 842 cerr << "getYForValue(" << val << "): min " << min << ", max "
849 849
850 return int(h - ((val - min) * h) / (max - min)); 850 return int(h - ((val - min) * h) / (max - min));
851 } 851 }
852 852
853 double 853 double
854 TimeValueLayer::getValueForY(View *v, int y) const 854 TimeValueLayer::getValueForY(LayerGeometryProvider *v, int y) const
855 { 855 {
856 double min = 0.0, max = 0.0; 856 double min = 0.0, max = 0.0;
857 bool logarithmic = false; 857 bool logarithmic = false;
858 int h = v->height(); 858 int h = v->getPaintHeight();
859 859
860 getScaleExtents(v, min, max, logarithmic); 860 getScaleExtents(v, min, max, logarithmic);
861 861
862 double val = min + (double(h - y) * double(max - min)) / h; 862 double val = min + (double(h - y) * double(max - min)) / h;
863 863
875 QString unit = getScaleUnits(); 875 QString unit = getScaleUnits();
876 return (m_verticalScale == AutoAlignScale && unit != ""); 876 return (m_verticalScale == AutoAlignScale && unit != "");
877 } 877 }
878 878
879 QColor 879 QColor
880 TimeValueLayer::getColourForValue(View *v, double val) const 880 TimeValueLayer::getColourForValue(LayerGeometryProvider *v, double val) const
881 { 881 {
882 double min, max; 882 double min, max;
883 bool log; 883 bool log;
884 getScaleExtents(v, min, max, log); 884 getScaleExtents(v, min, max, log);
885 885
906 return ColourDatabase::getInstance()->getColourIndex 906 return ColourDatabase::getInstance()->getColourIndex
907 (QString(darkbg ? "Bright Green" : "Green")); 907 (QString(darkbg ? "Bright Green" : "Green"));
908 } 908 }
909 909
910 void 910 void
911 TimeValueLayer::paint(View *v, QPainter &paint, QRect rect) const 911 TimeValueLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
912 { 912 {
913 if (!m_model || !m_model->isOK()) return; 913 if (!m_model || !m_model->isOK()) return;
914 914
915 sv_samplerate_t sampleRate = m_model->getSampleRate(); 915 sv_samplerate_t sampleRate = m_model->getSampleRate();
916 if (!sampleRate) return; 916 if (!sampleRate) return;
941 941
942 double min = m_model->getValueMinimum(); 942 double min = m_model->getValueMinimum();
943 double max = m_model->getValueMaximum(); 943 double max = m_model->getValueMaximum();
944 if (max == min) max = min + 1.0; 944 if (max == min) max = min + 1.0;
945 945
946 int origin = int(nearbyint(v->height() - 946 int origin = int(nearbyint(v->getPaintHeight() -
947 (-min * v->height()) / (max - min))); 947 (-min * v->getPaintHeight()) / (max - min)));
948 948
949 QPoint localPos; 949 QPoint localPos;
950 sv_frame_t illuminateFrame = -1; 950 sv_frame_t illuminateFrame = -1;
951 951
952 if (v->shouldIlluminateLocalFeatures(this, localPos)) { 952 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
976 int textY = 0; 976 int textY = 0;
977 if (m_plotStyle == PlotSegmentation) { 977 if (m_plotStyle == PlotSegmentation) {
978 textY = v->getTextLabelHeight(this, paint); 978 textY = v->getTextLabelHeight(this, paint);
979 } else { 979 } else {
980 int originY = getYForValue(v, 0.f); 980 int originY = getYForValue(v, 0.f);
981 if (originY > 0 && originY < v->height()) { 981 if (originY > 0 && originY < v->getPaintHeight()) {
982 paint.save(); 982 paint.save();
983 paint.setPen(getPartialShades(v)[1]); 983 paint.setPen(getPartialShades(v)[1]);
984 paint.drawLine(x0, originY, x1, originY); 984 paint.drawLine(x0, originY, x1, originY);
985 paint.restore(); 985 paint.restore();
986 } 986 }
1181 paint.setPen(QPen(getForegroundQColor(v), 2)); 1181 paint.setPen(QPen(getForegroundQColor(v), 2));
1182 1182
1183 if (!illuminate) { 1183 if (!illuminate) {
1184 if (!m_drawSegmentDivisions || 1184 if (!m_drawSegmentDivisions ||
1185 nx < x + 5 || 1185 nx < x + 5 ||
1186 x >= v->width() - 1) { 1186 x >= v->getPaintWidth() - 1) {
1187 paint.setPen(Qt::NoPen); 1187 paint.setPen(Qt::NoPen);
1188 } 1188 }
1189 } 1189 }
1190 1190
1191 paint.drawRect(x, -1, nx - x, v->height() + 1); 1191 paint.drawRect(x, -1, nx - x, v->getPaintHeight() + 1);
1192 } 1192 }
1193 1193
1194 if (v->shouldShowFeatureLabels()) { 1194 if (v->shouldShowFeatureLabels()) {
1195 1195
1196 QString label = p.label; 1196 QString label = p.label;
1229 if (m_plotStyle == PlotDiscreteCurves) { 1229 if (m_plotStyle == PlotDiscreteCurves) {
1230 paint.setRenderHint(QPainter::Antialiasing, true); 1230 paint.setRenderHint(QPainter::Antialiasing, true);
1231 paint.drawPath(path); 1231 paint.drawPath(path);
1232 } else if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines) 1232 } else if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines)
1233 && !path.isEmpty()) { 1233 && !path.isEmpty()) {
1234 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width()); 1234 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->getPaintWidth());
1235 paint.drawPath(path); 1235 paint.drawPath(path);
1236 } 1236 }
1237 1237
1238 paint.restore(); 1238 paint.restore();
1239 1239
1240 // looks like save/restore doesn't deal with this: 1240 // looks like save/restore doesn't deal with this:
1241 paint.setRenderHint(QPainter::Antialiasing, false); 1241 paint.setRenderHint(QPainter::Antialiasing, false);
1242 } 1242 }
1243 1243
1244 int 1244 int
1245 TimeValueLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const 1245 TimeValueLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const
1246 { 1246 {
1247 if (!m_model || shouldAutoAlign()) { 1247 if (!m_model || shouldAutoAlign()) {
1248 return 0; 1248 return 0;
1249 } else if (m_plotStyle == PlotSegmentation) { 1249 } else if (m_plotStyle == PlotSegmentation) {
1250 if (m_verticalScale == LogScale) { 1250 if (m_verticalScale == LogScale) {
1260 } 1260 }
1261 } 1261 }
1262 } 1262 }
1263 1263
1264 void 1264 void
1265 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const 1265 TimeValueLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const
1266 { 1266 {
1267 if (!m_model || m_model->getPoints().empty()) return; 1267 if (!m_model || m_model->getPoints().empty()) return;
1268 1268
1269 QString unit; 1269 QString unit;
1270 double min, max; 1270 double min, max;
1271 bool logarithmic; 1271 bool logarithmic;
1272 1272
1273 int w = getVerticalScaleWidth(v, false, paint); 1273 int w = getVerticalScaleWidth(v, false, paint);
1274 int h = v->height(); 1274 int h = v->getPaintHeight();
1275 1275
1276 if (m_plotStyle == PlotSegmentation) { 1276 if (m_plotStyle == PlotSegmentation) {
1277 1277
1278 getValueExtents(min, max, logarithmic, unit); 1278 getValueExtents(min, max, logarithmic, unit);
1279 1279
1312 mw)); 1312 mw));
1313 } 1313 }
1314 } 1314 }
1315 1315
1316 void 1316 void
1317 TimeValueLayer::drawStart(View *v, QMouseEvent *e) 1317 TimeValueLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e)
1318 { 1318 {
1319 #ifdef DEBUG_TIME_VALUE_LAYER 1319 #ifdef DEBUG_TIME_VALUE_LAYER
1320 cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; 1320 cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl;
1321 #endif 1321 #endif
1322 1322
1362 1362
1363 m_editing = true; 1363 m_editing = true;
1364 } 1364 }
1365 1365
1366 void 1366 void
1367 TimeValueLayer::drawDrag(View *v, QMouseEvent *e) 1367 TimeValueLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e)
1368 { 1368 {
1369 #ifdef DEBUG_TIME_VALUE_LAYER 1369 #ifdef DEBUG_TIME_VALUE_LAYER
1370 cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; 1370 cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl;
1371 #endif 1371 #endif
1372 1372
1424 m_editingPoint.value = float(value); 1424 m_editingPoint.value = float(value);
1425 m_editingCommand->addPoint(m_editingPoint); 1425 m_editingCommand->addPoint(m_editingPoint);
1426 } 1426 }
1427 1427
1428 void 1428 void
1429 TimeValueLayer::drawEnd(View *, QMouseEvent *) 1429 TimeValueLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *)
1430 { 1430 {
1431 #ifdef DEBUG_TIME_VALUE_LAYER 1431 #ifdef DEBUG_TIME_VALUE_LAYER
1432 cerr << "TimeValueLayer::drawEnd" << endl; 1432 cerr << "TimeValueLayer::drawEnd" << endl;
1433 #endif 1433 #endif
1434 if (!m_model || !m_editing) return; 1434 if (!m_model || !m_editing) return;
1436 m_editingCommand = 0; 1436 m_editingCommand = 0;
1437 m_editing = false; 1437 m_editing = false;
1438 } 1438 }
1439 1439
1440 void 1440 void
1441 TimeValueLayer::eraseStart(View *v, QMouseEvent *e) 1441 TimeValueLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e)
1442 { 1442 {
1443 if (!m_model) return; 1443 if (!m_model) return;
1444 1444
1445 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); 1445 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
1446 if (points.empty()) return; 1446 if (points.empty()) return;
1454 1454
1455 m_editing = true; 1455 m_editing = true;
1456 } 1456 }
1457 1457
1458 void 1458 void
1459 TimeValueLayer::eraseDrag(View *, QMouseEvent *) 1459 TimeValueLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *)
1460 { 1460 {
1461 } 1461 }
1462 1462
1463 void 1463 void
1464 TimeValueLayer::eraseEnd(View *v, QMouseEvent *e) 1464 TimeValueLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e)
1465 { 1465 {
1466 if (!m_model || !m_editing) return; 1466 if (!m_model || !m_editing) return;
1467 1467
1468 m_editing = false; 1468 m_editing = false;
1469 1469
1481 m_editingCommand = 0; 1481 m_editingCommand = 0;
1482 m_editing = false; 1482 m_editing = false;
1483 } 1483 }
1484 1484
1485 void 1485 void
1486 TimeValueLayer::editStart(View *v, QMouseEvent *e) 1486 TimeValueLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e)
1487 { 1487 {
1488 #ifdef DEBUG_TIME_VALUE_LAYER 1488 #ifdef DEBUG_TIME_VALUE_LAYER
1489 cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; 1489 cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << endl;
1490 #endif 1490 #endif
1491 1491
1504 1504
1505 m_editing = true; 1505 m_editing = true;
1506 } 1506 }
1507 1507
1508 void 1508 void
1509 TimeValueLayer::editDrag(View *v, QMouseEvent *e) 1509 TimeValueLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e)
1510 { 1510 {
1511 #ifdef DEBUG_TIME_VALUE_LAYER 1511 #ifdef DEBUG_TIME_VALUE_LAYER
1512 cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; 1512 cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl;
1513 #endif 1513 #endif
1514 1514
1530 m_editingPoint.value = float(value); 1530 m_editingPoint.value = float(value);
1531 m_editingCommand->addPoint(m_editingPoint); 1531 m_editingCommand->addPoint(m_editingPoint);
1532 } 1532 }
1533 1533
1534 void 1534 void
1535 TimeValueLayer::editEnd(View *, QMouseEvent *) 1535 TimeValueLayer::editEnd(LayerGeometryProvider *, QMouseEvent *)
1536 { 1536 {
1537 #ifdef DEBUG_TIME_VALUE_LAYER 1537 #ifdef DEBUG_TIME_VALUE_LAYER
1538 cerr << "TimeValueLayer::editEnd" << endl; 1538 cerr << "TimeValueLayer::editEnd" << endl;
1539 #endif 1539 #endif
1540 if (!m_model || !m_editing) return; 1540 if (!m_model || !m_editing) return;
1560 m_editingCommand = 0; 1560 m_editingCommand = 0;
1561 m_editing = false; 1561 m_editing = false;
1562 } 1562 }
1563 1563
1564 bool 1564 bool
1565 TimeValueLayer::editOpen(View *v, QMouseEvent *e) 1565 TimeValueLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e)
1566 { 1566 {
1567 if (!m_model) return false; 1567 if (!m_model) return false;
1568 1568
1569 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); 1569 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
1570 if (points.empty()) return false; 1570 if (points.empty()) return false;
1683 1683
1684 finish(command); 1684 finish(command);
1685 } 1685 }
1686 1686
1687 void 1687 void
1688 TimeValueLayer::copy(View *v, Selection s, Clipboard &to) 1688 TimeValueLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to)
1689 { 1689 {
1690 if (!m_model) return; 1690 if (!m_model) return;
1691 1691
1692 SparseTimeValueModel::PointList points = 1692 SparseTimeValueModel::PointList points =
1693 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1693 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1701 } 1701 }
1702 } 1702 }
1703 } 1703 }
1704 1704
1705 bool 1705 bool
1706 TimeValueLayer::paste(View *v, const Clipboard &from, sv_frame_t /* frameOffset */, 1706 TimeValueLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */,
1707 bool interactive) 1707 bool interactive)
1708 { 1708 {
1709 if (!m_model) return false; 1709 if (!m_model) return false;
1710 1710
1711 const Clipboard::PointList &points = from.getPoints(); 1711 const Clipboard::PointList &points = from.getPoints();
1713 bool realign = false; 1713 bool realign = false;
1714 1714
1715 if (clipboardHasDifferentAlignment(v, from)) { 1715 if (clipboardHasDifferentAlignment(v, from)) {
1716 1716
1717 QMessageBox::StandardButton button = 1717 QMessageBox::StandardButton button =
1718 QMessageBox::question(v, tr("Re-align pasted items?"), 1718 QMessageBox::question(v->getView(), tr("Re-align pasted items?"),
1719 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), 1719 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
1720 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, 1720 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
1721 QMessageBox::Yes); 1721 QMessageBox::Yes);
1722 1722
1723 if (button == QMessageBox::Cancel) { 1723 if (button == QMessageBox::Cancel) {