File indexing completed on 2022-11-29 20:00:35

0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #include "clipboard.h"
0005 
0006 #include <QClipboard>
0007 #include <QGuiApplication>
0008 #include <QMimeData>
0009 #include <QRegularExpression>
0010 #include <QUrl>
0011 
0012 Clipboard::Clipboard(QObject *parent)
0013     : QObject(parent)
0014     , m_clipboard(QGuiApplication::clipboard())
0015 {
0016 }
0017 
0018 void Clipboard::saveText(const QString &message)
0019 {
0020     QRegularExpression re(QStringLiteral("<[^>]*>"));
0021     auto *mineData = new QMimeData; // ownership is transferred to clipboard
0022     mineData->setHtml(message);
0023     QString html = message;
0024     mineData->setText(html.replace(re, QString()));
0025     m_clipboard->setMimeData(mineData);
0026 }