Mercurial > hg > svgui
comparison view/Pane.cpp @ 267:4ed1446ad604
* more on measurement tool -- pull out some logic from pane to layer &c
still more to do
author | Chris Cannam |
---|---|
date | Thu, 21 Jun 2007 16:12:00 +0000 |
parents | aee39d8c0b83 |
children | 70537b0434c4 |
comparison
equal
deleted
inserted
replaced
266:aee39d8c0b83 | 267:4ed1446ad604 |
---|---|
40 #include "widgets/NotifyingPushButton.h" | 40 #include "widgets/NotifyingPushButton.h" |
41 | 41 |
42 using std::cerr; | 42 using std::cerr; |
43 using std::endl; | 43 using std::endl; |
44 | 44 |
45 QCursor Pane::m_measureCursor1; | 45 QCursor *Pane::m_measureCursor1 = 0; |
46 QCursor Pane::m_measureCursor2; | 46 QCursor *Pane::m_measureCursor2 = 0; |
47 bool Pane::m_measureCursorsCreated = false; | |
48 | 47 |
49 Pane::Pane(QWidget *w) : | 48 Pane::Pane(QWidget *w) : |
50 View(w, true), | 49 View(w, true), |
51 m_identifyFeatures(false), | 50 m_identifyFeatures(false), |
52 m_clickedInRange(false), | 51 m_clickedInRange(false), |
53 m_shiftPressed(false), | 52 m_shiftPressed(false), |
54 m_ctrlPressed(false), | 53 m_ctrlPressed(false), |
55 m_haveDraggingRect(false), | |
56 m_navigating(false), | 54 m_navigating(false), |
57 m_resizing(false), | 55 m_resizing(false), |
58 m_centreLineVisible(true), | 56 m_centreLineVisible(true), |
59 m_scaleWidth(0), | 57 m_scaleWidth(0), |
60 m_headsUpDisplay(0), | 58 m_headsUpDisplay(0), |
454 m_mousePos.y() - m_clickPos.y()); | 452 m_mousePos.y() - m_clickPos.y()); |
455 | 453 |
456 } | 454 } |
457 | 455 |
458 if (toolMode == ViewManager::MeasureMode && topLayer) { | 456 if (toolMode == ViewManager::MeasureMode && topLayer) { |
459 drawMeasurementRects(topLayer, paint); | 457 topLayer->paintMeasurementRects(this, paint); |
460 } | 458 } |
461 | 459 |
462 if (selectionIsBeingEdited()) { | 460 if (selectionIsBeingEdited()) { |
463 drawEditingSelection(paint); | 461 drawEditingSelection(paint); |
464 } | 462 } |
744 } | 742 } |
745 } | 743 } |
746 } | 744 } |
747 | 745 |
748 void | 746 void |
749 Pane::drawMeasurementRects(Layer *topLayer, QPainter &paint) | |
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 | |
778 int fontHeight = paint.fontMetrics().height(); | |
779 int fontAscent = paint.fontMetrics().ascent(); | |
780 | |
781 float v0, v1; | |
782 QString u0, u1; | |
783 bool b0 = false, b1 = false; | |
784 | |
785 QString axs, ays, bxs, bys, dxs, dys; | |
786 | |
787 int axx, axy, bxx, bxy, dxx, dxy; | |
788 int aw = 0, bw = 0, dw = 0; | |
789 | |
790 int labelCount = 0; | |
791 | |
792 if ((b0 = topLayer->getXScaleValue(this, r.start.x(), v0, u0))) { | |
793 axs = QString("%1 %2").arg(v0).arg(u0); | |
794 aw = paint.fontMetrics().width(axs); | |
795 ++labelCount; | |
796 } | |
797 | |
798 if (r.start != r.end) { | |
799 if ((b1 = topLayer->getXScaleValue(this, r.end.x(), v1, u1))) { | |
800 bxs = QString("%1 %2").arg(v1).arg(u1); | |
801 bw = paint.fontMetrics().width(bxs); | |
802 } | |
803 } | |
804 | |
805 if (b0 && b1 && u0 == u1) { | |
806 dxs = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); | |
807 dw = paint.fontMetrics().width(dxs); | |
808 } | |
809 | |
810 b0 = false; | |
811 b1 = false; | |
812 | |
813 if ((b0 = topLayer->getYScaleValue(this, r.start.y(), v0, u0))) { | |
814 ays = QString("%1 %2").arg(v0).arg(u0); | |
815 aw = std::max(aw, paint.fontMetrics().width(ays)); | |
816 ++labelCount; | |
817 } | |
818 | |
819 if (r.start != r.end) { | |
820 if ((b1 = topLayer->getYScaleValue(this, r.end.y(), v1, u1))) { | |
821 bys = QString("%1 %2").arg(v1).arg(u1); | |
822 bw = std::max(bw, paint.fontMetrics().width(bys)); | |
823 } | |
824 } | |
825 | |
826 if (b0 && b1 && u0 == u1) { | |
827 dys = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); | |
828 dw = std::max(dw, paint.fontMetrics().width(dys)); | |
829 } | |
830 | |
831 int mw = abs(r.end.x() - r.start.x()); | |
832 int mh = abs(r.end.y() - r.start.y()); | |
833 | |
834 bool edgeLabelsInside = false; | |
835 bool sizeLabelsInside = false; | |
836 | |
837 if (mw < std::max(aw, std::max(bw, dw)) + 4) { | |
838 // defaults stand | |
839 } else if (mw < aw + bw + 4) { | |
840 if (mh > fontHeight * labelCount * 3 + 4) { | |
841 edgeLabelsInside = true; | |
842 sizeLabelsInside = true; | |
843 } else if (mh > fontHeight * labelCount * 2 + 4) { | |
844 edgeLabelsInside = true; | |
845 } | |
846 } else if (mw < aw + bw + dw + 4) { | |
847 if (mh > fontHeight * labelCount * 3 + 4) { | |
848 edgeLabelsInside = true; | |
849 sizeLabelsInside = true; | |
850 } else if (mh > fontHeight * labelCount + 4) { | |
851 edgeLabelsInside = true; | |
852 } | |
853 } else { | |
854 if (mh > fontHeight * labelCount + 4) { | |
855 edgeLabelsInside = true; | |
856 sizeLabelsInside = true; | |
857 } | |
858 } | |
859 | |
860 if (edgeLabelsInside) { | |
861 | |
862 axx = r.start.x() + 2; | |
863 axy = r.start.y() + fontAscent + 2; | |
864 | |
865 bxx = r.end.x() - bw - 2; | |
866 bxy = r.end.y() - (labelCount-1) * fontHeight - 2; | |
867 | |
868 } else { | |
869 | |
870 axx = r.start.x() - aw - 2; | |
871 axy = r.start.y() + fontAscent; | |
872 | |
873 bxx = r.end.x() + 2; | |
874 bxy = r.end.y() - (labelCount-1) * fontHeight; | |
875 } | |
876 | |
877 dxx = (r.end.x() - r.start.x()) | |
878 / 2 + r.start.x() - dw/2; | |
879 | |
880 if (sizeLabelsInside) { | |
881 | |
882 dxy = (r.end.y() - r.start.y()) | |
883 / 2 + r.start.y() - (labelCount * fontHeight)/2 + fontAscent; | |
884 | |
885 } else { | |
886 | |
887 dxy = std::max(r.end.y(), r.start.y()) + fontAscent + 2; | |
888 } | |
889 | |
890 if (axs != "") { | |
891 drawVisibleText(paint, axx, axy, axs, OutlinedText); | |
892 axy += fontHeight; | |
893 } | |
894 | |
895 if (ays != "") { | |
896 drawVisibleText(paint, axx, axy, ays, OutlinedText); | |
897 axy += fontHeight; | |
898 } | |
899 | |
900 if (bxs != "") { | |
901 drawVisibleText(paint, bxx, bxy, bxs, OutlinedText); | |
902 bxy += fontHeight; | |
903 } | |
904 | |
905 if (bys != "") { | |
906 drawVisibleText(paint, bxx, bxy, bys, OutlinedText); | |
907 bxy += fontHeight; | |
908 } | |
909 | |
910 if (dxs != "") { | |
911 drawVisibleText(paint, dxx, dxy, dxs, OutlinedText); | |
912 dxy += fontHeight; | |
913 } | |
914 | |
915 if (dys != "") { | |
916 drawVisibleText(paint, dxx, dxy, dys, OutlinedText); | |
917 dxy += fontHeight; | |
918 } | |
919 | |
920 if (r.start != r.end) { | |
921 | |
922 paint.save(); | |
923 | |
924 paint.setPen(Qt::green); | |
925 | |
926 paint.drawRect(r.start.x(), r.start.y(), | |
927 r.end.x() - r.start.x(), | |
928 r.end.y() - r.start.y()); | |
929 | |
930 paint.restore(); | |
931 } | |
932 } | |
933 | |
934 void | |
935 Pane::drawEditingSelection(QPainter &paint) | 747 Pane::drawEditingSelection(QPainter &paint) |
936 { | 748 { |
937 int offset = m_mousePos.x() - m_clickPos.x(); | 749 int offset = m_mousePos.x() - m_clickPos.x(); |
938 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; | 750 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; |
939 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; | 751 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; |
1275 } | 1087 } |
1276 } | 1088 } |
1277 | 1089 |
1278 } else if (mode == ViewManager::MeasureMode) { | 1090 } else if (mode == ViewManager::MeasureMode) { |
1279 | 1091 |
1280 //!!! command | 1092 Layer *layer = getSelectedLayer(); |
1281 | 1093 if (layer) layer->measureStart(this, e); |
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 /*!!! | |
1295 m_measureStart = m_clickPos; | |
1296 m_measureEnd = m_measureStart; | |
1297 | |
1298 m_measureStartFrame = getFrameForX(m_clickPos.x()); | |
1299 m_measureEndFrame = m_measureStartFrame; | |
1300 | |
1301 m_haveMeasureRect = true; | |
1302 */ | |
1303 update(); | 1094 update(); |
1304 } | 1095 } |
1305 | 1096 |
1306 emit paneInteractedWith(); | 1097 emit paneInteractedWith(); |
1307 } | 1098 } |
1382 } | 1173 } |
1383 } | 1174 } |
1384 | 1175 |
1385 } else if (mode == ViewManager::MeasureMode) { | 1176 } else if (mode == ViewManager::MeasureMode) { |
1386 | 1177 |
1387 if (m_haveDraggingRect) { | 1178 Layer *layer = getSelectedLayer(); |
1388 | 1179 if (layer) layer->measureEnd(this, e); |
1389 LayerList::iterator vi = m_layers.end(); | 1180 if (m_measureCursor1) setCursor(*m_measureCursor1); |
1390 if (vi != m_layers.begin()) { | 1181 update(); |
1391 Layer *topLayer = *(--vi); | |
1392 m_measureRects[topLayer].push_back(m_draggingRect); | |
1393 } | |
1394 | |
1395 m_haveDraggingRect = false; | |
1396 } | |
1397 | |
1398 setCursor(m_measureCursor1); | |
1399 } | 1182 } |
1400 | 1183 |
1401 m_clickedInRange = false; | 1184 m_clickedInRange = false; |
1402 | 1185 |
1403 emit paneInteractedWith(); | 1186 emit paneInteractedWith(); |
1481 } | 1264 } |
1482 } | 1265 } |
1483 | 1266 |
1484 } else if (mode == ViewManager::MeasureMode) { | 1267 } else if (mode == ViewManager::MeasureMode) { |
1485 | 1268 |
1486 setCursor(m_measureCursor2); | 1269 if (m_measureCursor2) setCursor(*m_measureCursor2); |
1487 | 1270 |
1488 if (m_haveDraggingRect) { | 1271 Layer *layer = getSelectedLayer(); |
1489 m_draggingRect.end = e->pos(); | 1272 if (layer) layer->measureDrag(this, e); |
1490 if (hasTopLayerTimeXAxis()) { | 1273 |
1491 m_draggingRect.endFrame = getFrameForX(m_draggingRect.end.x()); | 1274 if (hasTopLayerTimeXAxis()) { |
1492 edgeScrollMaybe(e->x()); | 1275 edgeScrollMaybe(e->x()); |
1493 } | 1276 } |
1494 update(); | 1277 |
1495 } | 1278 update(); |
1496 } | 1279 } |
1497 } | 1280 } |
1498 | 1281 |
1499 void | 1282 void |
1500 Pane::zoomToRegion(int x0, int y0, int x1, int y1) | 1283 Pane::zoomToRegion(int x0, int y0, int x1, int y1) |
2086 Pane::toolModeChanged() | 1869 Pane::toolModeChanged() |
2087 { | 1870 { |
2088 ViewManager::ToolMode mode = m_manager->getToolMode(); | 1871 ViewManager::ToolMode mode = m_manager->getToolMode(); |
2089 // std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl; | 1872 // std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl; |
2090 | 1873 |
2091 if (mode == ViewManager::MeasureMode && !m_measureCursorsCreated) { | 1874 if (mode == ViewManager::MeasureMode && !m_measureCursor1) { |
2092 m_measureCursor1 = QCursor(QBitmap(":/icons/measure1cursor.xbm"), | 1875 m_measureCursor1 = new QCursor(QBitmap(":/icons/measure1cursor.xbm"), |
2093 QBitmap(":/icons/measure1mask.xbm"), | 1876 QBitmap(":/icons/measure1mask.xbm"), |
2094 15, 14); | 1877 15, 14); |
2095 m_measureCursor2 = QCursor(QBitmap(":/icons/measure2cursor.xbm"), | 1878 m_measureCursor2 = new QCursor(QBitmap(":/icons/measure2cursor.xbm"), |
2096 QBitmap(":/icons/measure2mask.xbm"), | 1879 QBitmap(":/icons/measure2mask.xbm"), |
2097 16, 17); | 1880 16, 17); |
2098 m_measureCursorsCreated = true; | |
2099 } | 1881 } |
2100 | 1882 |
2101 switch (mode) { | 1883 switch (mode) { |
2102 | 1884 |
2103 case ViewManager::NavigateMode: | 1885 case ViewManager::NavigateMode: |
2115 case ViewManager::DrawMode: | 1897 case ViewManager::DrawMode: |
2116 setCursor(Qt::CrossCursor); | 1898 setCursor(Qt::CrossCursor); |
2117 break; | 1899 break; |
2118 | 1900 |
2119 case ViewManager::MeasureMode: | 1901 case ViewManager::MeasureMode: |
2120 setCursor(m_measureCursor1); | 1902 if (m_measureCursor1) setCursor(*m_measureCursor1); |
2121 break; | 1903 break; |
2122 | 1904 |
2123 /* | 1905 /* |
2124 case ViewManager::TextMode: | 1906 case ViewManager::TextMode: |
2125 setCursor(Qt::IBeamCursor); | 1907 setCursor(Qt::IBeamCursor); |