From: <em...@us...> - 2006-05-13 09:46:13
|
Author: emostar Date: 2006-05-13 18:45:28 +0900 (Sat, 13 May 2006) New Revision: 4417 Modified: trunk/qt-gui/src/mlview3.cpp trunk/qt-gui/src/mlview3.h Log: Patch by Erik Johansson to copy the url with a right click. Modified: trunk/qt-gui/src/mlview3.cpp =================================================================== --- trunk/qt-gui/src/mlview3.cpp 2006-05-01 22:22:56 UTC (rev 4416) +++ trunk/qt-gui/src/mlview3.cpp 2006-05-13 09:45:28 UTC (rev 4417) @@ -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); + } + } +} + // ----------------------------------------------------------------------------- Modified: trunk/qt-gui/src/mlview3.h =================================================================== --- trunk/qt-gui/src/mlview3.h 2006-05-01 22:22:56 UTC (rev 4416) +++ trunk/qt-gui/src/mlview3.h 2006-05-13 09:45:28 UTC (rev 4417) @@ -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); }; |