Commit b06230b6 authored by Nikita Sirgienko's avatar Nikita Sirgienko
Browse files

Temporarily Revert "[Jupyter] Support `img` tag with `scr`attibute, pointed to...

Temporarily Revert "[Jupyter] Support `img` tag with `scr`attibute, pointed to web sites, in MarkdownEntry" because it don't work on Windows (for unknown reason)

This reverts commit d09fac4d.
parent 00f66900
......@@ -23,7 +23,6 @@ find_package(Qt5 5.8.0 CONFIG REQUIRED
Svg
Xml
XmlPatterns
Network
Test)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED
......
......@@ -78,7 +78,6 @@ set(cantor_PART_SRCS
animation.cpp
mathrender.cpp
mathrendertask.cpp
extended_document.cpp
worksheetcontrolitem.cpp
)
......
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2019 Sirgienko Nikita <warquark@gmail.com>
*/
#include "extended_document.h"
#include "worksheettextitem.h"
QNetworkAccessManager ExtendedDocument::networkManager;
ExtendedDocument::ExtendedDocument(QObject *parent): QTextDocument(parent)
{
}
void ExtendedDocument::handleLoad(QNetworkReply* reply)
{
const QUrl& requestUrl = reply->request().url();
if (loading.contains(requestUrl))
{
if (reply->error() == QNetworkReply::NoError)
{
QImage img;
img.loadFromData(reply->readAll());
if (!img.isNull())
{
this->addResource(QTextDocument::ImageResource, reply->request().url(), QVariant(img));
// TODO: find another way to redraw document
QTextCursor cursor(this);
cursor.movePosition(QTextCursor::End);
cursor.insertText(QLatin1String("\n"));
cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
cursor.removeSelectedText();
}
else
qDebug() << "content of url" << requestUrl << "not a image";
}
else
{
qDebug() << "loading image in document from" << requestUrl << "failed with error: " << reply->errorString();
}
loading.removeOne(requestUrl);
if (loading.size() == 0)
disconnect(&networkManager, &QNetworkAccessManager::finished, this, &ExtendedDocument::handleLoad);
}
}
QVariant ExtendedDocument::loadResource(int type, const QUrl &name)
{
if (type == QTextDocument::ImageResource && (name.scheme() == QLatin1String("http") || name.scheme() == QLatin1String("https")))
{
if (!loading.contains(name))
{
if (loading.size() == 0)
connect(&networkManager, &QNetworkAccessManager::finished, this, &ExtendedDocument::handleLoad);
QNetworkRequest request(name);
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
networkManager.get(request);
loading << name;
}
return QVariant();
}
else
return QTextDocument::loadResource(type, name);
}
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2019 Sirgienko Nikita <warquark@gmail.com>
*/
#ifndef EXTENDEDDOCUMENT_H
#define EXTENDEDDOCUMENT_H
#include <QTextDocument>
#include <QDebug>
#include <QNetworkReply>
#include <QImage>
#include <QList>
#include <QGraphicsTextItem>
#include <QTextCursor>
/**
* Additional class with one purpose - expand QTextDocument and
* allow Image Resources from web (http and https urls)
*/
class ExtendedDocument : public QTextDocument
{
public:
ExtendedDocument(QObject *parent = nullptr);
protected:
QVariant loadResource(int type, const QUrl &name) override;
private Q_SLOTS:
void handleLoad(QNetworkReply *reply);
private:
QList<QUrl> loading; // List of currently loaded urls
static QNetworkAccessManager networkManager;
};
#endif /* EXTENDEDDOCUMENT_H */
......@@ -25,7 +25,6 @@ set(worksheettest_SRCS
../animation.cpp
../mathrender.cpp
../mathrendertask.cpp
../extended_document.cpp
../worksheetcontrolitem.cpp
worksheet_test.cpp)
......
......@@ -23,7 +23,6 @@
#include "worksheetentry.h"
#include "lib/renderer.h"
#include "worksheetcursor.h"
#include "extended_document.h"
#include <QApplication>
#include <QClipboard>
......@@ -46,7 +45,6 @@
WorksheetTextItem::WorksheetTextItem(QGraphicsObject* parent, Qt::TextInteractionFlags ti)
: QGraphicsTextItem(parent)
{
setDocument(new ExtendedDocument(this));
setTextInteractionFlags(ti);
if (ti & Qt::TextEditable) {
setCursor(Qt::IBeamCursor);
......
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