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