File indexing completed on 2024-06-23 05:03:09

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGPRINTPLUGIN_H
0007 #define SKGPRINTPLUGIN_H
0008 /** @file
0009  * A plugin to print pages.
0010 *
0011 * @author Stephane MANKOWSKI
0012  */
0013 #include <qprinter.h>
0014 #ifdef SKG_WEBENGINE
0015 #include <qwebengineview.h>
0016 #endif
0017 #ifdef SKG_WEBKIT
0018 #include <qwebframe.h>
0019 #include <qwebview.h>
0020 #endif
0021 #if !defined(SKG_WEBENGINE) && !defined(SKG_WEBKIT)
0022 #include <qtextbrowser.h>
0023 #endif
0024 
0025 #include "skginterfaceplugin.h"
0026 #include "ui_skgprintpluginwidget_pref.h"
0027 
0028 /**
0029  * A plugin to print pages
0030  */
0031 class SKGPrintPlugin : public SKGInterfacePlugin
0032 {
0033     Q_OBJECT
0034     Q_INTERFACES(SKGInterfacePlugin)
0035 
0036 public:
0037     /**
0038      * Default Constructor
0039      */
0040     explicit SKGPrintPlugin(QWidget* iWidget, QObject* iParent, const QVariantList& iArg);
0041 
0042     /**
0043      * Default Destructor
0044      */
0045     ~SKGPrintPlugin() override;
0046 
0047     /**
0048      * Called to initialise the plugin
0049      * @param iDocument the main document
0050      * @return true if the plugin is compatible with the document
0051      */
0052     bool setupActions(SKGDocument* iDocument) override;
0053 
0054     /**
0055      * The preference skeleton of the plugin.
0056      * @return The preference skeleton of the plugin
0057      */
0058     KConfigSkeleton* getPreferenceSkeleton() override;
0059 
0060     /**
0061      * The title of the plugin.
0062      * @return The title of the plugin
0063      */
0064     QString title() const override;
0065 
0066     /**
0067      * The tips list of the plugin.
0068      * @return The tips list of the plugin
0069      */
0070     QStringList tips() const override;
0071 
0072     /**
0073      * Must be implemented to set the position of the plugin.
0074      * @return integer value between 0 and 999 (default = 999)
0075      */
0076     int getOrder() const override;
0077 
0078 private Q_SLOTS:
0079     void onPrint();
0080     void onPrintPreview();
0081     void onPrintHtml();
0082     void print(QPrinter* iPrinter);
0083 
0084 private:
0085     Q_DISABLE_COPY(SKGPrintPlugin)
0086 
0087     SKGError getHtml(QPrinter* iPrinter, QString& oHtml) const;
0088 
0089     SKGDocument* m_currentDocument;
0090     QPrinter m_printer;
0091 #ifdef SKG_WEBENGINE
0092     QWebEngineView m_toPrint;
0093 #endif
0094 #ifdef SKG_WEBKIT
0095     QWebView m_toPrint;
0096 #endif
0097 #if !defined(SKG_WEBENGINE) && !defined(SKG_WEBKIT)
0098     QTextEdit m_toPrint;
0099 #endif
0100     Ui::skgprintplugin_pref ui {};
0101 };
0102 
0103 #endif  // SKGPRINTPLUGIN_H