| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef MESSAGEPREVIEWER_H |
| 4 | #define MESSAGEPREVIEWER_H |
| 5 | |
| 6 | #include "core/message.h" |
| 7 | #include "gui/tabcontent.h" |
| 8 | #include "services/abstract/label.h" |
| 9 | #include "services/abstract/rootitem.h" |
| 10 | |
| 11 | #include <QAction> |
| 12 | #include <QPointer> |
| 13 | #include <QToolButton> |
| 14 | #include <QUrl> |
| 15 | |
| 16 | class QGridLayout; |
| 17 | class QStackedLayout; |
| 18 | class QToolBar; |
| 19 | class WebBrowser; |
| 20 | class ItemDetails; |
| 21 | |
| 22 | class LabelToolbarAction : public QAction { |
| 23 | Q_OBJECT |
| 24 | |
| 25 | public: |
| 26 | explicit LabelToolbarAction(QObject* parent = nullptr); |
| 27 | |
| 28 | Label* label() const; |
| 29 | void setLabel(Label* label); |
| 30 | |
| 31 | private: |
| 32 | QPointer<Label> m_label; |
| 33 | }; |
| 34 | |
| 35 | class MessagePreviewer : public TabContent { |
| 36 | Q_OBJECT |
| 37 | |
| 38 | public: |
| 39 | explicit MessagePreviewer(QWidget* parent = nullptr); |
| 40 | virtual ~MessagePreviewer(); |
| 41 | |
| 42 | void reloadFontSettings(); |
| 43 | |
| 44 | virtual WebBrowser* webBrowser() const; |
| 45 | |
| 46 | public slots: |
| 47 | void setToolbarsVisible(bool visible); |
| 48 | void clear(); |
| 49 | |
| 50 | void showItemDetails(RootItem* item); |
| 51 | void loadUrl(const QString& url); |
| 52 | void loadMessage(const Message& message, RootItem* root); |
| 53 | |
| 54 | private slots: |
| 55 | void switchLabel(bool assign); |
| 56 | void markMessageAsRead(); |
| 57 | void markMessageAsUnread(); |
| 58 | void markMessageAsReadUnread(RootItem::ReadStatus read); |
| 59 | void switchMessageImportance(bool checked); |
| 60 | |
| 61 | signals: |
| 62 | void markMessageRead(int id, RootItem::ReadStatus read); |
| 63 | void markMessageImportant(int id, RootItem::Importance important); |
| 64 | void setMessageLabelIds(int id, const QStringList& ids); |
| 65 | |
| 66 | private: |
| 67 | void createConnections(); |
| 68 | void updateButtons(); |
| 69 | void updateLabels(bool only_clear); |
| 70 | |
| 71 | void ensureItemDetailsVisible(); |
| 72 | void ensureDefaultBrowserVisible(); |
| 73 | |
| 74 | QGridLayout* m_mainLayout; |
| 75 | QStackedLayout* m_viewerLayout; |
| 76 | QToolBar* m_toolBar; |
| 77 | WebBrowser* m_msgBrowser; |
| 78 | Message m_message; |
| 79 | QPointer<RootItem> m_root; |
| 80 | QAction* m_actionMarkRead; |
| 81 | QAction* m_actionMarkUnread; |
| 82 | QAction* m_actionSwitchImportance; |
| 83 | QAction* m_separator; |
| 84 | QList<LabelToolbarAction*> m_btnLabels; |
| 85 | ItemDetails* m_itemDetails; |
| 86 | bool m_toolbarVisible; |
| 87 | |
| 88 | static const int INDEX_DEFAULT = 0; |
| 89 | static const int INDEX_ITEMS = 1; |
| 90 | static const int INDEX_CUSTOM = 2; |
| 91 | }; |
| 92 | |
| 93 | #endif // MESSAGEPREVIEWER_H |