Mercurial > hg > svgui
comparison layer/RegionLayer.cpp @ 978:64c2b3a4435a 3.0-integration
Merge from branch osx-retina
author | Chris Cannam |
---|---|
date | Fri, 26 Jun 2015 14:10:40 +0100 |
parents | 4fe7a09be0fe |
children | 2adca8f05583 |
comparison
equal
deleted
inserted
replaced
977:f40ccbf228c2 | 978:64c2b3a4435a |
---|---|
242 m_verticalScale = scale; | 242 m_verticalScale = scale; |
243 emit layerParametersChanged(); | 243 emit layerParametersChanged(); |
244 } | 244 } |
245 | 245 |
246 bool | 246 bool |
247 RegionLayer::isLayerScrollable(const View *v) const | 247 RegionLayer::isLayerScrollable(const LayerGeometryProvider *v) const |
248 { | 248 { |
249 QPoint discard; | 249 QPoint discard; |
250 return !v->shouldIlluminateLocalFeatures(this, discard); | 250 return !v->shouldIlluminateLocalFeatures(this, discard); |
251 } | 251 } |
252 | 252 |
300 | 300 |
301 return true; | 301 return true; |
302 } | 302 } |
303 | 303 |
304 RegionModel::PointList | 304 RegionModel::PointList |
305 RegionLayer::getLocalPoints(View *v, int x) const | 305 RegionLayer::getLocalPoints(LayerGeometryProvider *v, int x) const |
306 { | 306 { |
307 if (!m_model) return RegionModel::PointList(); | 307 if (!m_model) return RegionModel::PointList(); |
308 | 308 |
309 long frame = v->getFrameForX(x); | 309 long frame = v->getFrameForX(x); |
310 | 310 |
343 | 343 |
344 return usePoints; | 344 return usePoints; |
345 } | 345 } |
346 | 346 |
347 bool | 347 bool |
348 RegionLayer::getPointToDrag(View *v, int x, int y, RegionModel::Point &p) const | 348 RegionLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, RegionModel::Point &p) const |
349 { | 349 { |
350 if (!m_model) return false; | 350 if (!m_model) return false; |
351 | 351 |
352 long frame = v->getFrameForX(x); | 352 long frame = v->getFrameForX(x); |
353 | 353 |
381 } | 381 } |
382 return ""; | 382 return ""; |
383 } | 383 } |
384 | 384 |
385 QString | 385 QString |
386 RegionLayer::getFeatureDescription(View *v, QPoint &pos) const | 386 RegionLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const |
387 { | 387 { |
388 int x = pos.x(); | 388 int x = pos.x(); |
389 | 389 |
390 if (!m_model || !m_model->getSampleRate()) return ""; | 390 if (!m_model || !m_model->getSampleRate()) return ""; |
391 | 391 |
451 getYForValue(v, region.value)); | 451 getYForValue(v, region.value)); |
452 return text; | 452 return text; |
453 } | 453 } |
454 | 454 |
455 bool | 455 bool |
456 RegionLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, | 456 RegionLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
457 int &resolution, | 457 int &resolution, |
458 SnapType snap) const | 458 SnapType snap) const |
459 { | 459 { |
460 if (!m_model) { | 460 if (!m_model) { |
461 return Layer::snapToFeatureFrame(v, frame, resolution, snap); | 461 return Layer::snapToFeatureFrame(v, frame, resolution, snap); |
534 frame = snapped; | 534 frame = snapped; |
535 return found; | 535 return found; |
536 } | 536 } |
537 | 537 |
538 bool | 538 bool |
539 RegionLayer::snapToSimilarFeature(View *v, sv_frame_t &frame, | 539 RegionLayer::snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame, |
540 int &resolution, | 540 int &resolution, |
541 SnapType snap) const | 541 SnapType snap) const |
542 { | 542 { |
543 if (!m_model) { | 543 if (!m_model) { |
544 return Layer::snapToSimilarFeature(v, frame, resolution, snap); | 544 return Layer::snapToSimilarFeature(v, frame, resolution, snap); |
622 if (m_model) return m_model->getScaleUnits(); | 622 if (m_model) return m_model->getScaleUnits(); |
623 else return ""; | 623 else return ""; |
624 } | 624 } |
625 | 625 |
626 void | 626 void |
627 RegionLayer::getScaleExtents(View *v, double &min, double &max, bool &log) const | 627 RegionLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const |
628 { | 628 { |
629 min = 0.0; | 629 min = 0.0; |
630 max = 0.0; | 630 max = 0.0; |
631 log = false; | 631 log = false; |
632 | 632 |
674 | 674 |
675 if (max == min) max = min + 1.0; | 675 if (max == min) max = min + 1.0; |
676 } | 676 } |
677 | 677 |
678 int | 678 int |
679 RegionLayer::spacingIndexToY(View *v, int i) const | 679 RegionLayer::spacingIndexToY(LayerGeometryProvider *v, int i) const |
680 { | 680 { |
681 int h = v->height(); | 681 int h = v->getPaintHeight(); |
682 int n = int(m_spacingMap.size()); | 682 int n = int(m_spacingMap.size()); |
683 // this maps from i (spacing of the value from the spacing | 683 // this maps from i (spacing of the value from the spacing |
684 // map) and n (number of region types) to y | 684 // map) and n (number of region types) to y |
685 int y = h - (((h * i) / n) + (h / (2 * n))); | 685 int y = h - (((h * i) / n) + (h / (2 * n))); |
686 return y; | 686 return y; |
687 } | 687 } |
688 | 688 |
689 double | 689 double |
690 RegionLayer::yToSpacingIndex(View *v, int y) const | 690 RegionLayer::yToSpacingIndex(LayerGeometryProvider *v, int y) const |
691 { | 691 { |
692 // we return an inexact result here (double rather than int) | 692 // we return an inexact result here (double rather than int) |
693 int h = v->height(); | 693 int h = v->getPaintHeight(); |
694 int n = int(m_spacingMap.size()); | 694 int n = int(m_spacingMap.size()); |
695 // from y = h - ((h * i) / n) + (h / (2 * n)) as above (vh taking place of i) | 695 // from y = h - ((h * i) / n) + (h / (2 * n)) as above (vh taking place of i) |
696 double vh = double(2*h*n - h - 2*n*y) / double(2*h); | 696 double vh = double(2*h*n - h - 2*n*y) / double(2*h); |
697 return vh; | 697 return vh; |
698 } | 698 } |
699 | 699 |
700 int | 700 int |
701 RegionLayer::getYForValue(View *v, double val) const | 701 RegionLayer::getYForValue(LayerGeometryProvider *v, double val) const |
702 { | 702 { |
703 double min = 0.0, max = 0.0; | 703 double min = 0.0, max = 0.0; |
704 bool logarithmic = false; | 704 bool logarithmic = false; |
705 int h = v->height(); | 705 int h = v->getPaintHeight(); |
706 | 706 |
707 if (m_verticalScale == EqualSpaced) { | 707 if (m_verticalScale == EqualSpaced) { |
708 | 708 |
709 if (m_spacingMap.empty()) return h/2; | 709 if (m_spacingMap.empty()) return h/2; |
710 | 710 |
731 return int(h - ((val - min) * h) / (max - min)); | 731 return int(h - ((val - min) * h) / (max - min)); |
732 } | 732 } |
733 } | 733 } |
734 | 734 |
735 double | 735 double |
736 RegionLayer::getValueForY(View *v, int y) const | 736 RegionLayer::getValueForY(LayerGeometryProvider *v, int y) const |
737 { | 737 { |
738 return getValueForY(v, y, -1); | 738 return getValueForY(v, y, -1); |
739 } | 739 } |
740 | 740 |
741 double | 741 double |
742 RegionLayer::getValueForY(View *v, int y, int avoid) const | 742 RegionLayer::getValueForY(LayerGeometryProvider *v, int y, int avoid) const |
743 { | 743 { |
744 double min = 0.0, max = 0.0; | 744 double min = 0.0, max = 0.0; |
745 bool logarithmic = false; | 745 bool logarithmic = false; |
746 int h = v->height(); | 746 int h = v->getPaintHeight(); |
747 | 747 |
748 if (m_verticalScale == EqualSpaced) { | 748 if (m_verticalScale == EqualSpaced) { |
749 | 749 |
750 // if we're equal spaced, we probably want to snap to the | 750 // if we're equal spaced, we probably want to snap to the |
751 // nearest item when close to it, and give some notification | 751 // nearest item when close to it, and give some notification |
834 return val; | 834 return val; |
835 } | 835 } |
836 } | 836 } |
837 | 837 |
838 QColor | 838 QColor |
839 RegionLayer::getColourForValue(View *v, double val) const | 839 RegionLayer::getColourForValue(LayerGeometryProvider *v, double val) const |
840 { | 840 { |
841 double min, max; | 841 double min, max; |
842 bool log; | 842 bool log; |
843 getScaleExtents(v, min, max, log); | 843 getScaleExtents(v, min, max, log); |
844 | 844 |
864 return ColourDatabase::getInstance()->getColourIndex | 864 return ColourDatabase::getInstance()->getColourIndex |
865 (QString(darkbg ? "Bright Blue" : "Blue")); | 865 (QString(darkbg ? "Bright Blue" : "Blue")); |
866 } | 866 } |
867 | 867 |
868 void | 868 void |
869 RegionLayer::paint(View *v, QPainter &paint, QRect rect) const | 869 RegionLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const |
870 { | 870 { |
871 if (!m_model || !m_model->isOK()) return; | 871 if (!m_model || !m_model->isOK()) return; |
872 | 872 |
873 sv_samplerate_t sampleRate = m_model->getSampleRate(); | 873 sv_samplerate_t sampleRate = m_model->getSampleRate(); |
874 if (!sampleRate) return; | 874 if (!sampleRate) return; |
940 } | 940 } |
941 | 941 |
942 if (w < 1) w = 1; | 942 if (w < 1) w = 1; |
943 | 943 |
944 if (m_plotStyle == PlotSegmentation) { | 944 if (m_plotStyle == PlotSegmentation) { |
945 paint.setPen(getForegroundQColor(v)); | 945 paint.setPen(getForegroundQColor(v->getView())); |
946 paint.setBrush(getColourForValue(v, p.value)); | 946 paint.setBrush(getColourForValue(v, p.value)); |
947 } else { | 947 } else { |
948 paint.setPen(getBaseQColor()); | 948 paint.setPen(getBaseQColor()); |
949 paint.setBrush(brushColour); | 949 paint.setBrush(brushColour); |
950 } | 950 } |
956 if (!shouldIlluminate || | 956 if (!shouldIlluminate || |
957 // "illuminatePoint != p" | 957 // "illuminatePoint != p" |
958 RegionModel::Point::Comparator()(illuminatePoint, p) || | 958 RegionModel::Point::Comparator()(illuminatePoint, p) || |
959 RegionModel::Point::Comparator()(p, illuminatePoint)) { | 959 RegionModel::Point::Comparator()(p, illuminatePoint)) { |
960 | 960 |
961 paint.setPen(QPen(getForegroundQColor(v), 1)); | 961 paint.setPen(QPen(getForegroundQColor(v->getView()), 1)); |
962 paint.drawLine(x, 0, x, v->height()); | 962 paint.drawLine(x, 0, x, v->getPaintHeight()); |
963 paint.setPen(Qt::NoPen); | 963 paint.setPen(Qt::NoPen); |
964 | 964 |
965 } else { | 965 } else { |
966 paint.setPen(QPen(getForegroundQColor(v), 2)); | 966 paint.setPen(QPen(getForegroundQColor(v->getView()), 2)); |
967 } | 967 } |
968 | 968 |
969 paint.drawRect(x, -1, ex - x, v->height() + 2); | 969 paint.drawRect(x, -1, ex - x, v->getPaintHeight() + 2); |
970 | 970 |
971 } else { | 971 } else { |
972 | 972 |
973 if (shouldIlluminate && | 973 if (shouldIlluminate && |
974 // "illuminatePoint == p" | 974 // "illuminatePoint == p" |
1038 - paint.fontMetrics().descent(); | 1038 - paint.fontMetrics().descent(); |
1039 } else { | 1039 } else { |
1040 labelX = x + 5; | 1040 labelX = x + 5; |
1041 labelY = v->getTextLabelHeight(this, paint); | 1041 labelY = v->getTextLabelHeight(this, paint); |
1042 if (labelX < nextLabelMinX) { | 1042 if (labelX < nextLabelMinX) { |
1043 if (lastLabelY < v->height()/2) { | 1043 if (lastLabelY < v->getPaintHeight()/2) { |
1044 labelY = lastLabelY + fontHeight; | 1044 labelY = lastLabelY + fontHeight; |
1045 } | 1045 } |
1046 } | 1046 } |
1047 lastLabelY = labelY; | 1047 lastLabelY = labelY; |
1048 nextLabelMinX = labelX + paint.fontMetrics().width(label); | 1048 nextLabelMinX = labelX + paint.fontMetrics().width(label); |
1054 | 1054 |
1055 paint.restore(); | 1055 paint.restore(); |
1056 } | 1056 } |
1057 | 1057 |
1058 int | 1058 int |
1059 RegionLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const | 1059 RegionLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const |
1060 { | 1060 { |
1061 if (!m_model || | 1061 if (!m_model || |
1062 m_verticalScale == AutoAlignScale || | 1062 m_verticalScale == AutoAlignScale || |
1063 m_verticalScale == EqualSpaced) { | 1063 m_verticalScale == EqualSpaced) { |
1064 return 0; | 1064 return 0; |
1076 } | 1076 } |
1077 } | 1077 } |
1078 } | 1078 } |
1079 | 1079 |
1080 void | 1080 void |
1081 RegionLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const | 1081 RegionLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const |
1082 { | 1082 { |
1083 if (!m_model || m_model->getPoints().empty()) return; | 1083 if (!m_model || m_model->getPoints().empty()) return; |
1084 | 1084 |
1085 QString unit; | 1085 QString unit; |
1086 double min, max; | 1086 double min, max; |
1119 mw)); | 1119 mw)); |
1120 } | 1120 } |
1121 } | 1121 } |
1122 | 1122 |
1123 void | 1123 void |
1124 RegionLayer::drawStart(View *v, QMouseEvent *e) | 1124 RegionLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) |
1125 { | 1125 { |
1126 if (!m_model) return; | 1126 if (!m_model) return; |
1127 | 1127 |
1128 long frame = v->getFrameForX(e->x()); | 1128 long frame = v->getFrameForX(e->x()); |
1129 if (frame < 0) frame = 0; | 1129 if (frame < 0) frame = 0; |
1143 | 1143 |
1144 m_editing = true; | 1144 m_editing = true; |
1145 } | 1145 } |
1146 | 1146 |
1147 void | 1147 void |
1148 RegionLayer::drawDrag(View *v, QMouseEvent *e) | 1148 RegionLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) |
1149 { | 1149 { |
1150 if (!m_model || !m_editing) return; | 1150 if (!m_model || !m_editing) return; |
1151 | 1151 |
1152 sv_frame_t frame = v->getFrameForX(e->x()); | 1152 sv_frame_t frame = v->getFrameForX(e->x()); |
1153 if (frame < 0) frame = 0; | 1153 if (frame < 0) frame = 0; |
1173 | 1173 |
1174 recalcSpacing(); | 1174 recalcSpacing(); |
1175 } | 1175 } |
1176 | 1176 |
1177 void | 1177 void |
1178 RegionLayer::drawEnd(View *, QMouseEvent *) | 1178 RegionLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) |
1179 { | 1179 { |
1180 if (!m_model || !m_editing) return; | 1180 if (!m_model || !m_editing) return; |
1181 finish(m_editingCommand); | 1181 finish(m_editingCommand); |
1182 m_editingCommand = 0; | 1182 m_editingCommand = 0; |
1183 m_editing = false; | 1183 m_editing = false; |
1184 | 1184 |
1185 recalcSpacing(); | 1185 recalcSpacing(); |
1186 } | 1186 } |
1187 | 1187 |
1188 void | 1188 void |
1189 RegionLayer::eraseStart(View *v, QMouseEvent *e) | 1189 RegionLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) |
1190 { | 1190 { |
1191 if (!m_model) return; | 1191 if (!m_model) return; |
1192 | 1192 |
1193 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; | 1193 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; |
1194 | 1194 |
1200 m_editing = true; | 1200 m_editing = true; |
1201 recalcSpacing(); | 1201 recalcSpacing(); |
1202 } | 1202 } |
1203 | 1203 |
1204 void | 1204 void |
1205 RegionLayer::eraseDrag(View *, QMouseEvent *) | 1205 RegionLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) |
1206 { | 1206 { |
1207 } | 1207 } |
1208 | 1208 |
1209 void | 1209 void |
1210 RegionLayer::eraseEnd(View *v, QMouseEvent *e) | 1210 RegionLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) |
1211 { | 1211 { |
1212 if (!m_model || !m_editing) return; | 1212 if (!m_model || !m_editing) return; |
1213 | 1213 |
1214 m_editing = false; | 1214 m_editing = false; |
1215 | 1215 |
1227 m_editing = false; | 1227 m_editing = false; |
1228 recalcSpacing(); | 1228 recalcSpacing(); |
1229 } | 1229 } |
1230 | 1230 |
1231 void | 1231 void |
1232 RegionLayer::editStart(View *v, QMouseEvent *e) | 1232 RegionLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) |
1233 { | 1233 { |
1234 if (!m_model) return; | 1234 if (!m_model) return; |
1235 | 1235 |
1236 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) { | 1236 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) { |
1237 return; | 1237 return; |
1252 m_dragStartY = e->y(); | 1252 m_dragStartY = e->y(); |
1253 recalcSpacing(); | 1253 recalcSpacing(); |
1254 } | 1254 } |
1255 | 1255 |
1256 void | 1256 void |
1257 RegionLayer::editDrag(View *v, QMouseEvent *e) | 1257 RegionLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) |
1258 { | 1258 { |
1259 if (!m_model || !m_editing) return; | 1259 if (!m_model || !m_editing) return; |
1260 | 1260 |
1261 int xdist = e->x() - m_dragStartX; | 1261 int xdist = e->x() - m_dragStartX; |
1262 int ydist = e->y() - m_dragStartY; | 1262 int ydist = e->y() - m_dragStartY; |
1287 m_editingCommand->addPoint(m_editingPoint); | 1287 m_editingCommand->addPoint(m_editingPoint); |
1288 recalcSpacing(); | 1288 recalcSpacing(); |
1289 } | 1289 } |
1290 | 1290 |
1291 void | 1291 void |
1292 RegionLayer::editEnd(View *, QMouseEvent *) | 1292 RegionLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) |
1293 { | 1293 { |
1294 if (!m_model || !m_editing) return; | 1294 if (!m_model || !m_editing) return; |
1295 | 1295 |
1296 if (m_editingCommand) { | 1296 if (m_editingCommand) { |
1297 | 1297 |
1315 m_editing = false; | 1315 m_editing = false; |
1316 recalcSpacing(); | 1316 recalcSpacing(); |
1317 } | 1317 } |
1318 | 1318 |
1319 bool | 1319 bool |
1320 RegionLayer::editOpen(View *v, QMouseEvent *e) | 1320 RegionLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) |
1321 { | 1321 { |
1322 if (!m_model) return false; | 1322 if (!m_model) return false; |
1323 | 1323 |
1324 RegionModel::Point region(0); | 1324 RegionModel::Point region(0); |
1325 if (!getPointToDrag(v, e->x(), e->y(), region)) return false; | 1325 if (!getPointToDrag(v, e->x(), e->y(), region)) return false; |
1445 finish(command); | 1445 finish(command); |
1446 recalcSpacing(); | 1446 recalcSpacing(); |
1447 } | 1447 } |
1448 | 1448 |
1449 void | 1449 void |
1450 RegionLayer::copy(View *v, Selection s, Clipboard &to) | 1450 RegionLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) |
1451 { | 1451 { |
1452 if (!m_model) return; | 1452 if (!m_model) return; |
1453 | 1453 |
1454 RegionModel::PointList points = | 1454 RegionModel::PointList points = |
1455 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1455 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
1463 } | 1463 } |
1464 } | 1464 } |
1465 } | 1465 } |
1466 | 1466 |
1467 bool | 1467 bool |
1468 RegionLayer::paste(View *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) | 1468 RegionLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) |
1469 { | 1469 { |
1470 if (!m_model) return false; | 1470 if (!m_model) return false; |
1471 | 1471 |
1472 const Clipboard::PointList &points = from.getPoints(); | 1472 const Clipboard::PointList &points = from.getPoints(); |
1473 | 1473 |
1474 bool realign = false; | 1474 bool realign = false; |
1475 | 1475 |
1476 if (clipboardHasDifferentAlignment(v, from)) { | 1476 if (clipboardHasDifferentAlignment(v, from)) { |
1477 | 1477 |
1478 QMessageBox::StandardButton button = | 1478 QMessageBox::StandardButton button = |
1479 QMessageBox::question(v, tr("Re-align pasted items?"), | 1479 QMessageBox::question(v->getView(), tr("Re-align pasted items?"), |
1480 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?"), | 1480 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?"), |
1481 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, | 1481 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, |
1482 QMessageBox::Yes); | 1482 QMessageBox::Yes); |
1483 | 1483 |
1484 if (button == QMessageBox::Cancel) { | 1484 if (button == QMessageBox::Cancel) { |