presentation/ComposePreview.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QObject> | ||
| 4 | #include <QPointer> | ||
| 5 | #include <QSharedPointer> | ||
| 6 | #include <QString> | ||
| 7 | #include <QTextDocument> | ||
| 8 | #include <QTextDocumentFragment> | ||
| 9 | #include <atomic> | ||
| 10 | |||
| 11 | // Sprint 108 §4.14 (D-27): *⋯ › Preview* — the message as the outbox would | ||
| 12 | // build it (formatted HTML with the hidden quote of a reply, and the plain | ||
| 13 | // part), without sending. The HTML goes through MailJD's own reader | ||
| 14 | // preparation (NativeMailDocument, Reader mode) on a worker, so the preview | ||
| 15 | // shows what MailJD's reader would show; images appear as their | ||
| 16 | // descriptions. The prepared fragment is placed into the frame's document | ||
| 17 | // from C++, so no foreign HTML reaches a QML rich-text binding. Read-only; | ||
| 18 | // one preview at a time. | ||
| 19 | class ComposePreview : public QObject { | ||
| 20 | 4 | Q_OBJECT | |
| 21 | Q_PROPERTY(bool ready READ ready NOTIFY changed) | ||
| 22 | Q_PROPERTY(bool formatted READ formatted NOTIFY changed) | ||
| 23 | Q_PROPERTY(QString plainText READ plainText NOTIFY changed) | ||
| 24 | Q_PROPERTY(QString subject READ subject NOTIFY changed) | ||
| 25 | Q_PROPERTY(QString recipients READ recipients NOTIFY changed) | ||
| 26 | Q_PROPERTY(QString notice READ notice NOTIFY changed) | ||
| 27 | |||
| 28 | public: | ||
| 29 | 795 | explicit ComposePreview(QObject *parent = nullptr) : QObject(parent) {} | |
| 30 | |||
| 31 | 501 | bool ready() const { return m_ready; } | |
| 32 | 325 | bool formatted() const { return m_formatted; } | |
| 33 | 160 | QString plainText() const { return m_plainText; } | |
| 34 | 160 | QString subject() const { return m_subject; } | |
| 35 | 159 | QString recipients() const { return m_recipients; } | |
| 36 | 159 | QString notice() const { return m_notice; } | |
| 37 | |||
| 38 | // Builds the preview of a ComposeSession; `changed` reports it ready. | ||
| 39 | Q_INVOKABLE void build(QObject *session); | ||
| 40 | Q_INVOKABLE void clear(); | ||
| 41 | // The light/dark frames' TextEdit passes its textDocument: the prepared | ||
| 42 | // document goes into it as a fragment (no rich text through QML). | ||
| 43 | Q_INVOKABLE void attachDocument(QObject *quickTextDocument); | ||
| 44 | // The prepared document as plain text (tests, accessibility). | ||
| 45 | Q_INVOKABLE QString renderedText() const; | ||
| 46 | |||
| 47 | signals: | ||
| 48 | void changed(); | ||
| 49 | |||
| 50 | private: | ||
| 51 | bool m_ready = false; | ||
| 52 | bool m_formatted = false; | ||
| 53 | QSharedPointer<const QTextDocumentFragment> m_fragment; | ||
| 54 | QPointer<QTextDocument> m_target; | ||
| 55 | void fill(); | ||
| 56 | QString m_plainText; | ||
| 57 | QString m_subject; | ||
| 58 | QString m_recipients; | ||
| 59 | QString m_notice; | ||
| 60 | std::atomic<quint64> m_generation{0}; | ||
| 61 | }; | ||
| 62 |