From 8097d20c2addba06a748f838ac6b7d7cdb29df14 Mon Sep 17 00:00:00 2001 From: James Hogan Date: Sat, 22 Nov 2008 11:39:57 +0000 Subject: [PATCH] Inverted mouse control and allowed range selecting without losing previous selection until unpress --- tcViewportWidget.cpp | 34 +++++++++++++++++++++++----------- tcViewportWidget.h | 3 +++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tcViewportWidget.cpp b/tcViewportWidget.cpp index 98d0ddd..25ad832 100644 --- a/tcViewportWidget.cpp +++ b/tcViewportWidget.cpp @@ -314,21 +314,33 @@ void tcViewportWidget::paintGL() glLineWidth(1); // Draw a fence around the selected region - if (m_mouseSlicing || m_sliced) + for (int i = 0; i < 2; ++i) { - tcGeo ending = (m_mouseSlicing ? m_mouseCoord : m_slice[1]); + tcGeo coord; + tcGeo ending; float colour[4] = {1.0f, 0.5f, 1.0f, 1.0f}; - if (!m_mouseSlicing) + if (0 == i && m_mouseSlicing && m_mouseIntersecting) { + coord = m_mouseCoord; + ending = m_mouseStartCoord; + } + else if (1 == i && m_sliced) + { + coord = m_slice[0]; + ending = m_slice[1]; colour[0] = 0.0f; colour[3] = 0.5f; } - tcGeo delta = ending - m_slice[0]; + else + { + continue; + } + + tcGeo delta = ending - coord; int nlon = 2 + fabs(delta.lon())*10*meanRadius / m_observer->range(); int nlat = 2 + fabs(delta.lat())*10*meanRadius / m_observer->range(); double dlon = delta.lon() / nlon; double dlat = delta.lat() / nlat; - tcGeo coord = m_slice[0]; glDisable(GL_CULL_FACE); glBegin(GL_TRIANGLE_STRIP); @@ -416,12 +428,11 @@ void tcViewportWidget::mousePressEvent(QMouseEvent* event) else if (event->button() == Qt::RightButton) { bool ok; - m_slice[0] = geoAt(event->posF().x(), event->posF().y(), &ok); + m_mouseStartCoord = geoAt(event->posF().x(), event->posF().y(), &ok); m_mouseIntersecting = false; if (ok) { m_mouseSlicing = true; - m_sliced = false; } } } @@ -435,9 +446,10 @@ void tcViewportWidget::mouseReleaseEvent(QMouseEvent* event) else if (m_mouseSlicing) { m_mouseSlicing = false; + m_sliced = m_mouseIntersecting; if (m_mouseIntersecting) { - m_sliced = true; + m_slice[0] = m_mouseStartCoord; m_slice[1] = m_mouseCoord; } updateGL(); @@ -452,16 +464,16 @@ void tcViewportWidget::wheelEvent(QWheelEvent* event) { if (event->modifiers().testFlag(Qt::ControlModifier)) { - m_observer->adjustElevation(-delta); + m_observer->adjustElevation(delta); } else { - m_observer->adjustRange(delta); + m_observer->adjustRange(-delta); } } else { - m_observer->adjustAzimuth(delta); + m_observer->adjustAzimuth(-delta); } m_observer->setFocusAltitude(m_globe->radiusAt(m_observer->focus())); diff --git a/tcViewportWidget.h b/tcViewportWidget.h index 223877b..f766a7e 100644 --- a/tcViewportWidget.h +++ b/tcViewportWidget.h @@ -164,6 +164,9 @@ class tcViewportWidget : public QGLWidget /// Slicing with the mouse? bool m_mouseSlicing; + /// Start of mouse slicing action. + tcGeo m_mouseStartCoord; + /// Sliced? bool m_sliced; -- 2.11.4.GIT