Mercurial > hg > svgui
comparison view/Pane.cpp @ 262:dae479593572
* more measurement tool stuff
author | Chris Cannam |
---|---|
date | Thu, 14 Jun 2007 17:03:16 +0000 |
parents | 11021509c4eb |
children | 16fffa24da02 |
comparison
equal
deleted
inserted
replaced
261:11021509c4eb | 262:dae479593572 |
---|---|
39 #include "widgets/RangeInputDialog.h" | 39 #include "widgets/RangeInputDialog.h" |
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 | |
45 QCursor Pane::m_measureCursor1; | |
46 QCursor Pane::m_measureCursor2; | |
47 bool Pane::m_measureCursorsCreated = false; | |
44 | 48 |
45 Pane::Pane(QWidget *w) : | 49 Pane::Pane(QWidget *w) : |
46 View(w, true), | 50 View(w, true), |
47 m_identifyFeatures(false), | 51 m_identifyFeatures(false), |
48 m_clickedInRange(false), | 52 m_clickedInRange(false), |
295 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const | 299 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const |
296 { | 300 { |
297 QPoint discard; | 301 QPoint discard; |
298 bool b0, b1; | 302 bool b0, b1; |
299 | 303 |
304 if (m_manager && m_manager->getToolMode() == ViewManager::MeasureMode) { | |
305 return false; | |
306 } | |
307 | |
300 if (layer == getSelectedLayer() && | 308 if (layer == getSelectedLayer() && |
301 !shouldIlluminateLocalSelection(discard, b0, b1)) { | 309 !shouldIlluminateLocalSelection(discard, b0, b1)) { |
302 | 310 |
303 pos = m_identifyPoint; | 311 pos = m_identifyPoint; |
304 return m_identifyFeatures; | 312 return m_identifyFeatures; |
430 if (m_manager && | 438 if (m_manager && |
431 m_manager->shouldShowLayerNames()) { | 439 m_manager->shouldShowLayerNames()) { |
432 drawLayerNames(r, paint); | 440 drawLayerNames(r, paint); |
433 } | 441 } |
434 | 442 |
435 if (m_clickedInRange && m_manager) { | 443 if (m_shiftPressed && m_clickedInRange && |
444 toolMode == ViewManager::NavigateMode) { | |
436 | 445 |
437 //!!! be nice if this looked a bit more in keeping with the | 446 //!!! be nice if this looked a bit more in keeping with the |
438 //selection block | 447 //selection block |
439 | 448 |
440 if (m_shiftPressed && toolMode == ViewManager::NavigateMode) { | 449 paint.setPen(Qt::blue); |
441 | 450 //!!! shouldn't use clickPos -- needs to use a clicked frame |
442 paint.setPen(Qt::blue); | 451 paint.drawRect(m_clickPos.x(), m_clickPos.y(), |
443 //!!! shouldn't use clickPos -- needs to use a clicked frame | 452 m_mousePos.x() - m_clickPos.x(), |
444 paint.drawRect(m_clickPos.x(), m_clickPos.y(), | 453 m_mousePos.y() - m_clickPos.y()); |
445 m_mousePos.x() - m_clickPos.x(), | 454 |
446 m_mousePos.y() - m_clickPos.y()); | 455 } |
447 | 456 |
448 } else if (toolMode == ViewManager::MeasureMode && topLayer) { | 457 if (toolMode == ViewManager::MeasureMode && topLayer && |
449 | 458 m_haveMeasureRect) { |
459 if (m_measureCentreFrame != m_centreFrame) { | |
460 m_haveMeasureRect = false; | |
461 } else { | |
450 drawMeasurementRect(topLayer, paint); | 462 drawMeasurementRect(topLayer, paint); |
451 } | 463 } |
452 } | 464 } |
453 | 465 |
454 if (selectionIsBeingEdited()) { | 466 if (selectionIsBeingEdited()) { |
455 drawEditingSelection(paint); | 467 drawEditingSelection(paint); |
456 } | 468 } |
743 int fontHeight = paint.fontMetrics().height(); | 755 int fontHeight = paint.fontMetrics().height(); |
744 int fontAscent = paint.fontMetrics().ascent(); | 756 int fontAscent = paint.fontMetrics().ascent(); |
745 | 757 |
746 float v0, v1; | 758 float v0, v1; |
747 QString u0, u1; | 759 QString u0, u1; |
748 bool b0, b1; | 760 bool b0 = false, b1 = false; |
749 | 761 |
750 QString axs, ays, bxs, bys, dxs, dys; | 762 QString axs, ays, bxs, bys, dxs, dys; |
751 | 763 |
752 if ((b0 = topLayer->getXScaleValue(this, m_clickPos.x(), v0, u0))) { | 764 if ((b0 = topLayer->getXScaleValue(this, m_measureStart.x(), v0, u0))) { |
753 axs = QString("%1 %2").arg(v0).arg(u0); | 765 axs = QString("%1 %2").arg(v0).arg(u0); |
754 } | 766 } |
755 | 767 |
756 if ((b1 = topLayer->getXScaleValue(this, m_mousePos.x(), v1, u1))) { | 768 if (m_measureStart != m_measureEnd) { |
757 bxs = QString("%1 %2").arg(v1).arg(u1); | 769 if ((b1 = topLayer->getXScaleValue(this, m_measureEnd.x(), v1, u1))) { |
770 bxs = QString("%1 %2").arg(v1).arg(u1); | |
771 } | |
758 } | 772 } |
759 | 773 |
760 if (b0 && b1 && u0 == u1) { | 774 if (b0 && b1 && u0 == u1) { |
761 dxs = QString("(%1 %2)").arg(v1 - v0).arg(u1); | 775 dxs = QString("(%1 %2)").arg(v1 - v0).arg(u1); |
762 } | 776 } |
763 | 777 |
764 if ((b0 = topLayer->getYScaleValue(this, m_clickPos.y(), v0, u0))) { | 778 b0 = false; |
779 b1 = false; | |
780 | |
781 if ((b0 = topLayer->getYScaleValue(this, m_measureStart.y(), v0, u0))) { | |
765 ays = QString("%1 %2").arg(v0).arg(u0); | 782 ays = QString("%1 %2").arg(v0).arg(u0); |
766 } | 783 } |
767 | 784 |
768 if ((b1 = topLayer->getYScaleValue(this, m_mousePos.y(), v1, u1))) { | 785 if (m_measureStart != m_measureEnd) { |
769 bys = QString("%1 %2").arg(v1).arg(u1); | 786 if ((b1 = topLayer->getYScaleValue(this, m_measureEnd.y(), v1, u1))) { |
787 bys = QString("%1 %2").arg(v1).arg(u1); | |
788 } | |
770 } | 789 } |
771 | 790 |
772 if (b0 && b1 && u0 == u1) { | 791 if (b0 && b1 && u0 == u1) { |
773 dys = QString("(%1 %2)").arg(v1 - v0).arg(u1); | 792 dys = QString("(%1 %2)").arg(v1 - v0).arg(u1); |
774 } | 793 } |
775 | 794 |
776 int x = m_clickPos.x() + 2; | 795 int x = m_measureStart.x() + 2; |
777 int y = m_clickPos.y() + fontAscent + 2; | 796 int y = m_measureStart.y() + fontAscent + 2; |
778 | 797 |
779 if (axs != "") { | 798 if (axs != "") { |
780 drawVisibleText(paint, x, y, axs, OutlinedText); | 799 drawVisibleText(paint, x, y, axs, OutlinedText); |
781 y += fontHeight; | 800 y += fontHeight; |
782 } | 801 } |
784 if (ays != "") { | 803 if (ays != "") { |
785 drawVisibleText(paint, x, y, ays, OutlinedText); | 804 drawVisibleText(paint, x, y, ays, OutlinedText); |
786 y += fontHeight; | 805 y += fontHeight; |
787 } | 806 } |
788 | 807 |
789 x = m_mousePos.x() - paint.fontMetrics().width(bxs) - 2; | 808 x = m_measureEnd.x() - paint.fontMetrics().width(bxs) - 2; |
790 y = m_mousePos.y() - 2; | 809 y = m_measureEnd.y() - 2; |
791 | 810 |
792 if (bys != "" && bxs != "") y -= fontHeight; | 811 if (bys != "" && bxs != "") y -= fontHeight; |
793 | 812 |
794 if (bxs != "") { | 813 if (bxs != "") { |
795 drawVisibleText(paint, x, y, bxs, OutlinedText); | 814 drawVisibleText(paint, x, y, bxs, OutlinedText); |
796 y += fontHeight; | 815 y += fontHeight; |
797 } | 816 } |
798 | 817 |
799 x = m_mousePos.x() - paint.fontMetrics().width(bys) - 2; | 818 x = m_measureEnd.x() - paint.fontMetrics().width(bys) - 2; |
800 | 819 |
801 if (bys != "") { | 820 if (bys != "") { |
802 drawVisibleText(paint, x, y, bys, OutlinedText); | 821 drawVisibleText(paint, x, y, bys, OutlinedText); |
803 y += fontHeight; | 822 y += fontHeight; |
804 } | 823 } |
805 | 824 |
806 paint.save(); | 825 if (m_measureStart != m_measureEnd) { |
807 | 826 |
808 paint.setPen(Qt::green); | 827 paint.save(); |
809 | 828 |
810 paint.drawRect(m_clickPos.x(), m_clickPos.y(), | 829 paint.setPen(Qt::green); |
811 m_mousePos.x() - m_clickPos.x(), | 830 |
812 m_mousePos.y() - m_clickPos.y()); | 831 paint.drawRect(m_measureStart.x(), m_measureStart.y(), |
813 | 832 m_measureEnd.x() - m_measureStart.x(), |
814 paint.restore(); | 833 m_measureEnd.y() - m_measureStart.y()); |
834 | |
835 paint.restore(); | |
836 } | |
815 } | 837 } |
816 | 838 |
817 void | 839 void |
818 Pane::drawEditingSelection(QPainter &paint) | 840 Pane::drawEditingSelection(QPainter &paint) |
819 { | 841 { |
1067 emit rightButtonMenuRequested(mapToGlobal(e->pos())); | 1089 emit rightButtonMenuRequested(mapToGlobal(e->pos())); |
1068 return; | 1090 return; |
1069 } | 1091 } |
1070 | 1092 |
1071 m_clickPos = e->pos(); | 1093 m_clickPos = e->pos(); |
1094 m_mousePos = m_clickPos; | |
1072 m_clickedInRange = true; | 1095 m_clickedInRange = true; |
1073 m_editingSelection = Selection(); | 1096 m_editingSelection = Selection(); |
1074 m_editingSelectionEdge = 0; | 1097 m_editingSelectionEdge = 0; |
1075 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier); | 1098 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier); |
1076 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); | 1099 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); |
1154 Layer *layer = getSelectedLayer(); | 1177 Layer *layer = getSelectedLayer(); |
1155 if (layer && layer->isLayerEditable()) { | 1178 if (layer && layer->isLayerEditable()) { |
1156 layer->editStart(this, e); | 1179 layer->editStart(this, e); |
1157 } | 1180 } |
1158 } | 1181 } |
1182 | |
1183 } else if (mode == ViewManager::MeasureMode) { | |
1184 | |
1185 m_measureStart = m_clickPos; | |
1186 m_measureEnd = m_clickPos; | |
1187 m_haveMeasureRect = true; | |
1188 m_measureCentreFrame = m_centreFrame; | |
1189 update(); | |
1159 } | 1190 } |
1160 | 1191 |
1161 emit paneInteractedWith(); | 1192 emit paneInteractedWith(); |
1162 } | 1193 } |
1163 | 1194 |
1234 if (layer && layer->isLayerEditable()) { | 1265 if (layer && layer->isLayerEditable()) { |
1235 layer->editEnd(this, e); | 1266 layer->editEnd(this, e); |
1236 update(); | 1267 update(); |
1237 } | 1268 } |
1238 } | 1269 } |
1270 | |
1271 } else if (mode == ViewManager::MeasureMode) { | |
1272 | |
1273 setCursor(m_measureCursor1); | |
1239 } | 1274 } |
1240 | 1275 |
1241 m_clickedInRange = false; | 1276 m_clickedInRange = false; |
1242 | 1277 |
1243 emit paneInteractedWith(); | 1278 emit paneInteractedWith(); |
1321 } | 1356 } |
1322 } | 1357 } |
1323 | 1358 |
1324 } else if (mode == ViewManager::MeasureMode) { | 1359 } else if (mode == ViewManager::MeasureMode) { |
1325 | 1360 |
1326 m_mousePos = e->pos(); | 1361 setCursor(m_measureCursor2); |
1327 edgeScrollMaybe(e->x()); | 1362 m_measureEnd = e->pos(); |
1328 update(); | 1363 update(); |
1329 } | 1364 } |
1330 } | 1365 } |
1331 | 1366 |
1332 void | 1367 void |
1919 Pane::toolModeChanged() | 1954 Pane::toolModeChanged() |
1920 { | 1955 { |
1921 ViewManager::ToolMode mode = m_manager->getToolMode(); | 1956 ViewManager::ToolMode mode = m_manager->getToolMode(); |
1922 // std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl; | 1957 // std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl; |
1923 | 1958 |
1924 static QCursor measureCursor; | 1959 if (!m_measureCursorsCreated) { |
1925 static bool measureCursorCreated = false; | 1960 m_measureCursor1 = QCursor(QBitmap(":/icons/measure1cursor.xbm"), |
1926 | 1961 QBitmap(":/icons/measure1mask.xbm"), |
1927 if (!measureCursorCreated) { | 1962 15, 14); |
1928 measureCursor = QCursor(QBitmap(":/icons/measure1cursor.xbm"), | 1963 m_measureCursor2 = QCursor(QBitmap(":/icons/measure2cursor.xbm"), |
1929 QBitmap(":/icons/measure1mask.xbm"), | 1964 QBitmap(":/icons/measure2mask.xbm"), |
1930 15, 14); | 1965 16, 17); |
1931 measureCursorCreated = true; | 1966 m_measureCursorsCreated = true; |
1932 } | 1967 } |
1933 | 1968 |
1934 switch (mode) { | 1969 switch (mode) { |
1935 | 1970 |
1936 case ViewManager::NavigateMode: | 1971 case ViewManager::NavigateMode: |
1948 case ViewManager::DrawMode: | 1983 case ViewManager::DrawMode: |
1949 setCursor(Qt::CrossCursor); | 1984 setCursor(Qt::CrossCursor); |
1950 break; | 1985 break; |
1951 | 1986 |
1952 case ViewManager::MeasureMode: | 1987 case ViewManager::MeasureMode: |
1953 setCursor(measureCursor); | 1988 setCursor(m_measureCursor1); |
1954 break; | 1989 break; |
1955 | 1990 |
1956 /* | 1991 /* |
1957 case ViewManager::TextMode: | 1992 case ViewManager::TextMode: |
1958 setCursor(Qt::IBeamCursor); | 1993 setCursor(Qt::IBeamCursor); |