File indexing completed on 2025-03-09 04:54:41

0001 /*
0002   SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "messageviewer_export.h"
0010 
0011 #include <QEventLoop>
0012 #include <QObject>
0013 #include <QPrinter>
0014 
0015 class QWebEngineView;
0016 namespace MessageViewer
0017 {
0018 class MESSAGEVIEWER_EXPORT PrintMessage : public QObject
0019 {
0020     Q_OBJECT
0021 public:
0022     explicit PrintMessage(QObject *parent = nullptr);
0023     ~PrintMessage() override;
0024 
0025     void setView(QWebEngineView *view);
0026     void setDocumentName(const QString &name);
0027 
0028     void print();
0029     void printPreview();
0030 
0031     [[nodiscard]] QString documentName() const;
0032 
0033     [[nodiscard]] QWidget *parentWidget() const;
0034     void setParentWidget(QWidget *newParentWidget);
0035 
0036 Q_SIGNALS:
0037     void printingFinished();
0038 
0039 private:
0040     void printDocument(QPrinter *printer);
0041     void printFinished(bool success);
0042     QString mDocumentName;
0043     QPrinter mPrinter;
0044     QEventLoop mWaitForResult;
0045     QWidget *mParentWidget = nullptr;
0046     QWebEngineView *mView = nullptr;
0047     bool mInPrintPreview = false;
0048 };
0049 }