1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Dragging the whole non-shrinked text in SqueezeLabel now

This commit is contained in:
nowrep 2012-05-27 12:43:57 +02:00
parent c992778556
commit 033bfa246b
2 changed files with 33 additions and 0 deletions

View File

@ -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();
}

View File

@ -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