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

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2020 Nikita Sirgienko <warquark@gmail.com>
0004 */
0005 
0006 #ifndef HIEARARCHYENTRY_H
0007 #define HIEARARCHYENTRY_H
0008 
0009 #include <QString>
0010 #include <QDomElement>
0011 #include <QDomDocument>
0012 #include <KZip>
0013 
0014 #include "worksheetentry.h"
0015 #include "worksheettextitem.h"
0016 
0017 class QActionGroup;
0018 class QMenu;
0019 
0020 class HierarchyEntry : public WorksheetEntry
0021 {
0022   Q_OBJECT
0023   public:
0024     // Should be plane and int: "1, 2, 3", but not "1, 2, 4"
0025     enum class HierarchyLevel {
0026         Chapter = 1,
0027         Subchapter = 2,
0028         Section = 3,
0029         Subsection = 4,
0030         Paragraph = 5,
0031         Subparagraph = 6,
0032 
0033         EndValue = 7
0034     };
0035 
0036     explicit HierarchyEntry(Worksheet* worksheet);
0037     ~HierarchyEntry() override;
0038 
0039     enum {Type = UserType + 9};
0040     int type() const override;
0041 
0042     QString text() const;
0043     QString hierarchyText() const;
0044 
0045     HierarchyLevel level() const;
0046     void setLevel(HierarchyLevel);
0047     int hierarchyNumber() const;
0048 
0049     void updateHierarchyLevel(std::vector<int>& currectNumbers);
0050     qreal hierarchyItemWidth();
0051 
0052     void updateControlElementForHierarchy(qreal responsibilityZoneYEnd, int maxHierarchyDepth, bool haveSubElements);
0053 
0054     bool isEmpty() override;
0055 
0056     bool acceptRichText() override;
0057 
0058     bool focusEntry(int pos = WorksheetTextItem::TopLeft, qreal xCoord=0) override;
0059 
0060     void setContent(const QString& content) override;
0061     void setContent(const QDomElement& content, const KZip& file) override;
0062     void setContentFromJupyter(const QJsonObject& cell) override;
0063     static bool isConvertableToHierarchyEntry(const QJsonObject& cell);
0064 
0065     QDomElement toXml(QDomDocument& doc, KZip* archive) override;
0066     QJsonValue toJupyterJson() override;
0067     QString toPlain(const QString& commandSep, const QString& commentStartingSeq, const QString& commentEndingSeq) override;
0068 
0069     void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) override;
0070 
0071     int searchText(const QString& text, const QString& pattern,
0072                    QTextDocument::FindFlags qt_flags);
0073     WorksheetCursor search(const QString& pattern, unsigned flags,
0074                            QTextDocument::FindFlags qt_flags,
0075                            const WorksheetCursor& pos = WorksheetCursor()) override;
0076 
0077     void startDrag(QPointF grabPos = QPointF()) override;
0078 
0079   Q_SIGNALS:
0080     void hierarhyEntryNameChange(QString name, QString searchName, int depth);
0081 
0082   public Q_SLOTS:
0083     bool evaluate(WorksheetEntry::EvaluationOption evalOp = FocusNext) override;
0084     void updateEntry() override;
0085     void populateMenu(QMenu* menu, QPointF pos) override;
0086     void handleControlElementDoubleClick();
0087     void updateAfterSettingsChanges() override;
0088 
0089   protected:
0090     bool wantToEvaluate() override;
0091     void recalculateControlGeometry() override;
0092 
0093   private Q_SLOTS:
0094     void setLevelTriggered(QAction*);
0095 
0096   private:
0097     void updateFonts(bool force = false);
0098 
0099   private:
0100 
0101     WorksheetTextItem* m_hierarchyLevelItem;
0102     WorksheetTextItem* m_textItem;
0103     HierarchyLevel m_depth;
0104     int m_hierarchyNumber;
0105     QActionGroup* m_setLevelActionGroup;
0106     QMenu* m_setLevelMenu;
0107     WorksheetEntry* m_hidedSubentries;
0108 };
0109 
0110 #endif // HIEARARCHYENTRY_H