Commit b111957b authored by Volodymyr Melnychenko's avatar Volodymyr Melnychenko

Data exchange between Basket and other apps(via clipboard and drag&drop) is restored.

parent 508772c0
Pipeline #47638 passed with stage
in 4 minutes and 6 seconds
......@@ -46,7 +46,6 @@
#include <QtXml/QDomDocument>
#include <KTextEdit>
#include <KAboutData>
#include <KActionCollection>
#include <KAuthorized>
......@@ -3967,11 +3966,8 @@ void BasketScene::doCopy(CopyMode copyMode)
int countCopied = countSelecteds();
if (selection->firstStacked()) {
QDrag *d = NoteDrag::dragObject(selection, copyMode == CutToClipboard, /*source=*/nullptr); // d will be deleted by QT
// /*bool shouldRemove = */d->drag();
// delete selection;
cb->setMimeData(d->mimeData(), mode); // NoteMultipleDrag will be deleted by QT
// if (copyMode == CutToClipboard && !note->useFile()) // If useFile(), NoteDrag::dragObject() will delete it TODO
// note->slotDelete();
cb->setMimeData(d->mimeData(), mode);
if (copyMode == CutToClipboard) {
noteDeleteWithoutConfirmation(/*deleteFilesToo=*/false);
......
......@@ -311,10 +311,8 @@ QString TextContent::toHtml(const QString & /*imageName*/, const QString & /*cut
QString HtmlContent::toHtml(const QString & /*imageName*/, const QString & /*cuttedFullPath*/)
{
// return Tools::htmlToParagraph(html());
QTextDocument simpleRichText;
simpleRichText.setHtml(html());
return Tools::textDocumentToMinimalHTML(&simpleRichText);
//extract HTML content exactly as is, with no further processing applied
return m_graphicsTextItem.document()->toHtml("utf-8");
}
QString ImageContent::toHtml(const QString & /*imageName*/, const QString &cuttedFullPath)
......@@ -373,19 +371,16 @@ QPixmap AnimationContent::toPixmap()
void NoteContent::toLink(QUrl *url, QString *title, const QString &cuttedFullPath)
{
if (useFile()) {
*url = QUrl::fromUserInput(cuttedFullPath.isEmpty() ? fullPath() : cuttedFullPath);
*title = (cuttedFullPath.isEmpty() ? fullPath() : cuttedFullPath);
} else {
*url = QUrl();
title->clear();
}
*url = QUrl();
title->clear();
}
void LinkContent::toLink(QUrl *url, QString *title, const QString & /*cuttedFullPath*/)
{
*url = this->url();
*title = this->title();
}
void CrossReferenceContent::toLink(QUrl *url, QString *title, const QString & /*cuttedFullPath*/)
{
*url = this->url();
......@@ -397,11 +392,6 @@ void LauncherContent::toLink(QUrl *url, QString *title, const QString &cuttedFul
*url = QUrl::fromUserInput(cuttedFullPath.isEmpty() ? fullPath() : cuttedFullPath);
*title = name();
}
void UnknownContent::toLink(QUrl *url, QString *title, const QString & /*cuttedFullPath*/)
{
*url = QUrl();
*title = QString();
}
bool TextContent::useFile() const
{
......
......@@ -876,7 +876,6 @@ public:
// Simple Generic Methods:
QString toText(const QString & /*cuttedFullPath*/) override;
QString toHtml(const QString &imageName, const QString &cuttedFullPath) override;
void toLink(QUrl *url, QString *title, const QString &cuttedFullPath) override;
bool useFile() const override;
bool canBeSavedAs() const override;
QString saveAsFilters() const override;
......
......@@ -67,10 +67,10 @@ QDrag *NoteDrag::dragObject(NoteSelection *noteList, bool cutting, QWidget *sour
}
// The "Other Flavors" Serialization:
serializeText(noteList, multipleDrag);
serializeHtml(noteList, multipleDrag);
serializeImage(noteList, multipleDrag);
serializeLinks(noteList, multipleDrag, cutting);
serializeText(noteList, mimeData);
serializeHtml(noteList, mimeData);
serializeImage(noteList, mimeData);
serializeLinks(noteList, mimeData, cutting);
// The Alternate Flavors:
if (noteList->count() == 1)
......@@ -120,7 +120,7 @@ void NoteDrag::serializeNotes(NoteSelection *noteList, QDataStream &stream, bool
stream << (quint64)0; // Mark the end of the notes in this group/hierarchy.
}
void NoteDrag::serializeText(NoteSelection *noteList, QDrag *multipleDrag)
void NoteDrag::serializeText(NoteSelection *noteList, QMimeData* mimeData)
{
QString textEquivalent;
QString text;
......@@ -130,13 +130,11 @@ void NoteDrag::serializeText(NoteSelection *noteList, QDrag *multipleDrag)
textEquivalent += (!textEquivalent.isEmpty() ? "\n" : QString()) + text;
}
if (!textEquivalent.isEmpty()) {
QMimeData *mimeData = new QMimeData;
mimeData->setText(textEquivalent);
multipleDrag->setMimeData(mimeData);
}
}
void NoteDrag::serializeHtml(NoteSelection *noteList, QDrag *multipleDrag)
void NoteDrag::serializeHtml(NoteSelection *noteList, QMimeData* mimeData)
{
QString htmlEquivalent;
QString html;
......@@ -147,16 +145,15 @@ void NoteDrag::serializeHtml(NoteSelection *noteList, QDrag *multipleDrag)
}
if (!htmlEquivalent.isEmpty()) {
// Add HTML flavour:
QMimeData *mimeData = new QMimeData;
mimeData->setHtml(htmlEquivalent);
// But also QTextEdit flavour, to be able to paste several notes to a text edit:
QByteArray byteArray = ("<!--StartFragment--><p>" + htmlEquivalent).toLocal8Bit();
mimeData->setData("application/x-qrichtext", byteArray);
multipleDrag->setMimeData(mimeData);
}
}
void NoteDrag::serializeImage(NoteSelection *noteList, QDrag *multipleDrag)
void NoteDrag::serializeImage(NoteSelection *noteList, QMimeData* mimeData)
{
QList<QPixmap> pixmaps;
QPixmap pixmap;
......@@ -188,13 +185,11 @@ void NoteDrag::serializeImage(NoteSelection *noteList, QDrag *multipleDrag)
height += (*it).height();
}
}
QMimeData *mimeData = new QMimeData;
mimeData->setImageData(pixmapEquivalent.toImage());
multipleDrag->setMimeData(mimeData);
}
}
void NoteDrag::serializeLinks(NoteSelection *noteList, QDrag *multipleDrag, bool cutting)
void NoteDrag::serializeLinks(NoteSelection *noteList, QMimeData* mimeData, bool cutting)
{
QList<QUrl> urls;
QStringList titles;
......@@ -209,7 +204,6 @@ void NoteDrag::serializeLinks(NoteSelection *noteList, QDrag *multipleDrag, bool
}
if (!urls.isEmpty()) {
// First, the standard text/uri-list MIME format:
QMimeData *mimeData = new QMimeData;
mimeData->setUrls(urls);
// Then, also provide it in the Mozilla proprietary format (that also allow to add titles to URLs):
......@@ -240,7 +234,6 @@ void NoteDrag::serializeLinks(NoteSelection *noteList, QDrag *multipleDrag, bool
arrayCut[1] = 0;
mimeData->setData("application/x-kde-cutselection", arrayCut);
}
multipleDrag->setMimeData(mimeData);
}
}
......
......@@ -41,10 +41,10 @@ class NoteDrag
{
protected:
static void serializeNotes(NoteSelection *noteList, QDataStream &stream, bool cutting);
static void serializeText(NoteSelection *noteList, QDrag *multipleDrag);
static void serializeHtml(NoteSelection *noteList, QDrag *multipleDrag);
static void serializeImage(NoteSelection *noteList, QDrag *multipleDrag);
static void serializeLinks(NoteSelection *noteList, QDrag *multipleDrag, bool cutting);
static void serializeText(NoteSelection *noteList, QMimeData* mimeData);
static void serializeHtml(NoteSelection *noteList, QMimeData* mimeData);
static void serializeImage(NoteSelection *noteList, QMimeData* mimeData);
static void serializeLinks(NoteSelection *noteList, QMimeData* mimeData, bool cutting);
static void setFeedbackPixmap(NoteSelection *noteList, QDrag *multipleDrag);
static Note *decodeHierarchy(QDataStream &stream, BasketScene *parent, bool moveFiles, bool moveNotes, BasketScene *originalBasket);
......
......@@ -216,6 +216,13 @@ QList<State*> Tools::detectTags(const QString& text, int& prefixLength)
if (state) tagsDetected.append(state);
}
//if tags are found, eat possible trailing whitespaces as well
if (prefixLength)
{
prefixLength = text.indexOf(QRegularExpression("[^\\s]"), prefixLength);
if (prefixLength == -1)
prefixLength = text.length();
}
return tagsDetected;
}
......@@ -414,10 +421,10 @@ QString Tools::htmlToText(const QString &html)
QString Tools::textDocumentToMinimalHTML(QTextDocument *document)
{
QFont docFont = document->defaultFont();
QFont originalFont = document->defaultFont();
document->setDefaultFont(QFont());
QString docContent = document->toHtml("utf-8");
document->setDefaultFont(docFont);
document->setDefaultFont(originalFont);
//Tag styles appear in html output as body styles. Remove them to preserve internal formatting.
QRegularExpression patternBodyTag("<body.*?>");
......
......@@ -46,6 +46,8 @@ BASKET_EXPORT QString textToHTML(const QString &text);
BASKET_EXPORT QString textToHTMLWithoutP(const QString &text);
BASKET_EXPORT QString htmlToParagraph(const QString &html);
BASKET_EXPORT QString htmlToText(const QString &html);
//Discards styles of tags applied to the note
BASKET_EXPORT QString textDocumentToMinimalHTML(QTextDocument *document); //!< Avoid unneeded spans and style attributes
BASKET_EXPORT QString detectURLs(const QString &text);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment