# HG changeset patch # User Chris Cannam # Date 1181840596 0 # Node ID dae479593572a19cd79168f5ba1e968ba25bbf86 # Parent 11021509c4eb88ae84aab17395d426964f32bf39 * more measurement tool stuff diff -r 11021509c4eb -r dae479593572 layer/WaveformLayer.cpp --- a/layer/WaveformLayer.cpp Thu Jun 14 16:28:27 2007 +0000 +++ b/layer/WaveformLayer.cpp Thu Jun 14 17:03:16 2007 +0000 @@ -1063,7 +1063,7 @@ int my = m + (((channel - minChannel) * h) / channels); - int vy = y - my; + int vy = my - y; float value = 0; switch (scale) { diff -r 11021509c4eb -r dae479593572 view/Pane.cpp --- a/view/Pane.cpp Thu Jun 14 16:28:27 2007 +0000 +++ b/view/Pane.cpp Thu Jun 14 17:03:16 2007 +0000 @@ -42,6 +42,10 @@ using std::cerr; using std::endl; +QCursor Pane::m_measureCursor1; +QCursor Pane::m_measureCursor2; +bool Pane::m_measureCursorsCreated = false; + Pane::Pane(QWidget *w) : View(w, true), m_identifyFeatures(false), @@ -297,6 +301,10 @@ QPoint discard; bool b0, b1; + if (m_manager && m_manager->getToolMode() == ViewManager::MeasureMode) { + return false; + } + if (layer == getSelectedLayer() && !shouldIlluminateLocalSelection(discard, b0, b1)) { @@ -432,23 +440,27 @@ drawLayerNames(r, paint); } - if (m_clickedInRange && m_manager) { + if (m_shiftPressed && m_clickedInRange && + toolMode == ViewManager::NavigateMode) { //!!! be nice if this looked a bit more in keeping with the //selection block + + paint.setPen(Qt::blue); + //!!! shouldn't use clickPos -- needs to use a clicked frame + paint.drawRect(m_clickPos.x(), m_clickPos.y(), + m_mousePos.x() - m_clickPos.x(), + m_mousePos.y() - m_clickPos.y()); - if (m_shiftPressed && toolMode == ViewManager::NavigateMode) { + } - paint.setPen(Qt::blue); - //!!! shouldn't use clickPos -- needs to use a clicked frame - paint.drawRect(m_clickPos.x(), m_clickPos.y(), - m_mousePos.x() - m_clickPos.x(), - m_mousePos.y() - m_clickPos.y()); - - } else if (toolMode == ViewManager::MeasureMode && topLayer) { - + if (toolMode == ViewManager::MeasureMode && topLayer && + m_haveMeasureRect) { + if (m_measureCentreFrame != m_centreFrame) { + m_haveMeasureRect = false; + } else { drawMeasurementRect(topLayer, paint); - } + } } if (selectionIsBeingEdited()) { @@ -745,36 +757,43 @@ float v0, v1; QString u0, u1; - bool b0, b1; + bool b0 = false, b1 = false; QString axs, ays, bxs, bys, dxs, dys; - if ((b0 = topLayer->getXScaleValue(this, m_clickPos.x(), v0, u0))) { + if ((b0 = topLayer->getXScaleValue(this, m_measureStart.x(), v0, u0))) { axs = QString("%1 %2").arg(v0).arg(u0); } - if ((b1 = topLayer->getXScaleValue(this, m_mousePos.x(), v1, u1))) { - bxs = QString("%1 %2").arg(v1).arg(u1); + if (m_measureStart != m_measureEnd) { + if ((b1 = topLayer->getXScaleValue(this, m_measureEnd.x(), v1, u1))) { + bxs = QString("%1 %2").arg(v1).arg(u1); + } } if (b0 && b1 && u0 == u1) { dxs = QString("(%1 %2)").arg(v1 - v0).arg(u1); } - if ((b0 = topLayer->getYScaleValue(this, m_clickPos.y(), v0, u0))) { + b0 = false; + b1 = false; + + if ((b0 = topLayer->getYScaleValue(this, m_measureStart.y(), v0, u0))) { ays = QString("%1 %2").arg(v0).arg(u0); } - - if ((b1 = topLayer->getYScaleValue(this, m_mousePos.y(), v1, u1))) { - bys = QString("%1 %2").arg(v1).arg(u1); + + if (m_measureStart != m_measureEnd) { + if ((b1 = topLayer->getYScaleValue(this, m_measureEnd.y(), v1, u1))) { + bys = QString("%1 %2").arg(v1).arg(u1); + } } if (b0 && b1 && u0 == u1) { dys = QString("(%1 %2)").arg(v1 - v0).arg(u1); } - int x = m_clickPos.x() + 2; - int y = m_clickPos.y() + fontAscent + 2; + int x = m_measureStart.x() + 2; + int y = m_measureStart.y() + fontAscent + 2; if (axs != "") { drawVisibleText(paint, x, y, axs, OutlinedText); @@ -786,8 +805,8 @@ y += fontHeight; } - x = m_mousePos.x() - paint.fontMetrics().width(bxs) - 2; - y = m_mousePos.y() - 2; + x = m_measureEnd.x() - paint.fontMetrics().width(bxs) - 2; + y = m_measureEnd.y() - 2; if (bys != "" && bxs != "") y -= fontHeight; @@ -796,22 +815,25 @@ y += fontHeight; } - x = m_mousePos.x() - paint.fontMetrics().width(bys) - 2; + x = m_measureEnd.x() - paint.fontMetrics().width(bys) - 2; if (bys != "") { drawVisibleText(paint, x, y, bys, OutlinedText); y += fontHeight; } - paint.save(); - - paint.setPen(Qt::green); + if (m_measureStart != m_measureEnd) { - paint.drawRect(m_clickPos.x(), m_clickPos.y(), - m_mousePos.x() - m_clickPos.x(), - m_mousePos.y() - m_clickPos.y()); - - paint.restore(); + paint.save(); + + paint.setPen(Qt::green); + + paint.drawRect(m_measureStart.x(), m_measureStart.y(), + m_measureEnd.x() - m_measureStart.x(), + m_measureEnd.y() - m_measureStart.y()); + + paint.restore(); + } } void @@ -1069,6 +1091,7 @@ } m_clickPos = e->pos(); + m_mousePos = m_clickPos; m_clickedInRange = true; m_editingSelection = Selection(); m_editingSelectionEdge = 0; @@ -1156,6 +1179,14 @@ layer->editStart(this, e); } } + + } else if (mode == ViewManager::MeasureMode) { + + m_measureStart = m_clickPos; + m_measureEnd = m_clickPos; + m_haveMeasureRect = true; + m_measureCentreFrame = m_centreFrame; + update(); } emit paneInteractedWith(); @@ -1236,6 +1267,10 @@ update(); } } + + } else if (mode == ViewManager::MeasureMode) { + + setCursor(m_measureCursor1); } m_clickedInRange = false; @@ -1323,8 +1358,8 @@ } else if (mode == ViewManager::MeasureMode) { - m_mousePos = e->pos(); - edgeScrollMaybe(e->x()); + setCursor(m_measureCursor2); + m_measureEnd = e->pos(); update(); } } @@ -1921,14 +1956,14 @@ ViewManager::ToolMode mode = m_manager->getToolMode(); // std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl; - static QCursor measureCursor; - static bool measureCursorCreated = false; - - if (!measureCursorCreated) { - measureCursor = QCursor(QBitmap(":/icons/measure1cursor.xbm"), - QBitmap(":/icons/measure1mask.xbm"), - 15, 14); - measureCursorCreated = true; + if (!m_measureCursorsCreated) { + m_measureCursor1 = QCursor(QBitmap(":/icons/measure1cursor.xbm"), + QBitmap(":/icons/measure1mask.xbm"), + 15, 14); + m_measureCursor2 = QCursor(QBitmap(":/icons/measure2cursor.xbm"), + QBitmap(":/icons/measure2mask.xbm"), + 16, 17); + m_measureCursorsCreated = true; } switch (mode) { @@ -1950,7 +1985,7 @@ break; case ViewManager::MeasureMode: - setCursor(measureCursor); + setCursor(m_measureCursor1); break; /* diff -r 11021509c4eb -r dae479593572 view/Pane.h --- a/view/Pane.h Thu Jun 14 16:28:27 2007 +0000 +++ b/view/Pane.h Thu Jun 14 17:03:16 2007 +0000 @@ -124,9 +124,13 @@ QPoint m_identifyPoint; QPoint m_clickPos; QPoint m_mousePos; + QPoint m_measureStart; + QPoint m_measureEnd; bool m_clickedInRange; bool m_shiftPressed; bool m_ctrlPressed; + bool m_haveMeasureRect; + size_t m_measureCentreFrame; bool m_navigating; bool m_resizing; size_t m_dragCentreFrame; @@ -150,6 +154,10 @@ Thumbwheel *m_hthumb; Thumbwheel *m_vthumb; NotifyingPushButton *m_reset; + + static QCursor m_measureCursor1; + static QCursor m_measureCursor2; + static bool m_measureCursorsCreated; }; #endif