| 1 | #pragma once |
| 2 | |
| 3 | // Qt |
| 4 | #include <QObject> // Required for inheritance |
| 5 | #include <QTextObjectInterface> // Required for inheritance |
| 6 | |
| 7 | class QSyntaxStyle; |
| 8 | |
| 9 | /** |
| 10 | * @brief Class, that describes |
| 11 | * attribute for making text frame. |
| 12 | */ |
| 13 | class QFramedTextAttribute : public QObject, |
| 14 | public QTextObjectInterface |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | Q_INTERFACES(QTextObjectInterface) |
| 18 | |
| 19 | public: |
| 20 | |
| 21 | enum Property |
| 22 | { |
| 23 | FramedString = 1 |
| 24 | }; |
| 25 | |
| 26 | /** |
| 27 | * @brief Static method for getting framed text |
| 28 | * attribute type. |
| 29 | */ |
| 30 | static int type(); |
| 31 | |
| 32 | /** |
| 33 | * @brief Constructor. |
| 34 | * @param parent Pointer to parent QObject. |
| 35 | */ |
| 36 | explicit QFramedTextAttribute(QObject* parent=nullptr); |
| 37 | |
| 38 | // Disable copying |
| 39 | QFramedTextAttribute(const QFramedTextAttribute&) = delete; |
| 40 | QFramedTextAttribute& operator=(const QFramedTextAttribute&) = delete; |
| 41 | |
| 42 | /** |
| 43 | * @brief Method for getting custom element (frame) |
| 44 | * size. Though frame symbol has no size, this |
| 45 | * method returns {0, 0} |
| 46 | */ |
| 47 | QSizeF intrinsicSize(QTextDocument *doc, |
| 48 | int posInDocument, |
| 49 | const QTextFormat &format) override; |
| 50 | |
| 51 | /** |
| 52 | * @brief Method for drawing frame. |
| 53 | */ |
| 54 | void drawObject(QPainter *painter, |
| 55 | const QRectF &rect, |
| 56 | QTextDocument *doc, |
| 57 | int posInDocument, |
| 58 | const QTextFormat &format) override; |
| 59 | |
| 60 | /** |
| 61 | * @brief Method for creating frame in cursor |
| 62 | * selection. |
| 63 | * @param cursor Cursor. |
| 64 | */ |
| 65 | void frame(QTextCursor cursor); |
| 66 | |
| 67 | /** |
| 68 | * @brief Method for clearing all frames |
| 69 | * with desired cursor. |
| 70 | */ |
| 71 | void clear(QTextCursor cursor); |
| 72 | |
| 73 | /** |
| 74 | * @brief Method for setting syntax style |
| 75 | * for rendering. |
| 76 | */ |
| 77 | void setSyntaxStyle(QSyntaxStyle* style); |
| 78 | |
| 79 | /** |
| 80 | * @brief Method for getting syntax style. |
| 81 | */ |
| 82 | QSyntaxStyle* syntaxStyle() const; |
| 83 | |
| 84 | private: |
| 85 | |
| 86 | QSyntaxStyle* m_style; |
| 87 | }; |
| 88 |