QTfrontend/ui/widget/chatwidget.cpp
changeset 8768 7450cb9c815b
parent 8762 388d2bf73ff9
child 8887 539380a498e4
equal deleted inserted replaced
8765:688062f1db59 8768:7450cb9c815b
   293     gameSettings = settings;
   293     gameSettings = settings;
   294 }
   294 }
   295 
   295 
   296 void HWChatWidget::linkClicked(const QUrl & link)
   296 void HWChatWidget::linkClicked(const QUrl & link)
   297 {
   297 {
   298     if (link.scheme() == "http")
   298     if ((link.scheme() == "http") or (link.scheme() == "https"))
   299         QDesktopServices::openUrl(link);
   299         QDesktopServices::openUrl(link);
   300     if (link.scheme() == "hwnick")
   300     else if (link.scheme() == "hwnick")
   301     {
   301     {
   302         // decode nick
   302         // decode nick
   303         QString nick = QString::fromUtf8(QByteArray::fromBase64(link.encodedQuery()));
   303         QString nick = QString::fromUtf8(QByteArray::fromBase64(link.encodedQuery()));
   304         QModelIndexList mil = chatNicks->model()->match(chatNicks->model()->index(0, 0), Qt::DisplayRole, nick);
   304         QModelIndexList mil = chatNicks->model()->match(chatNicks->model()->index(0, 0), Qt::DisplayRole, nick);
   305 
   305 
   366 
   366 
   367     // unlinked nick (if own one)
   367     // unlinked nick (if own one)
   368     return QString("<span class=\"nick\">%1</span>").arg(Qt::escape(nickname));
   368     return QString("<span class=\"nick\">%1</span>").arg(Qt::escape(nickname));
   369 }
   369 }
   370 
   370 
   371 const QRegExp HWChatWidget::URLREGEXP = QRegExp("(http://)?(www\\.)?((hedgewars\\.org|code\\.google\\.com|googlecode\\.com|hh\\.unit22\\.org)(/[^ ]*)?)");
   371 const QRegExp HWChatWidget::URLREGEXP = QRegExp("(http(s)?://)?(www\\.)?((hedgewars\\.org|code\\.google\\.com|googlecode\\.com|hh\\.unit22\\.org)(/[^ ]*)?)");
   372 
   372 
   373 bool HWChatWidget::containsHighlight(const QString & sender, const QString & message)
   373 bool HWChatWidget::containsHighlight(const QString & sender, const QString & message)
   374 {
   374 {
   375     if ((sender != m_userNick) && (!m_userNick.isEmpty()))
   375     if ((sender != m_userNick) && (!m_userNick.isEmpty()))
   376     {
   376     {
   387 
   387 
   388 QString HWChatWidget::messageToHTML(const QString & message)
   388 QString HWChatWidget::messageToHTML(const QString & message)
   389 {
   389 {
   390     QString formattedStr = Qt::escape(message);
   390     QString formattedStr = Qt::escape(message);
   391     // link some urls
   391     // link some urls
   392     formattedStr = formattedStr.replace(URLREGEXP, "<a href=\"http://\\3\">\\3</a>");
   392     formattedStr = formattedStr.replace(URLREGEXP, "<a href=\"http\\2://\\4\">\\4</a>");
   393     return formattedStr;
   393     return formattedStr;
   394 }
   394 }
   395 
   395 
   396 void HWChatWidget::onChatAction(const QString & nick, const QString & action)
   396 void HWChatWidget::onChatAction(const QString & nick, const QString & action)
   397 {
   397 {