File indexing completed on 2024-04-28 05:08:20

0001 /***************************************************************************
0002     Copyright (C) 2003-2020 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #ifndef TELLICO_ENTRYVIEW_H
0026 #define TELLICO_ENTRYVIEW_H
0027 
0028 #include "datavectors.h"
0029 
0030 #ifdef USE_KHTML
0031 #include <KHTMLPart>
0032 #include <KHTMLView>
0033 #else
0034 #include <QWebEngineView>
0035 #include <QWebEnginePage>
0036 #include <QPrinter>
0037 #endif
0038 
0039 class QTemporaryFile;
0040 
0041 namespace Tellico {
0042   class XSLTHandler;
0043   class ImageFactory;
0044   class StyleOptions;
0045 
0046 /**
0047  * @author Robby Stephenson
0048  */
0049 class EntryView : public
0050 #ifdef USE_KHTML
0051   KHTMLPart {
0052 #else
0053   QWebEngineView {
0054 #endif
0055 
0056 Q_OBJECT
0057 
0058 public:
0059   /**
0060    * The EntryView shows a HTML representation of the data in the entry.
0061    *
0062    * @param parent QWidget parent
0063    */
0064   EntryView(QWidget* parent);
0065   /**
0066    */
0067   virtual ~EntryView();
0068 
0069   /**
0070    * Uses the xslt handler to convert an entry to html, and then writes that html to the view
0071    *
0072    * @param entry The entry to show
0073    */
0074   void showEntry(Data::EntryPtr entry);
0075   void showText(const QString& text);
0076 
0077   /**
0078    * Clear the widget and set Entry pointer to NULL
0079    */
0080   void clear();
0081   /**
0082    * Sets the XSLT file. If the file name does not start with a back-slash, then the
0083    * standard directories are searched.
0084    *
0085    * @param file The XSLT file name
0086    */
0087   void setXSLTFile(const QString& file);
0088   void addXSLTStringParam(const QByteArray& name, const QByteArray& value);
0089   void setXSLTOptions(const StyleOptions& options);
0090   void setUseGradientImages(bool b) { m_useGradientImages = b; }
0091   void resetView();
0092 
0093 Q_SIGNALS:
0094   void signalTellicoAction(const QUrl& url);
0095 
0096 public Q_SLOTS:
0097   void copy();
0098   /**
0099    * Helper function to refresh view.
0100    */
0101   void slotRefresh();
0102   void showEntries(Tellico::Data::EntryList entries);
0103 
0104 private Q_SLOTS:
0105   /**
0106    * Open a URL.
0107    *
0108    * @param url The URL to open
0109    */
0110   void slotOpenURL(const QUrl& url);
0111   void slotReloadEntry();
0112 
0113 protected:
0114 #ifdef USE_KHTML
0115   void changeEvent(QEvent* event);
0116 #else
0117   void changeEvent(QEvent* event) Q_DECL_OVERRIDE;
0118 #endif
0119 
0120 private Q_SLOTS:
0121   void slotPrint();
0122 
0123 private:
0124   void resetColors();
0125 #ifdef USE_KHTML
0126   void contextMenuEvent(QContextMenuEvent* event);
0127 #else
0128   void contextMenuEvent(QContextMenuEvent* event) Q_DECL_OVERRIDE;
0129 #endif
0130 
0131   Data::EntryPtr m_entry;
0132   XSLTHandler* m_handler;
0133   QString m_xsltFile;
0134   QString m_textToShow;
0135 
0136   QTemporaryFile* m_tempFile;
0137   bool m_useGradientImages;
0138   bool m_checkCommonFile;
0139 #ifndef USE_KHTML
0140   QPrinter m_printer;
0141 #endif
0142 };
0143 
0144 #ifdef USE_KHTML
0145 class EntryViewWidget : public KHTMLView {
0146 Q_OBJECT
0147 public:
0148   EntryViewWidget(EntryView* part, QWidget* parent);
0149 
0150 public Q_SLOTS:
0151   void copy();
0152 
0153 protected:
0154   void changeEvent(QEvent* event) Q_DECL_OVERRIDE;
0155 };
0156 #else
0157 class EntryViewPage : public QWebEnginePage {
0158 Q_OBJECT
0159 public:
0160   EntryViewPage(QWidget* parent);
0161 
0162 Q_SIGNALS:
0163   void signalTellicoAction(const QUrl& url);
0164 
0165 protected:
0166   virtual bool acceptNavigationRequest(const QUrl& url, QWebEnginePage::NavigationType type, bool isMainFrame) Q_DECL_OVERRIDE;
0167   virtual QWebEnginePage* createWindow(QWebEnginePage::WebWindowType type) Q_DECL_OVERRIDE;
0168 
0169 private:
0170   void openExternalLink(const QUrl& url);
0171 };
0172 #endif
0173 
0174 } //end namespace
0175 #endif