VisualizationDragWidget.cpp
55 lines
| 1.5 KiB
| text/x-c
|
CppLexer
r838 | #include "Visualization/VisualizationDragWidget.h" | |||
#include "Visualization/VisualizationDragDropContainer.h" | ||||
#include <QApplication> | ||||
r844 | #include <QMouseEvent> | |||
r838 | ||||
r958 | #include <SqpApplication.h> | |||
r838 | struct VisualizationDragWidget::VisualizationDragWidgetPrivate { | |||
r844 | QPoint m_DragStartPosition; | |||
bool m_DragStartPositionValid = false; | ||||
r838 | ||||
r844 | explicit VisualizationDragWidgetPrivate() {} | |||
r838 | }; | |||
r844 | VisualizationDragWidget::VisualizationDragWidget(QWidget *parent) | |||
: QWidget{parent}, impl{spimpl::make_unique_impl<VisualizationDragWidgetPrivate>()} | ||||
r838 | { | |||
} | ||||
void VisualizationDragWidget::mousePressEvent(QMouseEvent *event) | ||||
{ | ||||
r844 | if (event->button() == Qt::LeftButton) { | |||
impl->m_DragStartPosition = event->pos(); | ||||
} | ||||
r838 | ||||
r844 | impl->m_DragStartPositionValid = isDragAllowed(); | |||
r838 | ||||
QWidget::mousePressEvent(event); | ||||
} | ||||
void VisualizationDragWidget::mouseMoveEvent(QMouseEvent *event) | ||||
{ | ||||
r844 | if (!impl->m_DragStartPositionValid || !isDragAllowed()) { | |||
r838 | return; | |||
r844 | } | |||
r838 | ||||
r844 | if (!(event->buttons() & Qt::LeftButton)) { | |||
r838 | return; | |||
r844 | } | |||
r838 | ||||
r958 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::DragAndDrop | |||
|| event->modifiers().testFlag(Qt::AltModifier)) { | ||||
r838 | ||||
r958 | if ((event->pos() - impl->m_DragStartPosition).manhattanLength() | |||
< QApplication::startDragDistance()) { | ||||
return; | ||||
} | ||||
r838 | ||||
r958 | emit dragDetected(this, impl->m_DragStartPosition); | |||
} | ||||
r838 | ||||
QWidget::mouseMoveEvent(event); | ||||
} | ||||