From f4c02946dda3f510102253779e5c88c8baf082c3 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Sun, 23 Aug 2020 19:32:03 +0200 Subject: [PATCH] copy hyperlink from memo/open in browser --- src/mainwindow.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dc9a58f..6de4514 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1525,6 +1525,47 @@ void MainWindow::setupchatTab() { }); +QObject::connect(copylink, &QAction::triggered, [=] { + +QModelIndex index = ui->listChat->currentIndex(); +QString memo_chat = index.data(Qt::DisplayRole).toString(); +QClipboard *clipboard = QGuiApplication::clipboard(); +QRegExp rx("((?:https?|ftp)://\\S+)"); +int pos = rx.indexIn(memo_chat, 0); +if (-1 != pos) +{ + QString cap = rx.cap(0); + cap = cap.left(cap.indexOf('\'')); + int startPos = cap.indexOf("

"); + int endPos = cap.indexOf("

"); + int length = endPos - startPos; + QString hyperlink = cap.mid(startPos, length); + clipboard->setText(hyperlink); + ui->statusBar->showMessage(tr("Copied Hyperlink to clipboard"), 3 * 1000); + +} +}); + +QObject::connect(openlink, &QAction::triggered, [=] { + +QModelIndex index = ui->listChat->currentIndex(); +QString memo_chat = index.data(Qt::DisplayRole).toString(); +QClipboard *clipboard = QGuiApplication::clipboard(); +QRegExp rx("((?:https?|ftp)://\\S+)"); +int pos = rx.indexIn(memo_chat, 0); +if (-1 != pos) +{ + QString cap = rx.cap(0); + cap = cap.left(cap.indexOf('\'')); + int startPos = cap.indexOf("

"); + int endPos = cap.indexOf("

"); + int length = endPos - startPos; + QString hyperlink = cap.mid(startPos, length); + QDesktopServices::openUrl(QUrl(hyperlink)); + +} +}); + QObject::connect(copymessage, &QAction::triggered, [=] {