2023-01-26 17:31:16 +00:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
|
|
|
|
#ifndef PDFVIEWER_H
|
|
|
|
#define PDFVIEWER_H
|
|
|
|
|
2023-03-23 15:25:43 +00:00
|
|
|
#include "viewerinterfaces.h"
|
2023-01-26 17:31:16 +00:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
|
|
|
Q_DECLARE_LOGGING_CATEGORY(lcExample)
|
|
|
|
|
|
|
|
class QMainWindow;
|
|
|
|
class QPdfDocument;
|
|
|
|
class QPdfView;
|
|
|
|
class QPdfPageSelector;
|
|
|
|
class QListView;
|
|
|
|
class QTabWidget;
|
|
|
|
class QTreeView;
|
|
|
|
class ZoomSelector;
|
2023-03-23 15:25:43 +00:00
|
|
|
class PdfViewer : public ViewerInterface
|
2023-01-26 17:31:16 +00:00
|
|
|
{
|
2023-03-23 15:25:43 +00:00
|
|
|
Q_OBJECT
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Examples.DocumentViewer.ViewerInterface" FILE "pdfviewer.json")
|
|
|
|
Q_INTERFACES(ViewerInterface)
|
2023-01-26 17:31:16 +00:00
|
|
|
public:
|
|
|
|
~PdfViewer() override;
|
2023-03-23 15:25:43 +00:00
|
|
|
void init(QFile *file, QWidget *parent, QMainWindow *mainWindow) override;
|
2023-01-26 17:31:16 +00:00
|
|
|
QString viewerName() const override { return staticMetaObject.className(); };
|
2023-03-23 15:25:43 +00:00
|
|
|
QStringList supportedMimeTypes() const override;
|
2023-01-26 17:31:16 +00:00
|
|
|
bool supportsOverview() const override { return true; }
|
|
|
|
bool hasContent() const override;
|
|
|
|
QByteArray saveState() const override { return QByteArray(); }
|
|
|
|
bool restoreState(QByteArray &) override { return true; }
|
|
|
|
|
2023-03-23 15:25:43 +00:00
|
|
|
#ifdef QT_DOCUMENTVIEWER_PRINTSUPPORT
|
2023-01-26 17:31:16 +00:00
|
|
|
protected:
|
|
|
|
void printDocument(QPrinter *printer) const override;
|
2023-03-23 15:25:43 +00:00
|
|
|
#endif // QT_DOCUMENTVIEWER_PRINTSUPPORT
|
2023-01-26 17:31:16 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void openPdfFile();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initPdfViewer();
|
|
|
|
void bookmarkSelected(const QModelIndex &index);
|
|
|
|
void pageSelected(int page);
|
|
|
|
|
|
|
|
// action handlers
|
|
|
|
void onActionOpenTriggered();
|
|
|
|
void onActionQuitTriggered();
|
|
|
|
void onActionZoomInTriggered();
|
|
|
|
void onActionZoomOutTriggered();
|
|
|
|
void onActionPreviousPageTriggered();
|
|
|
|
void onActionNextPageTriggered();
|
|
|
|
void onActionBackTriggered();
|
|
|
|
void onActionForwardTriggered();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void populateQuestions();
|
|
|
|
|
|
|
|
const qreal zoomMultiplier = qSqrt(2.0);
|
|
|
|
static constexpr int maxIconWidth = 200;
|
|
|
|
QToolBar *m_toolBar = nullptr;
|
2023-03-23 15:25:43 +00:00
|
|
|
ZoomSelector *m_zoomSelector = nullptr;
|
|
|
|
QPdfPageSelector *m_pageSelector = nullptr;
|
|
|
|
QPdfDocument *m_document = nullptr;
|
|
|
|
QPdfView *m_pdfView = nullptr;
|
2023-01-26 17:31:16 +00:00
|
|
|
QAction *m_actionForward = nullptr;
|
|
|
|
QAction *m_actionBack = nullptr;
|
|
|
|
QTreeView *m_bookmarks = nullptr;
|
|
|
|
QListView *m_pages = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //PDFVIEWER_H
|