When a link is posted as a normal message, I can drag it from the ircview into a browser and it will open. Or drag it to a text box and the link is pasted. However, if I try dragging a link from the topic panel in Konversation, it simply starts selecting text; it doesn't drag the link as a single object. I can select the whole link (or any other subset of text) and drag the selection, but that's not the same...
[Comment from a bug triager] Reported as bug 261841. (double report probably due the network problems that appearead yesterday) Closing
I tried to mark it as a duplicate but I kept getting 'database locked' errors. *** This bug has been marked as a duplicate of bug 261841 ***
commit 78bb1dd38b58b0d746b034d81edc00a0c2562121 branch master Author: Eike Hein <hein@kde.org> Date: Mon Jan 3 19:20:04 2011 +0100 Make web links and email addresses in the topic area draggable. BUG:261843 Clearing the selection if one is set at the time a drag is initiated requires Konversation to be built against Qt 4.7 or higher. diff --git a/src/viewer/topiclabel.cpp b/src/viewer/topiclabel.cpp index 516a250..a7e5e85 100644 --- a/src/viewer/topiclabel.cpp +++ b/src/viewer/topiclabel.cpp @@ -30,6 +30,7 @@ namespace Konversation setAlignment(Qt::AlignVCenter | Qt::AlignLeft); setTextInteractionFlags(Qt::TextBrowserInteraction); + m_mousePressedOnUrl = false; m_isOnChannel = false; m_server = NULL; @@ -140,6 +141,66 @@ namespace Konversation resetLinkHighlightState(); } + void TopicLabel::mousePressEvent(QMouseEvent* ev) + { + if (ev->button() == Qt::LeftButton) + { + if (!m_currentUrl.isEmpty()) + { + m_mousePressedOnUrl = true; + m_mousePressPosition = ev->pos(); + + // We need to keep a copy of the current URL because by the time + // the Manhatten length is reached and the drag is initiated the + // cursor may have left the link, causing m_currentUrl to be + // cleared. + m_dragUrl = m_currentUrl; + } + } + + QLabel::mousePressEvent(ev); + } + + void TopicLabel::mouseReleaseEvent(QMouseEvent *ev) + { + if (ev->button() == Qt::LeftButton) + { + m_mousePressedOnUrl = false; + } + + QLabel::mouseReleaseEvent(ev); + } + + void TopicLabel::mouseMoveEvent(QMouseEvent* ev) + { + if (m_mousePressedOnUrl && (m_mousePressPosition - ev->pos()).manhattanLength() > KApplication::startDragDistance()) + { +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + setSelection(0, 0); +#endif + + QPointer<QDrag> drag = new QDrag(this); + QMimeData* mimeData = new QMimeData; + + KUrl url(m_dragUrl); + url.populateMimeData(mimeData); + + drag->setMimeData(mimeData); + + QPixmap pixmap = KIO::pixmapForUrl(url, 0, KIconLoader::Desktop, KIconLoader::SizeMedium); + drag->setPixmap(pixmap); + + drag->exec(); + + m_mousePressedOnUrl = false; + m_dragUrl.clear(); + + return; + } + + QLabel::mouseMoveEvent(ev); + } + void TopicLabel::setText(const QString& text) { m_fullText = text; diff --git a/src/viewer/topiclabel.h b/src/viewer/topiclabel.h index 8656bad..5080876 100644 --- a/src/viewer/topiclabel.h +++ b/src/viewer/topiclabel.h @@ -51,7 +51,10 @@ namespace Konversation int textWidth(const QString& text); virtual void leaveEvent (QEvent*); virtual void contextMenuEvent(QContextMenuEvent* ev); - void resizeEvent(QResizeEvent*); + virtual void resizeEvent(QResizeEvent*); + virtual void mouseReleaseEvent(QMouseEvent* ev); + virtual void mousePressEvent(QMouseEvent* ev); + virtual void mouseMoveEvent(QMouseEvent* ev); protected slots: void highlightedSlot(const QString&); @@ -71,6 +74,9 @@ namespace Konversation QString m_currentChannel; bool m_isOnChannel; QString m_currentUrl; + QString m_dragUrl; + bool m_mousePressedOnUrl; + QPoint m_mousePressPosition; }; }
*** Bug 261841 has been marked as a duplicate of this bug. ***