@@ -49,8 +49,6 @@ namespace
4949}
5050
5151ScatterplotWidget::ScatterplotWidget (mv::plugin::ViewPlugin* parentPlugin) :
52- QOpenGLWidget(),
53- _pointRenderer(),
5452 _densityRenderer(DensityRenderer::RenderMode::DENSITY),
5553 _isInitialized(false ),
5654 _renderMode(SCATTERPLOT),
@@ -59,21 +57,17 @@ ScatterplotWidget::ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin) :
5957 _widgetSizeInfo(),
6058 _dataRectangleAction(this , " Data rectangle" ),
6159 _navigationAction(this , " Navigation" ),
62- _colorMapImage(),
6360 _pixelSelectionTool(this ),
6461 _samplerPixelSelectionTool(this ),
6562 _pixelRatio(1.0 ),
66- _mousePositions(),
67- _isNavigating(false ),
6863 _weightDensity(false ),
6964 _parentPlugin(parentPlugin)
7065{
7166 setContextMenuPolicy (Qt::CustomContextMenu);
7267 setAcceptDrops (true );
7368 setMouseTracking (true );
74- setFocusPolicy (Qt::ClickFocus);
69+ // setFocusPolicy(Qt::ClickFocus);
7570 grabGesture (Qt::PinchGesture);
76- // setAttribute(Qt::WA_TranslucentBackground);
7771 installEventFilter (this );
7872
7973 _navigationAction.initialize (this );
@@ -146,159 +140,58 @@ ScatterplotWidget::ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin) :
146140
147141 update ();
148142 });
149- }
150143
151- bool ScatterplotWidget::event (QEvent* event)
152- {
153- if (!event)
154- return QOpenGLWidget::event (event);
144+ connect (&_navigationAction.getZoomDataExtentsAction (), &TriggerAction::triggered, this , [this ]() -> void {
145+ _pointRenderer.getNavigator ().resetView ();
146+ });
155147
156- auto setIsNavigating = [this ](bool isNavigating) -> void {
157- _isNavigating = isNavigating;
148+ connect (&_pointRenderer.getNavigator (), &Navigator2D::isNavigatingChanged, this , [this ](bool isNavigating) -> void {
158149 _pixelSelectionTool.setEnabled (!isNavigating);
159- if (isNavigating) {
150+
151+ if (isNavigating) {
160152 _samplerPixelSelectionTool.setEnabled (false );
161153 }
162- else if (_parentPlugin) { // reset to UI-setting
154+ else if (_parentPlugin) {
163155 _samplerPixelSelectionTool.setEnabled (_parentPlugin->getSamplerAction ().getEnabledAction ().isChecked ());
164156 }
157+ });
165158
166- };
167-
168- // Set navigation flag on Alt press/release
169- if (event->type () == QEvent::KeyRelease) {
170- if (const auto * keyEvent = static_cast <QKeyEvent*>(event)) {
171- if (keyEvent->key () == Qt::Key_Alt) {
172- setIsNavigating (false );
173- }
174- }
175-
176- }
177- else if (event->type () == QEvent::KeyPress) {
178- if (const auto * keyEvent = static_cast <QKeyEvent*>(event)) {
179- if (keyEvent->key () == Qt::Key_Alt) {
180- setIsNavigating (true );
181- }
182- }
159+ connect (&_pointRenderer, &Renderer2D::zoomRectangleChanged, this , [this ]() -> void { update (); });
183160
184- }
161+ // auto setIsNavigating = [this](bool isNavigating) -> void {
162+ // _isNavigating = isNavigating;
163+ // _pixelSelectionTool.setEnabled(!isNavigating);
164+ // if (isNavigating) {
165+ // _samplerPixelSelectionTool.setEnabled(false);
166+ // }
167+ // else if (_parentPlugin) { // reset to UI-setting
168+ // _samplerPixelSelectionTool.setEnabled(_parentPlugin->getSamplerAction().getEnabledAction().isChecked());
169+ // }
185170
186- // Interactions when Alt is pressed
187- if (isInitialized () && QGuiApplication::keyboardModifiers () == Qt::AltModifier) {
171+ // };
188172
189- switch (event->type ())
190- {
191- case QEvent::Wheel:
192- {
193- // Scroll to zoom
194- if (auto * wheelEvent = static_cast <QWheelEvent*>(event))
195- zoomAround (wheelEvent->position ().toPoint (), wheelEvent->angleDelta ().x () / 1200 .f );
196-
197- break ;
198- }
199-
200- case QEvent::MouseButtonPress:
201- {
202- if (const auto * mouseEvent = static_cast <QMouseEvent*>(event))
203- {
204- if (mouseEvent->button () == Qt::MiddleButton)
205- resetView ();
206-
207- // Navigation
208- if (mouseEvent->buttons () == Qt::LeftButton)
209- {
210- setIsNavigating (true );
211- setCursor (Qt::ClosedHandCursor);
212- _mousePositions << mouseEvent->pos ();
213- update ();
214- }
215- }
216-
217- break ;
218- }
219-
220- case QEvent::MouseButtonRelease:
221- {
222- setIsNavigating (false );
223- setCursor (Qt::ArrowCursor);
224- _mousePositions.clear ();
225- update ();
226-
227- break ;
228- }
229-
230- case QEvent::MouseMove:
231- {
232- if (const auto * mouseEvent = static_cast <QMouseEvent*>(event))
233- {
234- _mousePositions << mouseEvent->pos ();
173+ _pointRenderer.getNavigator ().initialize (this );
174+ }
235175
236- if (mouseEvent->buttons () == Qt::LeftButton && _mousePositions.size () >= 2 )
237- {
238- const auto & previousMousePosition = _mousePositions[_mousePositions.size () - 2 ];
239- const auto & currentMousePosition = _mousePositions[_mousePositions.size () - 1 ];
240- const auto panVector = currentMousePosition - previousMousePosition;
176+ bool ScatterplotWidget::event (QEvent* event)
177+ {
178+ if (!event)
179+ return QOpenGLWidget::event (event);
241180
242- panBy (panVector);
243- }
244- }
181+ // Need this to receive key release events in the two-dimensional renderer
182+ if (event-> type () == QEvent::ShortcutOverride) {
183+ const auto keyEvent = dynamic_cast <QKeyEvent*>(event);
245184
246- break ;
247- }
185+ if (keyEvent-> key () == Qt::Key_Alt) {
186+ event-> accept ();
248187
188+ return QOpenGLWidget::event (event);
249189 }
250-
251190 }
252191
253192 return QOpenGLWidget::event (event);
254193}
255194
256- void ScatterplotWidget::resetView ()
257- {
258- _navigationAction.getZoomRectangleAction ().setBounds (_dataRectangleAction.getBounds ());
259- }
260-
261- void ScatterplotWidget::panBy (const QPointF& to)
262- {
263- auto & zoomRectangleAction = _navigationAction.getZoomRectangleAction ();
264-
265- const auto moveBy = QPointF (to.x () / _widgetSizeInfo.width * zoomRectangleAction.getWidth () * _widgetSizeInfo.ratioWidth * -1 .f ,
266- to.y () / _widgetSizeInfo.height * zoomRectangleAction.getHeight () * _widgetSizeInfo.ratioHeight );
267-
268- zoomRectangleAction.translateBy ({ moveBy.x (), moveBy.y () });
269-
270- update ();
271- }
272-
273- void ScatterplotWidget::zoomAround (const QPointF& at, float factor)
274- {
275- auto & zoomRectangleAction = _navigationAction.getZoomRectangleAction ();
276-
277- // the widget might have a different aspect ratio than the square opengl viewport
278- const auto offsetBounds = QPointF (zoomRectangleAction.getWidth () * (0 .5f * (1 - _widgetSizeInfo.ratioWidth )),
279- zoomRectangleAction.getHeight () * (0 .5f * (1 - _widgetSizeInfo.ratioHeight )) * -1 .f );
280-
281- const auto originBounds = QPointF (zoomRectangleAction.getLeft (), zoomRectangleAction.getTop ());
282-
283- // translate mouse point in widget to mouse point in bounds coordinates
284- const auto atTransformed = QPointF (at.x () / _widgetSizeInfo.width * zoomRectangleAction.getWidth () * _widgetSizeInfo.ratioWidth ,
285- at.y () / _widgetSizeInfo.height * zoomRectangleAction.getHeight () * _widgetSizeInfo.ratioHeight * -1 .f );
286-
287- const auto atInBounds = originBounds + offsetBounds + atTransformed;
288-
289- // ensure mouse position is the same after zooming
290- const auto currentBoundCenter = zoomRectangleAction.getCenter ();
291-
292- float moveMouseX = (atInBounds.x () - currentBoundCenter.first ) * factor;
293- float moveMouseY = (atInBounds.y () - currentBoundCenter.second ) * factor;
294-
295- // zoom and move view
296- zoomRectangleAction.translateBy ({ moveMouseX, moveMouseY });
297- zoomRectangleAction.expandBy (-1 .f * factor);
298-
299- update ();
300- }
301-
302195bool ScatterplotWidget::isInitialized () const
303196{
304197 return _isInitialized;
0 commit comments