File indexing completed on 2024-04-28 05:11:01
0001 /* 0002 This file is part of Akregator. 0003 0004 SPDX-FileCopyrightText: 2004 Teemu Rytilahti <tpr@d5k.net> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0007 */ 0008 0009 #pragma once 0010 0011 #include "akregator_export.h" 0012 #include "article.h" 0013 #include "articlematcher.h" 0014 0015 #include <QWidget> 0016 0017 #include <QPointer> 0018 0019 #include <QSharedPointer> 0020 #include <QUrl> 0021 #include <vector> 0022 0023 class KJob; 0024 class KActionCollection; 0025 0026 namespace Akregator 0027 { 0028 0029 class ArticleFormatter; 0030 class ArticleListJob; 0031 class OpenUrlRequest; 0032 class TreeNode; 0033 class ArticleHtmlWebEngineWriter; 0034 class ArticleViewerWebEngineWidgetNg; 0035 0036 class AKREGATOR_EXPORT ArticleViewerWidget : public QWidget 0037 { 0038 Q_OBJECT 0039 public: 0040 explicit ArticleViewerWidget(const QString &grantleeDirectory, KActionCollection *ac, QWidget *parent); 0041 ~ArticleViewerWidget() override; 0042 0043 /** Repaints the view. */ 0044 void reload(); 0045 0046 void displayAboutPage(); 0047 0048 void showArticle(const Article &article); 0049 0050 /** Shows the articles of the tree node @c node (combined view). 0051 * Changes in the node will update the view automatically. 0052 * 0053 * @param node The node to observe */ 0054 void showNode(Akregator::TreeNode *node); 0055 0056 [[nodiscard]] QSize sizeHint() const override; 0057 0058 [[nodiscard]] qreal zoomFactor() const; 0059 0060 Akregator::ArticleViewerWebEngineWidgetNg *articleViewerWidgetNg() const; 0061 0062 void updateAfterConfigChanged(); 0063 0064 public Q_SLOTS: 0065 void slotPrint(); 0066 0067 /** Set filters which will be used if the viewer is in combined view mode 0068 */ 0069 void setFilters(const std::vector<QSharedPointer<const Akregator::Filters::AbstractMatcher>> &filters); 0070 0071 /** Update view if combined view mode is set. Has to be called when 0072 * the displayed node gets modified. 0073 */ 0074 void slotUpdateCombinedView(); 0075 0076 /** 0077 * Clears the canvas and disconnects from the currently observed node 0078 * (if in combined view mode). 0079 */ 0080 void slotClear(); 0081 0082 void slotShowSummary(Akregator::TreeNode *node); 0083 0084 void slotPrintPreview(); 0085 void slotCopy(); 0086 0087 void slotZoomChangeInFrame(qreal value); 0088 Q_SIGNALS: 0089 0090 /** This gets emitted when url gets clicked */ 0091 void signalOpenUrlRequest(Akregator::OpenUrlRequest &); 0092 void showStatusBarMessage(const QString &msg); 0093 0094 void selectionChanged(); 0095 0096 protected: // methods 0097 bool openUrl(const QUrl &url); 0098 0099 protected Q_SLOTS: 0100 void slotSelectionChanged(); 0101 0102 void slotArticlesListed(KJob *job); 0103 0104 void slotArticlesUpdated(Akregator::TreeNode *node, const QList<Akregator::Article> &list); 0105 void slotArticlesAdded(Akregator::TreeNode *node, const QList<Akregator::Article> &list); 0106 void slotArticlesRemoved(Akregator::TreeNode *node, const QList<Akregator::Article> &list); 0107 0108 // from ArticleViewer 0109 private: 0110 QSharedPointer<ArticleFormatter> combinedViewFormatter(); 0111 QSharedPointer<ArticleFormatter> normalViewFormatter(); 0112 void keyPressEvent(QKeyEvent *e) override; 0113 0114 /** renders @c body. Use this method wherever possible. 0115 * @param body html to render, without header and footer */ 0116 void renderContent(const QString &body); 0117 0118 /** Resets the canvas and adds writes the HTML header to it. 0119 */ 0120 void beginWriting(); 0121 0122 /** Finishes writing to the canvas and completes the HTML (by adding closing tags) */ 0123 void endWriting(); 0124 0125 void connectToNode(TreeNode *node); 0126 void disconnectFromNode(TreeNode *node); 0127 0128 void setArticleActionsEnabled(bool enabled); 0129 0130 private: 0131 QString m_currentText; 0132 QPointer<TreeNode> m_node; 0133 QPointer<ArticleListJob> m_listJob; 0134 Article m_article; 0135 QList<Article> m_articles; 0136 QUrl m_link; 0137 std::vector<QSharedPointer<const Filters::AbstractMatcher>> m_filters; 0138 enum ViewMode { NormalView, CombinedView, SummaryView }; 0139 ViewMode m_viewMode = NormalView; 0140 Akregator::ArticleHtmlWebEngineWriter *m_articleHtmlWriter = nullptr; 0141 Akregator::ArticleViewerWebEngineWidgetNg *const m_articleViewerWidgetNg; 0142 QSharedPointer<ArticleFormatter> m_normalViewFormatter; 0143 QSharedPointer<ArticleFormatter> m_combinedViewFormatter; 0144 const QString m_grantleeDirectory; 0145 }; 0146 } // namespace Akregator