From 033bfa246b5cd9161da4917380a8d326f0278e0a Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 27 May 2012 12:43:57 +0200 Subject: [PATCH] Dragging the whole non-shrinked text in SqueezeLabel now --- src/lib/3rdparty/squeezelabelv2.cpp | 29 +++++++++++++++++++++++++++++ src/lib/3rdparty/squeezelabelv2.h | 4 ++++ 2 files changed, 33 insertions(+) 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