1 /*
2     TikZiT - a GUI diagram editor for TikZ
3     Copyright (C) 2018 Aleks Kissinger
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 
19 /*!
20  * Displays a LaTeX-generated PDF preview using Poppler. The right-click
21  * menu has options for exporting to file or clipboard.
22  */
23 
24 #ifndef PREVIEWWINDOW_H
25 #define PREVIEWWINDOW_H
26 
27 #include "pdfdocument.h"
28 
29 #include <QDialog>
30 #include <QLabel>
31 #include <QPlainTextEdit>
32 #include <QContextMenuEvent>
33 #include <poppler/qt5/poppler-qt5.h>
34 
35 namespace Ui {
36 class PreviewWindow;
37 }
38 
39 class PreviewWindow : public QDialog
40 {
41     Q_OBJECT
42 
43 public:
44     enum Status {
45         Running, Success, Failed
46     };
47     explicit PreviewWindow(QWidget *parent = nullptr);
48     ~PreviewWindow() override;
49     void restorePosition();
50     void setPdf(QString file);
51     QString preparePreview(QString tikz);
52     QPlainTextEdit *outputTextEdit();
53     void setStatus(Status status);
54 
55     PdfDocument *doc() const;
56 
57 public slots:
58     void render();
59     void exportImage();
60     void copyImageToClipboard();
61 
62 protected:
63     void resizeEvent(QResizeEvent *e) override;
64     void showEvent(QShowEvent *e) override;
65     void closeEvent(QCloseEvent *e) override;
66     void contextMenuEvent(QContextMenuEvent *event) override;
67 private:
68     Ui::PreviewWindow *ui;
69     PdfDocument *_doc;
70     QLabel *_loader;
71     bool _positionRestored;
72 };
73 
74 #endif // PREVIEWWINDOW_H
75