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

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2020 Sirgienko Nikita <warquark@gmail.com>
0004 */
0005 
0006 #ifndef HORIZONTALLINEENTRY_H
0007 #define HORIZONTALLINEENTRY_H
0008 
0009 #include "worksheetentry.h"
0010 
0011 class HorizontalRuleEntry : public WorksheetEntry
0012 {
0013   public:
0014     enum LineType {Thin = 0, Medium = 1, Thick = 2, Count = 3};
0015 
0016     HorizontalRuleEntry(Worksheet* worksheet);
0017     ~HorizontalRuleEntry() override;
0018 
0019     enum {Type = UserType + 8};
0020     int type() const override;
0021 
0022     void setLineType(LineType type);
0023     void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
0024 
0025     static bool isConvertableToHorizontalRuleEntry(const QJsonObject& cell);
0026 
0027     bool isEmpty() override;
0028     bool acceptRichText() override;
0029     void setContent(const QString&) override;
0030     void setContent(const QDomElement&, const KZip&) override;
0031     void setContentFromJupyter(const QJsonObject & cell) override;
0032     QDomElement toXml(QDomDocument&, KZip*) override;
0033     QJsonValue toJupyterJson() override;
0034     QString toPlain(const QString&, const QString&, const QString&) override;
0035     void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) override;
0036     void populateMenu(QMenu* menu, QPointF pos) override;
0037 
0038   public Q_SLOTS:
0039     bool evaluate(WorksheetEntry::EvaluationOption evalOp = FocusNext) override;
0040     void updateEntry() override;
0041 
0042     void changeSize(QSizeF s);
0043 
0044   protected:
0045     bool wantToEvaluate() override;
0046 
0047   private:
0048     static int lineWidth(LineType type);
0049     void initMenus();
0050 
0051   private Q_SLOTS:
0052     void lineTypeChanged(QAction* action);
0053     void lineColorChanged(QAction* action);
0054     void lineStyleChanged(QAction* action);
0055 
0056   public:
0057     static const qreal LineVerticalMargin;
0058     static constexpr unsigned int styleCount = 5;
0059     static const QString styleNames[styleCount];
0060     static const Qt::PenStyle styles[styleCount];
0061 
0062   private:
0063     LineType m_type;
0064     QColor m_color;
0065     qreal m_entry_zone_offset_x;
0066     qreal m_width;
0067     Qt::PenStyle m_style;
0068 
0069     bool m_menusInitialized;
0070 
0071     QActionGroup* m_lineTypeActionGroup;
0072     QMenu* m_lineTypeMenu;
0073     bool m_lineColorCustom;
0074 
0075     QActionGroup* m_lineColorActionGroup;
0076     QMenu* m_lineColorMenu;
0077 
0078     QActionGroup* m_lineStyleActionGroup;
0079     QMenu* m_lineStyleMenu;
0080 };
0081 
0082 #endif //HORIZONTALLINEENTRY_H