Mercurial > hg > svgui
comparison view/Pane.cpp @ 266:aee39d8c0b83
* more on measurement tool
author | Chris Cannam |
---|---|
date | Thu, 21 Jun 2007 14:05:23 +0000 |
parents | 7e9e533f1863 |
children | 4ed1446ad604 |
comparison
equal
deleted
inserted
replaced
265:a3a54632cd4c | 266:aee39d8c0b83 |
---|---|
50 View(w, true), | 50 View(w, true), |
51 m_identifyFeatures(false), | 51 m_identifyFeatures(false), |
52 m_clickedInRange(false), | 52 m_clickedInRange(false), |
53 m_shiftPressed(false), | 53 m_shiftPressed(false), |
54 m_ctrlPressed(false), | 54 m_ctrlPressed(false), |
55 m_haveDraggingRect(false), | |
55 m_navigating(false), | 56 m_navigating(false), |
56 m_resizing(false), | 57 m_resizing(false), |
57 m_centreLineVisible(true), | 58 m_centreLineVisible(true), |
58 m_scaleWidth(0), | 59 m_scaleWidth(0), |
59 m_headsUpDisplay(0), | 60 m_headsUpDisplay(0), |
452 m_mousePos.x() - m_clickPos.x(), | 453 m_mousePos.x() - m_clickPos.x(), |
453 m_mousePos.y() - m_clickPos.y()); | 454 m_mousePos.y() - m_clickPos.y()); |
454 | 455 |
455 } | 456 } |
456 | 457 |
457 if (toolMode == ViewManager::MeasureMode && topLayer && | 458 if (toolMode == ViewManager::MeasureMode && topLayer) { |
458 m_haveMeasureRect) { | 459 drawMeasurementRects(topLayer, paint); |
459 if (m_measureCentreFrame != m_centreFrame) { | |
460 m_haveMeasureRect = false; | |
461 } else { | |
462 drawMeasurementRect(topLayer, paint); | |
463 } | |
464 } | 460 } |
465 | 461 |
466 if (selectionIsBeingEdited()) { | 462 if (selectionIsBeingEdited()) { |
467 drawEditingSelection(paint); | 463 drawEditingSelection(paint); |
468 } | 464 } |
748 } | 744 } |
749 } | 745 } |
750 } | 746 } |
751 | 747 |
752 void | 748 void |
753 Pane::drawMeasurementRect(Layer *topLayer, QPainter &paint) | 749 Pane::drawMeasurementRects(Layer *topLayer, QPainter &paint) |
754 { | 750 { |
751 if (m_haveDraggingRect) { | |
752 drawMeasurementRect(topLayer, m_draggingRect, paint); | |
753 } | |
754 | |
755 if (m_measureRects.find(topLayer) == m_measureRects.end() || | |
756 m_measureRects[topLayer].empty()) return; | |
757 | |
758 MeasureRectList &rects = m_measureRects[topLayer]; | |
759 | |
760 for (MeasureRectList::iterator i = rects.begin(); | |
761 i != rects.end(); ++i) { | |
762 drawMeasurementRect(topLayer, *i, paint); | |
763 } | |
764 } | |
765 | |
766 void | |
767 Pane::drawMeasurementRect(Layer *topLayer, MeasureRect &r, QPainter &paint) | |
768 { | |
769 if (topLayer->hasTimeXAxis()) { | |
770 r.start.rx() = getXForFrame(r.startFrame); | |
771 r.end.rx() = getXForFrame(r.endFrame); | |
772 } | |
773 | |
774 int lx = std::min(r.start.x(), r.end.x()); | |
775 int rx = std::max(r.start.x(), r.end.x()); | |
776 if (rx < 0 || lx >= width()) return; | |
777 | |
755 int fontHeight = paint.fontMetrics().height(); | 778 int fontHeight = paint.fontMetrics().height(); |
756 int fontAscent = paint.fontMetrics().ascent(); | 779 int fontAscent = paint.fontMetrics().ascent(); |
757 | 780 |
758 float v0, v1; | 781 float v0, v1; |
759 QString u0, u1; | 782 QString u0, u1; |
764 int axx, axy, bxx, bxy, dxx, dxy; | 787 int axx, axy, bxx, bxy, dxx, dxy; |
765 int aw = 0, bw = 0, dw = 0; | 788 int aw = 0, bw = 0, dw = 0; |
766 | 789 |
767 int labelCount = 0; | 790 int labelCount = 0; |
768 | 791 |
769 if ((b0 = topLayer->getXScaleValue(this, m_measureStart.x(), v0, u0))) { | 792 if ((b0 = topLayer->getXScaleValue(this, r.start.x(), v0, u0))) { |
770 axs = QString("%1 %2").arg(v0).arg(u0); | 793 axs = QString("%1 %2").arg(v0).arg(u0); |
771 aw = paint.fontMetrics().width(axs); | 794 aw = paint.fontMetrics().width(axs); |
772 ++labelCount; | 795 ++labelCount; |
773 } | 796 } |
774 | 797 |
775 if (m_measureStart != m_measureEnd) { | 798 if (r.start != r.end) { |
776 if ((b1 = topLayer->getXScaleValue(this, m_measureEnd.x(), v1, u1))) { | 799 if ((b1 = topLayer->getXScaleValue(this, r.end.x(), v1, u1))) { |
777 bxs = QString("%1 %2").arg(v1).arg(u1); | 800 bxs = QString("%1 %2").arg(v1).arg(u1); |
778 bw = paint.fontMetrics().width(bxs); | 801 bw = paint.fontMetrics().width(bxs); |
779 } | 802 } |
780 } | 803 } |
781 | 804 |
782 if (b0 && b1 && u0 == u1) { | 805 if (b0 && b1 && u0 == u1) { |
783 dxs = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); | 806 dxs = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); |
784 dw = paint.fontMetrics().width(dxs); | 807 dw = paint.fontMetrics().width(dxs); |
785 } | 808 } |
786 | 809 |
787 b0 = false; | 810 b0 = false; |
788 b1 = false; | 811 b1 = false; |
789 | 812 |
790 if ((b0 = topLayer->getYScaleValue(this, m_measureStart.y(), v0, u0))) { | 813 if ((b0 = topLayer->getYScaleValue(this, r.start.y(), v0, u0))) { |
791 ays = QString("%1 %2").arg(v0).arg(u0); | 814 ays = QString("%1 %2").arg(v0).arg(u0); |
792 aw = std::max(aw, paint.fontMetrics().width(ays)); | 815 aw = std::max(aw, paint.fontMetrics().width(ays)); |
793 ++labelCount; | 816 ++labelCount; |
794 } | 817 } |
795 | 818 |
796 if (m_measureStart != m_measureEnd) { | 819 if (r.start != r.end) { |
797 if ((b1 = topLayer->getYScaleValue(this, m_measureEnd.y(), v1, u1))) { | 820 if ((b1 = topLayer->getYScaleValue(this, r.end.y(), v1, u1))) { |
798 bys = QString("%1 %2").arg(v1).arg(u1); | 821 bys = QString("%1 %2").arg(v1).arg(u1); |
799 bw = std::max(bw, paint.fontMetrics().width(bys)); | 822 bw = std::max(bw, paint.fontMetrics().width(bys)); |
800 } | 823 } |
801 } | 824 } |
802 | 825 |
803 if (b0 && b1 && u0 == u1) { | 826 if (b0 && b1 && u0 == u1) { |
804 dys = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); | 827 dys = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); |
805 dw = std::max(dw, paint.fontMetrics().width(dys)); | 828 dw = std::max(dw, paint.fontMetrics().width(dys)); |
806 } | 829 } |
807 | 830 |
808 int mw = abs(m_measureEnd.x() - m_measureStart.x()); | 831 int mw = abs(r.end.x() - r.start.x()); |
809 int mh = abs(m_measureEnd.y() - m_measureStart.y()); | 832 int mh = abs(r.end.y() - r.start.y()); |
810 | 833 |
811 bool edgeLabelsInside = false; | 834 bool edgeLabelsInside = false; |
812 bool sizeLabelsInside = false; | 835 bool sizeLabelsInside = false; |
813 | 836 |
814 if (mw < std::max(aw, std::max(bw, dw)) + 4) { | 837 if (mw < std::max(aw, std::max(bw, dw)) + 4) { |
834 } | 857 } |
835 } | 858 } |
836 | 859 |
837 if (edgeLabelsInside) { | 860 if (edgeLabelsInside) { |
838 | 861 |
839 axx = m_measureStart.x() + 2; | 862 axx = r.start.x() + 2; |
840 axy = m_measureStart.y() + fontAscent + 2; | 863 axy = r.start.y() + fontAscent + 2; |
841 | 864 |
842 bxx = m_measureEnd.x() - bw - 2; | 865 bxx = r.end.x() - bw - 2; |
843 bxy = m_measureEnd.y() - (labelCount-1) * fontHeight - 2; | 866 bxy = r.end.y() - (labelCount-1) * fontHeight - 2; |
844 | 867 |
845 } else { | 868 } else { |
846 | 869 |
847 axx = m_measureStart.x() - aw - 2; | 870 axx = r.start.x() - aw - 2; |
848 axy = m_measureStart.y() + fontAscent; | 871 axy = r.start.y() + fontAscent; |
849 | 872 |
850 bxx = m_measureEnd.x() + 2; | 873 bxx = r.end.x() + 2; |
851 bxy = m_measureEnd.y() - (labelCount-1) * fontHeight; | 874 bxy = r.end.y() - (labelCount-1) * fontHeight; |
852 } | 875 } |
853 | 876 |
854 dxx = (m_measureEnd.x() - m_measureStart.x()) | 877 dxx = (r.end.x() - r.start.x()) |
855 / 2 + m_measureStart.x() - dw/2; | 878 / 2 + r.start.x() - dw/2; |
856 | 879 |
857 if (sizeLabelsInside) { | 880 if (sizeLabelsInside) { |
858 | 881 |
859 dxy = (m_measureEnd.y() - m_measureStart.y()) | 882 dxy = (r.end.y() - r.start.y()) |
860 / 2 + m_measureStart.y() - (labelCount * fontHeight)/2 + fontAscent; | 883 / 2 + r.start.y() - (labelCount * fontHeight)/2 + fontAscent; |
861 | 884 |
862 } else { | 885 } else { |
863 | 886 |
864 dxy = std::max(m_measureEnd.y(), m_measureStart.y()) + fontAscent + 2; | 887 dxy = std::max(r.end.y(), r.start.y()) + fontAscent + 2; |
865 } | 888 } |
866 | 889 |
867 if (axs != "") { | 890 if (axs != "") { |
868 drawVisibleText(paint, axx, axy, axs, OutlinedText); | 891 drawVisibleText(paint, axx, axy, axs, OutlinedText); |
869 axy += fontHeight; | 892 axy += fontHeight; |
892 if (dys != "") { | 915 if (dys != "") { |
893 drawVisibleText(paint, dxx, dxy, dys, OutlinedText); | 916 drawVisibleText(paint, dxx, dxy, dys, OutlinedText); |
894 dxy += fontHeight; | 917 dxy += fontHeight; |
895 } | 918 } |
896 | 919 |
897 if (m_measureStart != m_measureEnd) { | 920 if (r.start != r.end) { |
898 | 921 |
899 paint.save(); | 922 paint.save(); |
900 | 923 |
901 paint.setPen(Qt::green); | 924 paint.setPen(Qt::green); |
902 | 925 |
903 paint.drawRect(m_measureStart.x(), m_measureStart.y(), | 926 paint.drawRect(r.start.x(), r.start.y(), |
904 m_measureEnd.x() - m_measureStart.x(), | 927 r.end.x() - r.start.x(), |
905 m_measureEnd.y() - m_measureStart.y()); | 928 r.end.y() - r.start.y()); |
906 | 929 |
907 paint.restore(); | 930 paint.restore(); |
908 } | 931 } |
909 } | 932 } |
910 | 933 |
1252 } | 1275 } |
1253 } | 1276 } |
1254 | 1277 |
1255 } else if (mode == ViewManager::MeasureMode) { | 1278 } else if (mode == ViewManager::MeasureMode) { |
1256 | 1279 |
1280 //!!! command | |
1281 | |
1282 MeasureRect rect; | |
1283 | |
1284 rect.start = m_clickPos; | |
1285 rect.end = rect.start; | |
1286 | |
1287 rect.startFrame = getFrameForX(rect.start.x()); | |
1288 rect.endFrame = rect.startFrame; | |
1289 | |
1290 m_draggingRect = rect; | |
1291 m_haveDraggingRect = true; | |
1292 | |
1293 | |
1294 /*!!! | |
1257 m_measureStart = m_clickPos; | 1295 m_measureStart = m_clickPos; |
1258 m_measureEnd = m_clickPos; | 1296 m_measureEnd = m_measureStart; |
1297 | |
1298 m_measureStartFrame = getFrameForX(m_clickPos.x()); | |
1299 m_measureEndFrame = m_measureStartFrame; | |
1300 | |
1259 m_haveMeasureRect = true; | 1301 m_haveMeasureRect = true; |
1260 m_measureCentreFrame = m_centreFrame; | 1302 */ |
1261 update(); | 1303 update(); |
1262 } | 1304 } |
1263 | 1305 |
1264 emit paneInteractedWith(); | 1306 emit paneInteractedWith(); |
1265 } | 1307 } |
1340 } | 1382 } |
1341 } | 1383 } |
1342 | 1384 |
1343 } else if (mode == ViewManager::MeasureMode) { | 1385 } else if (mode == ViewManager::MeasureMode) { |
1344 | 1386 |
1387 if (m_haveDraggingRect) { | |
1388 | |
1389 LayerList::iterator vi = m_layers.end(); | |
1390 if (vi != m_layers.begin()) { | |
1391 Layer *topLayer = *(--vi); | |
1392 m_measureRects[topLayer].push_back(m_draggingRect); | |
1393 } | |
1394 | |
1395 m_haveDraggingRect = false; | |
1396 } | |
1397 | |
1345 setCursor(m_measureCursor1); | 1398 setCursor(m_measureCursor1); |
1346 } | 1399 } |
1347 | 1400 |
1348 m_clickedInRange = false; | 1401 m_clickedInRange = false; |
1349 | 1402 |
1429 } | 1482 } |
1430 | 1483 |
1431 } else if (mode == ViewManager::MeasureMode) { | 1484 } else if (mode == ViewManager::MeasureMode) { |
1432 | 1485 |
1433 setCursor(m_measureCursor2); | 1486 setCursor(m_measureCursor2); |
1434 m_measureEnd = e->pos(); | 1487 |
1435 update(); | 1488 if (m_haveDraggingRect) { |
1489 m_draggingRect.end = e->pos(); | |
1490 if (hasTopLayerTimeXAxis()) { | |
1491 m_draggingRect.endFrame = getFrameForX(m_draggingRect.end.x()); | |
1492 edgeScrollMaybe(e->x()); | |
1493 } | |
1494 update(); | |
1495 } | |
1436 } | 1496 } |
1437 } | 1497 } |
1438 | 1498 |
1439 void | 1499 void |
1440 Pane::zoomToRegion(int x0, int y0, int x1, int y1) | 1500 Pane::zoomToRegion(int x0, int y0, int x1, int y1) |