diff --git a/src/lib/3rdparty/squeezelabelv2.cpp b/src/lib/3rdparty/squeezelabelv2.cpp index 3735db1b9..0e371f285 100644 --- a/src/lib/3rdparty/squeezelabelv2.cpp +++ b/src/lib/3rdparty/squeezelabelv2.cpp @@ -85,3 +85,32 @@ void SqueezeLabelV2::resizeEvent(QResizeEvent* event) QString elided = fm.elidedText(m_originalText, Qt::ElideMiddle, width()); QLabel::setText(elided); } + +void SqueezeLabelV2::mousePressEvent(QMouseEvent* event) +{ + if (event->buttons() & Qt::LeftButton) { + m_dragStart = event->pos(); + } + + QLabel::mousePressEvent(event); +} + +void SqueezeLabelV2::mouseMoveEvent(QMouseEvent* event) +{ + if (!(event->buttons() & Qt::LeftButton) || selectedText().length() != text().length()) { + QLabel::mouseMoveEvent(event); + return; + } + + int manhattanLength = (event->pos() - m_dragStart).manhattanLength(); + if (manhattanLength <= QApplication::startDragDistance()) { + return; + } + + QDrag* drag = new QDrag(this); + QMimeData* mime = new QMimeData; + mime->setText(m_originalText); + + drag->setMimeData(mime); + drag->exec(); +} diff --git a/src/lib/3rdparty/squeezelabelv2.h b/src/lib/3rdparty/squeezelabelv2.h index 15b683a26..176951cc2 100644 --- a/src/lib/3rdparty/squeezelabelv2.h +++ b/src/lib/3rdparty/squeezelabelv2.h @@ -41,8 +41,12 @@ protected: void keyPressEvent(QKeyEvent* event); void resizeEvent(QResizeEvent* event); + void mousePressEvent(QMouseEvent* event); + void mouseMoveEvent(QMouseEvent* event); + private: QString m_originalText; + QPoint m_dragStart; }; #endif // SQUEEZELABELV2_H