Commit 299d4749 authored by Nikita Sirgienko's avatar Nikita Sirgienko
Browse files

Add populateMenu to MarkdownEntry

parent 97ffb4e7
......@@ -28,6 +28,7 @@ extern "C" {
}
#endif
#include <KLocalizedString>
#include <QDebug>
MarkdownEntry::MarkdownEntry(Worksheet* worksheet) : WorksheetEntry(worksheet), m_textItem(new WorksheetTextItem(this, Qt::TextEditorInteraction)), rendered(false)
......@@ -39,6 +40,36 @@ MarkdownEntry::MarkdownEntry(Worksheet* worksheet) : WorksheetEntry(worksheet),
connect(m_textItem, SIGNAL(execute()), this, SLOT(evaluate()));
}
void MarkdownEntry::populateMenu(QMenu* menu, QPointF pos)
{
bool imageSelected = false;
QTextCursor cursor = m_textItem->textCursor();
const QChar repl = QChar::ObjectReplacementCharacter;
if (cursor.hasSelection()) {
QString selection = m_textItem->textCursor().selectedText();
imageSelected = selection.contains(repl);
} else {
// we need to try both the current cursor and the one after the that
cursor = m_textItem->cursorForPosition(pos);
qDebug() << cursor.position();
for (int i = 2; i; --i) {
int p = cursor.position();
if (m_textItem->document()->characterAt(p-1) == repl &&
cursor.charFormat().hasProperty(EpsRenderer::CantorFormula)) {
m_textItem->setTextCursor(cursor);
imageSelected = true;
break;
}
cursor.movePosition(QTextCursor::NextCharacter);
}
}
if (imageSelected) {
menu->addAction(i18n("Show LaTeX code"), this, SLOT(resolveImagesAtCursor()));
menu->addSeparator();
}
WorksheetEntry::populateMenu(menu, pos);
}
bool MarkdownEntry::isEmpty()
{
return m_textItem->document()->isEmpty();
......
......@@ -57,6 +57,7 @@ class MarkdownEntry : public WorksheetEntry
public Q_SLOTS:
bool evaluate(WorksheetEntry::EvaluationOption evalOp = FocusNext) override;
void updateEntry() override;
void populateMenu(QMenu* menu, QPointF pos) override;
protected:
bool renderMarkdown(QString& plain);
......
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