Hi,

The attached patch adds "Copy URL" to the popup menu when the user 
right-clicks on a url. If "Copy URL" is selected, the url is copied to both 
the Ctrl+C/V/X clipboard and the selection clipboard.

The reason for this patch is that I often find myself copying a url, changing 
desktop and opening the webpage in an already running konqueror instance. 
Trying to select the url is not as easy as just right-clicking on the url and 
selecting copy url, hence the patch :)

I add the url to both clipboards since I personally prefer the selection 
clipboard, but I'm guessing that others may prefer the "Windows"-clipboard.

// Erik

-- 
Fatal error! Hit any user to continue..

Erik Johansson
http://ejohansson.se
Index: mlview3.cpp
===================================================================
--- mlview3.cpp	(revision 4416)
+++ mlview3.cpp	(working copy)
@@ -30,6 +30,8 @@
 #include <qpainter.h>
 #include <qaccel.h>
 #include <qregexp.h>
+#include <qapplication.h>
+#include <qclipboard.h>
 
 #include "ewidgets.h"
 #include "licq_icqd.h"
@@ -144,7 +146,37 @@
   setPaper(QBrush(c));
 }
 
+/** @brief Adds "Copy URL" to the popup menu if the user right clicks on a URL. */
+QPopupMenu* MLView::createPopupMenu(const QPoint& point)
+{
+  QPopupMenu *menu = QTextBrowser::createPopupMenu(point);
 
+  m_url = anchorAt(point);
+  if (!m_url.isNull() && !m_url.isEmpty())
+    menu->insertItem(tr("Copy URL"), this, SLOT(slotCopyUrl()));
+
+  return menu;
+}
+
+/** @brief Adds the contents of m_url to the clipboard. */
+void MLView::slotCopyUrl()
+{
+  if (!m_url.isNull() && !m_url.isEmpty())
+  {
+    // This copies m_url to both the normal clipboard (Ctrl+C/V/X)
+    // and the selection clipboard (paste with middle mouse button).
+    QClipboard *cb = QApplication::clipboard();
+    cb->setText(m_url);
+    if (cb->supportsSelection())
+    {
+      bool enabled = cb->selectionModeEnabled();
+      cb->setSelectionMode(!enabled);
+      cb->setText(m_url);
+      cb->setSelectionMode(enabled);
+    }
+  }
+}
+
 // -----------------------------------------------------------------------------
 
 
Index: mlview3.h
===================================================================
--- mlview3.h	(revision 4416)
+++ mlview3.h	(working copy)
@@ -24,10 +24,18 @@
   void setHandleLinks(bool enable);
 
   static QString toRichText(const QString& s, bool highlightURLs = false, bool useHTML = false);
+
+protected:
+  virtual QPopupMenu *createPopupMenu(const QPoint& pos);
+
 public slots:
   virtual void setSource(const QString& name);
+  void slotCopyUrl();
+
 private:
   bool m_handleLinks;
+  QString m_url;
+
 signals:
   void viewurl(QWidget*, QString);
 };

Reply via email to