From 9b09681c8803d44402b3f4cf776635613aabfb49 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 15 Sep 2020 17:04:16 +0200 Subject: [PATCH 1/2] added code provided by jc-Rosichini in #591 --- src/chatdlg.cpp | 26 ++++++++++++++++++++++---- src/chatdlgbase.ui | 7 +++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/chatdlg.cpp b/src/chatdlg.cpp index d553a998c3..cf5481d8d5 100755 --- a/src/chatdlg.cpp +++ b/src/chatdlg.cpp @@ -106,8 +106,26 @@ void CChatDlg::OnClearChatHistory() void CChatDlg::AddChatText ( QString strChatText ) { // add new text in chat window - txvChatWindow->append ( strChatText ); - - // notify accessibility plugin that text has changed - QAccessible::updateAccessibility ( new QAccessibleValueChangeEvent ( txvChatWindow, strChatText ) ); + + // analyze strChatText to check if hyperlink + if (strChatText.contains("https://", Qt::CaseInsensitive) | strChatText.contains("http://", Qt::CaseInsensitive)) + { + int indx_http = strChatText.indexOf("http", 0); + int indx_space = strChatText.indexOf(" ", indx_http); + if (indx_space==-1) indx_space=strChatText.length(); + + int cutslash = (strChatText.at(indx_space-1)=='/') ? 1:0; // drop "/" if last character of url text + + QString new_strChatText = strChatText.left(indx_http)+""+strChatText.mid(indx_http,indx_space-indx_http-cutslash)+" "+strChatText.right(strChatText.length()-indx_space); + + txvChatWindow->append (new_strChatText); + // notify accessibility plugin that text has changed + QAccessible::updateAccessibility ( new QAccessibleValueChangeEvent ( txvChatWindow, new_strChatText) ); + } + else + { + txvChatWindow->append ( strChatText ); + // notify accessibility plugin that text has changed + QAccessible::updateAccessibility ( new QAccessibleValueChangeEvent ( txvChatWindow, strChatText ) ); + } } diff --git a/src/chatdlgbase.ui b/src/chatdlgbase.ui index 876256af11..9dff0ddf64 100755 --- a/src/chatdlgbase.ui +++ b/src/chatdlgbase.ui @@ -33,11 +33,14 @@ false - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::NoTextInteraction|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - false + true + + true + From b09c44fe4b9a6417311a0259dfcfd7096a18acc1 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 16 Sep 2020 18:54:34 +0200 Subject: [PATCH 2/2] update by jc-Rosichini (https://github.com/corrados/jamulus/issues/591#issuecomment-692995596) --- src/chatdlg.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/chatdlg.cpp b/src/chatdlg.cpp index cf5481d8d5..ce0863cf0a 100755 --- a/src/chatdlg.cpp +++ b/src/chatdlg.cpp @@ -107,18 +107,26 @@ void CChatDlg::AddChatText ( QString strChatText ) { // add new text in chat window - // analyze strChatText to check if hyperlink - if (strChatText.contains("https://", Qt::CaseInsensitive) | strChatText.contains("http://", Qt::CaseInsensitive)) + // analyze strChatText to check if hyperlink (limit ourselves to https:://) + int indx_http = strChatText.indexOf("https://", 0); + if (indx_http != -1) { - int indx_http = strChatText.indexOf("http", 0); int indx_space = strChatText.indexOf(" ", indx_http); if (indx_space==-1) indx_space=strChatText.length(); int cutslash = (strChatText.at(indx_space-1)=='/') ? 1:0; // drop "/" if last character of url text - - QString new_strChatText = strChatText.left(indx_http)+""+strChatText.mid(indx_http,indx_space-indx_http-cutslash)+" "+strChatText.right(strChatText.length()-indx_space); - - txvChatWindow->append (new_strChatText); + + QString URL_name = strChatText.mid(indx_http,indx_space-indx_http-cutslash); // as entered by the user + QUrl URL = QUrl::fromUserInput(URL_name); + + QString new_strChatText; + if ( URL.isValid() ) + { + new_strChatText.append( strChatText.left( indx_http )+""+URL_name+" "+strChatText.right( strChatText.length()-indx_space ) ); + } + else new_strChatText.append( strChatText ); // no change + + txvChatWindow->append ( new_strChatText ); // notify accessibility plugin that text has changed QAccessible::updateAccessibility ( new QAccessibleValueChangeEvent ( txvChatWindow, new_strChatText) ); }