Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/markdownentry.cpp b/src/markdownentry.cpp
- index f0ba5afb..bf9b0fe1 100644
- --- a/src/markdownentry.cpp
- +++ b/src/markdownentry.cpp
- @@ -30,6 +30,8 @@
- #include <QDebug>
- #include <QStandardPaths>
- #include <QDir>
- +#include <QFileDialog>
- +#include <KMessageBox>
- #include "jupyterutils.h"
- #include "mathrender.h"
- @@ -78,6 +80,8 @@ void MarkdownEntry::populateMenu(QMenu* menu, QPointF pos)
- menu->addAction(i18n("Show LaTeX code"), this, &MarkdownEntry::resolveImagesAtCursor);
- menu->addSeparator();
- }
- + menu->addAction(i18n("Add attachment"), this, &MarkdownEntry::addAttachment);
- + menu->addAction(i18n("Clear attachments"), this, &MarkdownEntry::clearAttachments);
- WorksheetEntry::populateMenu(menu, pos);
- }
- @@ -626,3 +630,35 @@ void MarkdownEntry::markUpMath()
- cursor.setCharFormat(format);
- }
- }
- +
- +void MarkdownEntry::addAttachment()
- +{
- + const QString& filename = QFileDialog::getOpenFileName(worksheet()->worksheetView(), i18n("Choose Image"), QString(), i18n("Images (*.png *.bmp *.jpg *.svg)"));
- + if (!filename.isEmpty())
- + {
- + QImageReader reader(filename);
- + const QImage img = reader.read();
- + if (!img.isNull())
- + {
- + QFileInfo info(filename);
- +
- + QUrl url;
- + url.setScheme(QLatin1String("internal"));
- + url.setPath(info.fileName());
- +
- + m_textItem->document()->addResource(QTextDocument::ImageResource, url, QVariant(img));
- + }
- + else
- + KMessageBox::error(worksheetView(), i18n("Cantor failed to read image with error \"%1\"", reader.errorString()), i18n("Cantor"));
- + }
- +}
- +
- +void MarkdownEntry::clearAttachments()
- +{
- + for (auto& attachment: attachedImages)
- + {
- + const QUrl& url = attachment.first;
- + m_textItem->document()->addResource(QTextDocument::ImageResource, url, QVariant());
- + }
- + attachedImages.clear();
- +}
- diff --git a/src/markdownentry.h b/src/markdownentry.h
- index c121e3b3..b2421a36 100644
- --- a/src/markdownentry.h
- +++ b/src/markdownentry.h
- @@ -87,6 +87,8 @@ class MarkdownEntry : public WorksheetEntry
- protected Q_SLOTS:
- void handleMathRender(QSharedPointer<MathRenderResult> result);
- + void addAttachment();
- + void clearAttachments();
- protected:
- WorksheetTextItem* m_textItem;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement