[Konversation-devel] [Bug 261843] Links in the topic can't be dragged

Eike Hein hein at kde.org
Mon Jan 3 20:15:25 CET 2011


https://bugs.kde.org/show_bug.cgi?id=261843


Eike Hein <hein at kde.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |FIXED




--- Comment #3 from Eike Hein <hein kde org>  2011-01-03 20:15:23 ---
commit 78bb1dd38b58b0d746b034d81edc00a0c2562121
branch master
Author: Eike Hein <hein at 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;
     };

 }

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Konversation-devel mailing list