File indexing completed on 2022-12-06 18:50:19

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
0004     SPDX-FileCopyrightText: 2012 Martin Kuettler <martin.kuettler@gmail.com>
0005 */
0006 
0007 #ifndef LATEXENTRY_H
0008 #define LATEXENTRY_H
0009 
0010 #include "worksheetentry.h"
0011 #include "worksheettextitem.h"
0012 
0013 class LatexEntry : public WorksheetEntry
0014 {
0015   Q_OBJECT
0016 
0017   public:
0018     explicit LatexEntry(Worksheet* worksheet);
0019     ~LatexEntry() override = default;
0020 
0021     enum {Type = UserType + 5};
0022     int type() const override;
0023 
0024     bool isEmpty() override;
0025 
0026     QString plain() const;
0027 
0028     bool acceptRichText() override;
0029 
0030     bool focusEntry(int pos = WorksheetTextItem::TopLeft, qreal xCoord = 0) override;
0031 
0032     void setContent(const QString& content) override;
0033     void setContent(const QDomElement& content, const KZip& file) override;
0034     void setContentFromJupyter(const QJsonObject & cell) override;
0035     static bool isConvertableToLatexEntry(const QJsonObject& cell);
0036 
0037     QDomElement toXml(QDomDocument& doc, KZip* archive) override;
0038     QJsonValue toJupyterJson() override;
0039     QString toPlain(const QString& commandSep, const QString& commentStartingSeq, const QString& commentEndingSeq) override;
0040 
0041     void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) override;
0042 
0043     int searchText(const QString& text, const QString& pattern,
0044                    QTextDocument::FindFlags qt_flags);
0045     WorksheetCursor search(const QString& pattern, unsigned flags,
0046                            QTextDocument::FindFlags qt_flags,
0047                            const WorksheetCursor& pos = WorksheetCursor()) override;
0048 
0049   public Q_SLOTS:
0050     bool evaluate(WorksheetEntry::EvaluationOption evalOp = FocusNext) override;
0051     void resolveImagesAtCursor();
0052     void updateEntry() override;
0053     void populateMenu(QMenu* menu, QPointF pos) override;
0054 
0055   protected:
0056     bool wantToEvaluate() override;
0057     bool eventFilter(QObject* object, QEvent* event) override;
0058 
0059   private:
0060     QString latexCode();
0061     bool renderLatexCode();
0062     bool isOneImageOnly();
0063 
0064   private:
0065     WorksheetTextItem* m_textItem;
0066     QTextImageFormat m_renderedFormat;
0067     QString m_latex;
0068 };
0069 
0070 #endif // LATEXENTRY_H