diff options
Diffstat (limited to 'examples/widgets/pdfviewer/mainwindow.cpp')
-rw-r--r-- | examples/widgets/pdfviewer/mainwindow.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/widgets/pdfviewer/mainwindow.cpp b/examples/widgets/pdfviewer/mainwindow.cpp new file mode 100644 index 0000000..1316ded --- /dev/null +++ b/examples/widgets/pdfviewer/mainwindow.cpp @@ -0,0 +1,39 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include <QFileDialog> +#include <QMessageBox> +#include <QPdfDocument> + +Q_LOGGING_CATEGORY(lcExample, "qt.examples.pdfviewer") + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) + , m_doc(new QPdfDocument(this)) +{ + ui->setupUi(this); + ui->pageWidget->setDocument(m_doc); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::open(const QUrl &docLocation) +{ + if (docLocation.isLocalFile()) + m_doc->load(docLocation.toLocalFile()); + else { + qCDebug(lcExample) << docLocation << "is not a valid local file"; + QMessageBox::critical(this, tr("Failed to open"), tr("%1 is not a valid local file").arg(docLocation.toString())); + } +} + +void MainWindow::on_actionOpen_triggered() +{ + QUrl toOpen = QFileDialog::getOpenFileUrl(this); + if (toOpen.isValid()) + open(toOpen); +} |