Fixed bug when the user clicks on a link without http:// in a QTextBrowser. This link was opened directly in RetroShare.

Show clickable links in the channel feed message.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4923 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-02-11 13:42:42 +00:00
parent 6a44342e4f
commit 340a313fea
11 changed files with 78 additions and 40 deletions

View File

@ -339,6 +339,7 @@ HEADERS += rshare.h \
gui/common/FriendList.h \
gui/common/FriendSelectionWidget.h \
gui/common/HashBox.h \
gui/common/LinkTextBrowser.h \
gui/style/RSStyle.h \
gui/style/StyleDialog.h \
gui/MessagesDialog.h \
@ -584,6 +585,7 @@ SOURCES += main.cpp \
gui/common/FriendList.cpp \
gui/common/FriendSelectionWidget.cpp \
gui/common/HashBox.cpp \
gui/common/LinkTextBrowser.cpp \
gui/style/RSStyle.cpp \
gui/style/StyleDialog.cpp \
gui/settings/configpage.cpp \

View File

@ -1250,7 +1250,7 @@ border-image: url(:/images/closepressed.png)
</item>
</layout>
</widget>
<widget class="QTextBrowser" name="postText">
<widget class="LinkTextBrowser" name="postText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -1262,12 +1262,6 @@ border-image: url(:/images/closepressed.png)
<pointsize>9</pointsize>
</font>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>true</bool>
</property>
</widget>
</widget>
</widget>
@ -1285,6 +1279,11 @@ border-image: url(:/images/closepressed.png)
</action>
</widget>
<customwidgets>
<customwidget>
<class>LinkTextBrowser</class>
<extends>QTextBrowser</extends>
<header>gui/common/LinkTextBrowser.h</header>
</customwidget>
<customwidget>
<class>GroupTreeWidget</class>
<extends>QWidget</extends>

View File

@ -1218,7 +1218,7 @@ border: 1px solid #CCCCCC;}</string>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QTextBrowser" name="msgText">
<widget class="LinkTextBrowser" name="msgText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -1238,12 +1238,6 @@ background: white;}</string>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>true</bool>
</property>
</widget>
<widget class="QWidget" name="layoutWidget_2">
<layout class="QVBoxLayout" name="verticalLayoutEdit">
@ -1477,6 +1471,11 @@ background: white;}</string>
<header>gui/common/FriendList.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LinkTextBrowser</class>
<extends>QTextBrowser</extends>
<header>gui/common/LinkTextBrowser.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="images.qrc"/>

View File

@ -173,7 +173,7 @@ border-image: url(:/images/closepressed.png)
<widget class="QWidget" name="verticalLayoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTextBrowser" name="textBrowser">
<widget class="LinkTextBrowser" name="textBrowser">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
@ -191,12 +191,6 @@ border-image: url(:/images/closepressed.png)
border-radius: 6px;
background: white;}</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
@ -665,6 +659,11 @@ border: 1px solid #CCCCCC;
<header location="global">gui/common/HashBox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LinkTextBrowser</class>
<extends>QTextBrowser</extends>
<header>gui/common/LinkTextBrowser.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>

View File

@ -80,7 +80,7 @@ public:
EmbedInHtmlAhref() :
EmbedInHtml(Ahref)
{
myRE.setPattern("(\\bretroshare://[^\\s]*)|(\\bhttps?://[^\\s]*)|(\\bwww\\.[^\\s]*)");
myRE.setPattern("(\\bretroshare://[^\\s]*)|(\\bhttps?://[^\\s]*)|(\\bfile://[^\\s]*)|(\\bwww\\.[^\\s]*)");
}
};

View File

@ -0,0 +1,19 @@
#include <QDesktopServices>
#include "LinkTextBrowser.h"
LinkTextBrowser::LinkTextBrowser(QWidget *parent) :
QTextBrowser(parent)
{
setOpenExternalLinks(true);
setOpenLinks(false);
connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
}
void LinkTextBrowser::linkClicked(const QUrl &url)
{
// some links are opened directly in the QTextBrowser with open external links set to true,
// so we handle links by our own
QDesktopServices::openUrl(url);
}

View File

@ -0,0 +1,17 @@
#ifndef LINKTEXTBROWSER_H
#define LINKTEXTBROWSER_H
#include <QTextBrowser>
class LinkTextBrowser : public QTextBrowser
{
Q_OBJECT
public:
explicit LinkTextBrowser(QWidget *parent = 0);
private slots:
void linkClicked(const QUrl &url);
};
#endif // LINKTEXTBROWSER_H

View File

@ -116,7 +116,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QTextBrowser" name="rsid">
<widget class="LinkTextBrowser" name="rsid">
<property name="enabled">
<bool>true</bool>
</property>
@ -141,9 +141,6 @@
<property name="readOnly">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
@ -549,11 +546,7 @@
</property>
<layout class="QVBoxLayout" name="_11">
<item>
<widget class="QTextBrowser" name="signers">
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
<widget class="LinkTextBrowser" name="signers"/>
</item>
</layout>
</widget>
@ -765,6 +758,11 @@ p, li { white-space: pre-wrap; }
<header>gui/common/AvatarWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LinkTextBrowser</class>
<extends>QTextBrowser</extends>
<header>gui/common/LinkTextBrowser.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>

View File

@ -29,6 +29,7 @@
#include "gui/notifyqt.h"
#include "util/misc.h"
#include "gui/RetroShareLink.h"
#include "gui/chat/HandleRichText.h"
#include <retroshare/rschannels.h>
@ -125,7 +126,7 @@ void ChanMsgItem::updateItemStatic()
{
/* subject */
titleLabel->setText(QString::fromStdWString(cmi.subject));
subjectLabel->setText(QString::fromStdWString(cmi.msg));
subjectLabel->setText(RsHtml::formatText(QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
/* disable buttons: deletion facility not enabled with cache services yet */
clearButton->setEnabled(false);
@ -162,7 +163,7 @@ void ChanMsgItem::updateItemStatic()
}
}
msgLabel->setText(QString::fromStdWString(cmi.msg));
msgLabel->setText(RsHtml::formatText(QString::fromStdWString(cmi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
msgWidget->setVisible(!cmi.msg.empty());
QDateTime qtime;

View File

@ -466,6 +466,9 @@ border-radius: 10px;}</string>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>

View File

@ -39,19 +39,13 @@
<widget class="QWidget" name="layoutWidget">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QTextBrowser" name="msgText">
<widget class="LinkTextBrowser" name="msgText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
@ -481,6 +475,13 @@ p, li { white-space: pre-wrap; }
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>LinkTextBrowser</class>
<extends>QTextBrowser</extends>
<header>gui/common/LinkTextBrowser.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>
</resources>