summaryrefslogtreecommitdiffstats
path: root/examples/pdfwidgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/pdfwidgets')
-rw-r--r--examples/pdfwidgets/CMakeLists.txt2
-rw-r--r--examples/pdfwidgets/pdfviewer/CMakeLists.txt38
-rw-r--r--examples/pdfwidgets/pdfviewer/doc/src/pdfviewer.qdoc59
-rw-r--r--examples/pdfwidgets/pdfviewer/images/busy.pngbin172 -> 0 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/document-open.svgzbin0 -> 4276 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/fileopen.pngbin1771 -> 0 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-down-search.svgzbin0 -> 330 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-next-24.pngbin782 -> 0 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-next-view-page.svgzbin0 -> 12615 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-next-view.svgzbin0 -> 6360 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-previous-24.pngbin797 -> 0 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-previous-view-page.svgzbin0 -> 12602 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-previous-view.svgzbin0 -> 6545 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/go-up-search.svgzbin0 -> 241 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-fit-best.svgzbin0 -> 6121 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-fit-width.svgzbin0 -> 6109 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-in-24.pngbin1302 -> 0 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-in-32.pngbin1873 -> 0 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-in.svgzbin0 -> 6033 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-original.svgzbin0 -> 5541 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-out-24.pngbin1247 -> 0 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-out-32.pngbin1749 -> 0 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-out.svgzbin0 -> 5420 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/images/zoom-previous.svgzbin0 -> 5665 bytes
-rw-r--r--examples/pdfwidgets/pdfviewer/main.cpp68
-rw-r--r--examples/pdfwidgets/pdfviewer/mainwindow.cpp191
-rw-r--r--examples/pdfwidgets/pdfviewer/mainwindow.h69
-rw-r--r--examples/pdfwidgets/pdfviewer/mainwindow.ui171
-rw-r--r--examples/pdfwidgets/pdfviewer/pageselector.cpp125
-rw-r--r--examples/pdfwidgets/pdfviewer/pageselector.h86
-rw-r--r--examples/pdfwidgets/pdfviewer/pdfviewer.pro4
-rw-r--r--examples/pdfwidgets/pdfviewer/resources.qrc17
-rw-r--r--examples/pdfwidgets/pdfviewer/searchresultdelegate.cpp46
-rw-r--r--examples/pdfwidgets/pdfviewer/searchresultdelegate.h20
-rw-r--r--examples/pdfwidgets/pdfviewer/zoomselector.cpp57
-rw-r--r--examples/pdfwidgets/pdfviewer/zoomselector.h51
36 files changed, 441 insertions, 563 deletions
diff --git a/examples/pdfwidgets/CMakeLists.txt b/examples/pdfwidgets/CMakeLists.txt
index 37496ebe3..dbde7f1c2 100644
--- a/examples/pdfwidgets/CMakeLists.txt
+++ b/examples/pdfwidgets/CMakeLists.txt
@@ -1 +1 @@
-add_subdirectory(pdfviewer)
+qt_internal_add_example(pdfviewer)
diff --git a/examples/pdfwidgets/pdfviewer/CMakeLists.txt b/examples/pdfwidgets/pdfviewer/CMakeLists.txt
index 692c33371..4ace81618 100644
--- a/examples/pdfwidgets/pdfviewer/CMakeLists.txt
+++ b/examples/pdfwidgets/pdfviewer/CMakeLists.txt
@@ -1,34 +1,32 @@
-# Generated from pdfviewer.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(pdfviewer LANGUAGES CXX)
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
+ set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/pdfwidgets/pdfviewer")
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets PdfWidgets)
qt_add_executable(pdfviewerwidgets
main.cpp
mainwindow.cpp mainwindow.h mainwindow.ui
- pageselector.cpp pageselector.h
+ searchresultdelegate.cpp searchresultdelegate.h
zoomselector.cpp zoomselector.h
)
+
set_target_properties(pdfviewerwidgets PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
+
target_link_libraries(pdfviewerwidgets PUBLIC
Qt::Core
Qt::Gui
@@ -36,17 +34,21 @@ target_link_libraries(pdfviewerwidgets PUBLIC
Qt::PdfWidgets
)
-
# Resources:
set(resources_resource_files
- "images/busy.png"
- "images/fileopen.png"
- "images/go-next-24.png"
- "images/go-previous-24.png"
- "images/zoom-in-24.png"
- "images/zoom-in-32.png"
- "images/zoom-out-24.png"
- "images/zoom-out-32.png"
+ "images/zoom-fit-width.svgz"
+ "images/zoom-in.svgz"
+ "images/go-previous-view-page.svgz"
+ "images/zoom-original.svgz"
+ "images/go-previous-view.svgz"
+ "images/go-next-view-page.svgz"
+ "images/zoom-fit-best.svgz"
+ "images/zoom-out.svgz"
+ "images/zoom-previous.svgz"
+ "images/document-open.svgz"
+ "images/go-next-view.svgz"
+ "images/go-down-search.svgz"
+ "images/go-up-search.svgz"
)
qt_add_resources(pdfviewerwidgets "resources"
diff --git a/examples/pdfwidgets/pdfviewer/doc/src/pdfviewer.qdoc b/examples/pdfwidgets/pdfviewer/doc/src/pdfviewer.qdoc
index 0cdd671be..b56958a9f 100644
--- a/examples/pdfwidgets/pdfviewer/doc/src/pdfviewer.qdoc
+++ b/examples/pdfwidgets/pdfviewer/doc/src/pdfviewer.qdoc
@@ -1,43 +1,19 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example pdfviewer
+ \meta installpath pdfwidgets
\ingroup qtpdf-examples
+ \examplecategory {User Interface Components}
- \title PDF Viewer Example
- \brief Renders PDF documents.
+ \title PDF Viewer Widget Example
+ \brief A widget-based PDF viewer that allows scrolling through the pages.
- \omit
- //! TODO add thumbnail \image pdfviewer.png
- \endomit
+ \image pdfviewer.png
- \e {PDF Viewer} demonstrates how to use the QPdfDocument class to render
- PDF documents and the QPdfPageNavigation class to navigate them.
+ \e {PDF Viewer} demonstrates how to use the QPdfView class to render
+ PDF documents and the QPdfPageNavigator class to navigate them.
Qt Creator and the integrated Qt Designer were used to create the example
UI and to connect it to the code. This affects the code, which might be
@@ -58,7 +34,7 @@
The class declares public and private slots that match the actions of the
selectors:
- \printuntil on_actionContinuous_triggered()
+ \printuntil on_actionForward_triggered()
The actual layout of the main window is specified in a \c{.ui} file. The
widgets and actions are available at runtime in the \c ui member variable.
@@ -79,16 +55,17 @@
\skipto MainWindow
\printuntil {
- The constructor first calls \c setupUi() to construct the zoom and page
- selectors according to the UI file. We set the maximum width of the
- selectors.
+ The constructor first calls \c setupUi() to construct most of the main window
+ according to the UI file. The zoom and page selectors need to be added to
+ the toolbar via \l QToolBar::insertWidget(), because that cannot be done
+ in a UI file:
- \printuntil addWidget(m_pageSelector)
+ \printuntil insertWidget(ui->actionForward, m_pageSelector);
- We use the QPdfPageNavigation class to handle the navigation through a
- PDF document:
+ We connect relevant signals to the page selector spinbox and the browser-style
+ back and forward buttons:
- \printuntil setPageNavigation
+ \printuntil forwardAvailableChanged
We connect the \c zoomModeChanged and \c zoomFactor changed signals of the
PDF view to the functions that reset the zoom selector:
diff --git a/examples/pdfwidgets/pdfviewer/images/busy.png b/examples/pdfwidgets/pdfviewer/images/busy.png
deleted file mode 100644
index 69056c479..000000000
--- a/examples/pdfwidgets/pdfviewer/images/busy.png
+++ /dev/null
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/document-open.svgz b/examples/pdfwidgets/pdfviewer/images/document-open.svgz
new file mode 100644
index 000000000..5ddde5981
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/document-open.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/fileopen.png b/examples/pdfwidgets/pdfviewer/images/fileopen.png
deleted file mode 100644
index 33e0d6394..000000000
--- a/examples/pdfwidgets/pdfviewer/images/fileopen.png
+++ /dev/null
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-down-search.svgz b/examples/pdfwidgets/pdfviewer/images/go-down-search.svgz
new file mode 100644
index 000000000..f845473e7
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/go-down-search.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-next-24.png b/examples/pdfwidgets/pdfviewer/images/go-next-24.png
deleted file mode 100644
index 9a55ef3d8..000000000
--- a/examples/pdfwidgets/pdfviewer/images/go-next-24.png
+++ /dev/null
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-next-view-page.svgz b/examples/pdfwidgets/pdfviewer/images/go-next-view-page.svgz
new file mode 100644
index 000000000..e7f7bece4
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/go-next-view-page.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-next-view.svgz b/examples/pdfwidgets/pdfviewer/images/go-next-view.svgz
new file mode 100644
index 000000000..2f86541cc
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/go-next-view.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-previous-24.png b/examples/pdfwidgets/pdfviewer/images/go-previous-24.png
deleted file mode 100644
index 2ea769eb8..000000000
--- a/examples/pdfwidgets/pdfviewer/images/go-previous-24.png
+++ /dev/null
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-previous-view-page.svgz b/examples/pdfwidgets/pdfviewer/images/go-previous-view-page.svgz
new file mode 100644
index 000000000..f4df6df40
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/go-previous-view-page.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-previous-view.svgz b/examples/pdfwidgets/pdfviewer/images/go-previous-view.svgz
new file mode 100644
index 000000000..688f55ffe
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/go-previous-view.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/go-up-search.svgz b/examples/pdfwidgets/pdfviewer/images/go-up-search.svgz
new file mode 100644
index 000000000..6378721fa
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/go-up-search.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-fit-best.svgz b/examples/pdfwidgets/pdfviewer/images/zoom-fit-best.svgz
new file mode 100644
index 000000000..0cb1b3074
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-fit-best.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-fit-width.svgz b/examples/pdfwidgets/pdfviewer/images/zoom-fit-width.svgz
new file mode 100644
index 000000000..a467f6eae
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-fit-width.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-in-24.png b/examples/pdfwidgets/pdfviewer/images/zoom-in-24.png
deleted file mode 100644
index d29b142b6..000000000
--- a/examples/pdfwidgets/pdfviewer/images/zoom-in-24.png
+++ /dev/null
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-in-32.png b/examples/pdfwidgets/pdfviewer/images/zoom-in-32.png
deleted file mode 100644
index 34d70af37..000000000
--- a/examples/pdfwidgets/pdfviewer/images/zoom-in-32.png
+++ /dev/null
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-in.svgz b/examples/pdfwidgets/pdfviewer/images/zoom-in.svgz
new file mode 100644
index 000000000..21d6c2ab2
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-in.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-original.svgz b/examples/pdfwidgets/pdfviewer/images/zoom-original.svgz
new file mode 100644
index 000000000..afa79db19
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-original.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-out-24.png b/examples/pdfwidgets/pdfviewer/images/zoom-out-24.png
deleted file mode 100644
index 19703474f..000000000
--- a/examples/pdfwidgets/pdfviewer/images/zoom-out-24.png
+++ /dev/null
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-out-32.png b/examples/pdfwidgets/pdfviewer/images/zoom-out-32.png
deleted file mode 100644
index b83220661..000000000
--- a/examples/pdfwidgets/pdfviewer/images/zoom-out-32.png
+++ /dev/null
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-out.svgz b/examples/pdfwidgets/pdfviewer/images/zoom-out.svgz
new file mode 100644
index 000000000..b6db7a144
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-out.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/images/zoom-previous.svgz b/examples/pdfwidgets/pdfviewer/images/zoom-previous.svgz
new file mode 100644
index 000000000..ad4c29215
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/images/zoom-previous.svgz
Binary files differ
diff --git a/examples/pdfwidgets/pdfviewer/main.cpp b/examples/pdfwidgets/pdfviewer/main.cpp
index fae6a5e30..6b890e0ac 100644
--- a/examples/pdfwidgets/pdfviewer/main.cpp
+++ b/examples/pdfwidgets/pdfviewer/main.cpp
@@ -1,65 +1,29 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "mainwindow.h"
#include <QApplication>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
#include <QUrl>
int main(int argc, char *argv[])
{
+ QCoreApplication::setApplicationName("Qt PDF Viewer");
+ QCoreApplication::setOrganizationName("QtProject");
+
QApplication a(argc, argv);
+
+ QCommandLineParser parser;
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.addPositionalArgument("file", "The file to open.");
+ parser.process(a);
+
MainWindow w;
- QStringList args = a.arguments();
w.show();
- if (args.length() > 1)
- w.open(QUrl::fromLocalFile(args[1]));
+ if (!parser.positionalArguments().isEmpty())
+ w.open(QUrl::fromLocalFile(parser.positionalArguments().constFirst()));
return a.exec();
}
diff --git a/examples/pdfwidgets/pdfviewer/mainwindow.cpp b/examples/pdfwidgets/pdfviewer/mainwindow.cpp
index bba1125b9..ce19359fc 100644
--- a/examples/pdfwidgets/pdfviewer/mainwindow.cpp
+++ b/examples/pdfwidgets/pdfviewer/mainwindow.cpp
@@ -1,64 +1,22 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "mainwindow.h"
#include "ui_mainwindow.h"
-#include "pageselector.h"
+#include "searchresultdelegate.h"
#include "zoomselector.h"
#include <QFileDialog>
+#include <QLineEdit>
#include <QMessageBox>
#include <QPdfBookmarkModel>
#include <QPdfDocument>
-#include <QPdfPageNavigation>
+#include <QPdfPageNavigator>
+#include <QPdfPageSelector>
+#include <QPdfSearchModel>
+#include <QShortcut>
+#include <QStandardPaths>
#include <QtMath>
const qreal zoomMultiplier = qSqrt(2.0);
@@ -69,7 +27,9 @@ MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_zoomSelector(new ZoomSelector(this))
- , m_pageSelector(new PageSelector(this))
+ , m_pageSelector(new QPdfPageSelector(this))
+ , m_searchModel(new QPdfSearchModel(this))
+ , m_searchField(new QLineEdit(this))
, m_document(new QPdfDocument(this))
{
ui->setupUi(this);
@@ -77,10 +37,13 @@ MainWindow::MainWindow(QWidget *parent)
m_zoomSelector->setMaximumWidth(150);
ui->mainToolBar->insertWidget(ui->actionZoom_In, m_zoomSelector);
- m_pageSelector->setMaximumWidth(150);
- ui->mainToolBar->addWidget(m_pageSelector);
-
- m_pageSelector->setPageNavigation(ui->pdfView->pageNavigation());
+ ui->mainToolBar->insertWidget(ui->actionForward, m_pageSelector);
+ connect(m_pageSelector, &QPdfPageSelector::currentPageChanged, this, &MainWindow::pageSelected);
+ m_pageSelector->setDocument(m_document);
+ auto nav = ui->pdfView->pageNavigator();
+ connect(nav, &QPdfPageNavigator::currentPageChanged, m_pageSelector, &QPdfPageSelector::setCurrentPage);
+ connect(nav, &QPdfPageNavigator::backAvailableChanged, ui->actionBack, &QAction::setEnabled);
+ connect(nav, &QPdfPageNavigator::forwardAvailableChanged, ui->actionForward, &QAction::setEnabled);
connect(m_zoomSelector, &ZoomSelector::zoomModeChanged, ui->pdfView, &QPdfView::setZoomMode);
connect(m_zoomSelector, &ZoomSelector::zoomFactorChanged, ui->pdfView, &QPdfView::setZoomFactor);
@@ -90,9 +53,26 @@ MainWindow::MainWindow(QWidget *parent)
bookmarkModel->setDocument(m_document);
ui->bookmarkView->setModel(bookmarkModel);
- connect(ui->bookmarkView, SIGNAL(activated(QModelIndex)), this, SLOT(bookmarkSelected(QModelIndex)));
-
- ui->tabWidget->setTabEnabled(1, false); // disable 'Pages' tab for now
+ connect(ui->bookmarkView, &QAbstractItemView::activated, this, &MainWindow::bookmarkSelected);
+
+ ui->thumbnailsView->setModel(m_document->pageModel());
+
+ m_searchModel->setDocument(m_document);
+ ui->pdfView->setSearchModel(m_searchModel);
+ ui->searchToolBar->insertWidget(ui->actionFindPrevious, m_searchField);
+ connect(new QShortcut(QKeySequence::Find, this), &QShortcut::activated, this, [this]() {
+ m_searchField->setFocus(Qt::ShortcutFocusReason);
+ });
+ m_searchField->setPlaceholderText(tr("Find in document"));
+ m_searchField->setMaximumWidth(400);
+ connect(m_searchField, &QLineEdit::textEdited, this, [this](const QString &text) {
+ m_searchModel->setSearchString(text);
+ ui->tabWidget->setCurrentWidget(ui->searchResultsTab);
+ });
+ ui->searchResultsView->setModel(m_searchModel);
+ ui->searchResultsView->setItemDelegate(new SearchResultDelegate(this));
+ connect(ui->searchResultsView->selectionModel(), &QItemSelectionModel::currentChanged,
+ this, &MainWindow::searchResultSelected);
ui->pdfView->setDocument(m_document);
@@ -109,11 +89,11 @@ void MainWindow::open(const QUrl &docLocation)
{
if (docLocation.isLocalFile()) {
m_document->load(docLocation.toLocalFile());
- const auto documentTitle = m_document->metaData(QPdfDocument::Title).toString();
- setWindowTitle(!documentTitle.isEmpty() ? documentTitle : QStringLiteral("PDF Viewer"));
+ pageSelected(0);
} 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()));
+ const QString message = tr("%1 is not a valid local file").arg(docLocation.toString());
+ qCDebug(lcExample).noquote() << message;
+ QMessageBox::critical(this, tr("Failed to open"), message);
}
qCDebug(lcExample) << docLocation;
}
@@ -123,15 +103,48 @@ void MainWindow::bookmarkSelected(const QModelIndex &index)
if (!index.isValid())
return;
- const int page = index.data(QPdfBookmarkModel::PageNumberRole).toInt();
- ui->pdfView->pageNavigation()->setCurrentPage(page);
+ const int page = index.data(int(QPdfBookmarkModel::Role::Page)).toInt();
+ const qreal zoomLevel = index.data(int(QPdfBookmarkModel::Role::Level)).toReal();
+ ui->pdfView->pageNavigator()->jump(page, {}, zoomLevel);
+}
+
+void MainWindow::pageSelected(int page)
+{
+ auto nav = ui->pdfView->pageNavigator();
+ nav->jump(page, {}, nav->currentZoom());
+ const auto documentTitle = m_document->metaData(QPdfDocument::MetaDataField::Title).toString();
+ setWindowTitle(!documentTitle.isEmpty() ? documentTitle : QStringLiteral("PDF Viewer"));
+ setWindowTitle(tr("%1: page %2 (%3 of %4)")
+ .arg(documentTitle.isEmpty() ? u"PDF Viewer"_qs : documentTitle,
+ m_pageSelector->currentPageLabel(), QString::number(page + 1), QString::number(m_document->pageCount())));
+}
+
+void MainWindow::searchResultSelected(const QModelIndex &current, const QModelIndex &previous)
+{
+ Q_UNUSED(previous);
+ if (!current.isValid())
+ return;
+
+ const int page = current.data(int(QPdfSearchModel::Role::Page)).toInt();
+ const QPointF location = current.data(int(QPdfSearchModel::Role::Location)).toPointF();
+ ui->pdfView->pageNavigator()->jump(page, location);
+ ui->pdfView->setCurrentSearchResultIndex(current.row());
}
void MainWindow::on_actionOpen_triggered()
{
- QUrl toOpen = QFileDialog::getOpenFileUrl(this, tr("Choose a PDF"), QUrl(), "Portable Documents (*.pdf)");
- if (toOpen.isValid())
- open(toOpen);
+ if (m_fileDialog == nullptr) {
+ m_fileDialog = new QFileDialog(this, tr("Choose a PDF"),
+ QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
+ m_fileDialog->setAcceptMode(QFileDialog::AcceptOpen);
+ m_fileDialog->setMimeTypeFilters({"application/pdf"});
+ }
+
+ if (m_fileDialog->exec() == QDialog::Accepted) {
+ const QUrl toOpen = m_fileDialog->selectedUrls().constFirst();
+ if (toOpen.isValid())
+ open(toOpen);
+ }
}
void MainWindow::on_actionQuit_triggered()
@@ -162,15 +175,51 @@ void MainWindow::on_actionZoom_Out_triggered()
void MainWindow::on_actionPrevious_Page_triggered()
{
- ui->pdfView->pageNavigation()->goToPreviousPage();
+ auto nav = ui->pdfView->pageNavigator();
+ nav->jump(nav->currentPage() - 1, {}, nav->currentZoom());
}
void MainWindow::on_actionNext_Page_triggered()
{
- ui->pdfView->pageNavigation()->goToNextPage();
+ auto nav = ui->pdfView->pageNavigator();
+ nav->jump(nav->currentPage() + 1, {}, nav->currentZoom());
+}
+
+void MainWindow::on_thumbnailsView_activated(const QModelIndex &index)
+{
+ auto nav = ui->pdfView->pageNavigator();
+ nav->jump(index.row(), {}, nav->currentZoom());
}
void MainWindow::on_actionContinuous_triggered()
{
- ui->pdfView->setPageMode(ui->actionContinuous->isChecked() ? QPdfView::MultiPage : QPdfView::SinglePage);
+ ui->pdfView->setPageMode(ui->actionContinuous->isChecked() ?
+ QPdfView::PageMode::MultiPage :
+ QPdfView::PageMode::SinglePage);
+}
+
+void MainWindow::on_actionBack_triggered()
+{
+ ui->pdfView->pageNavigator()->back();
+}
+
+void MainWindow::on_actionForward_triggered()
+{
+ ui->pdfView->pageNavigator()->forward();
+}
+
+void MainWindow::on_actionFindNext_triggered()
+{
+ int next = ui->searchResultsView->currentIndex().row() + 1;
+ if (next >= m_searchModel->rowCount({}))
+ next = 0;
+ ui->searchResultsView->setCurrentIndex(m_searchModel->index(next));
+}
+
+void MainWindow::on_actionFindPrevious_triggered()
+{
+ int prev = ui->searchResultsView->currentIndex().row() - 1;
+ if (prev < 0)
+ prev = m_searchModel->rowCount({}) - 1;
+ ui->searchResultsView->setCurrentIndex(m_searchModel->index(prev));
}
diff --git a/examples/pdfwidgets/pdfviewer/mainwindow.h b/examples/pdfwidgets/pdfviewer/mainwindow.h
index 571dbd911..7f5a5dbca 100644
--- a/examples/pdfwidgets/pdfviewer/mainwindow.h
+++ b/examples/pdfwidgets/pdfviewer/mainwindow.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
@@ -61,11 +14,15 @@ namespace Ui {
class MainWindow;
}
+class QFileDialog;
+class QLineEdit;
class QPdfDocument;
+class QPdfPageSelector;
+class QPdfSearchModel;
class QPdfView;
+class QSpinBox;
QT_END_NAMESPACE
-class PageSelector;
class ZoomSelector;
class MainWindow : public QMainWindow
@@ -81,6 +38,8 @@ public slots:
private slots:
void bookmarkSelected(const QModelIndex &index);
+ void pageSelected(int page);
+ void searchResultSelected(const QModelIndex &current, const QModelIndex &previous);
// action handlers
void on_actionOpen_triggered();
@@ -91,12 +50,20 @@ private slots:
void on_actionZoom_Out_triggered();
void on_actionPrevious_Page_triggered();
void on_actionNext_Page_triggered();
+ void on_thumbnailsView_activated(const QModelIndex &index);
void on_actionContinuous_triggered();
+ void on_actionBack_triggered();
+ void on_actionForward_triggered();
+ void on_actionFindNext_triggered();
+ void on_actionFindPrevious_triggered();
private:
Ui::MainWindow *ui;
ZoomSelector *m_zoomSelector;
- PageSelector *m_pageSelector;
+ QPdfPageSelector *m_pageSelector;
+ QPdfSearchModel *m_searchModel;
+ QLineEdit *m_searchField;
+ QFileDialog *m_fileDialog = nullptr;
QPdfDocument *m_document;
};
diff --git a/examples/pdfwidgets/pdfviewer/mainwindow.ui b/examples/pdfwidgets/pdfviewer/mainwindow.ui
index 2651525a5..881df2e1b 100644
--- a/examples/pdfwidgets/pdfviewer/mainwindow.ui
+++ b/examples/pdfwidgets/pdfviewer/mainwindow.ui
@@ -111,6 +111,74 @@
<attribute name="title">
<string>Pages</string>
</attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <property name="leftMargin">
+ <number>2</number>
+ </property>
+ <property name="topMargin">
+ <number>2</number>
+ </property>
+ <property name="rightMargin">
+ <number>2</number>
+ </property>
+ <property name="bottomMargin">
+ <number>2</number>
+ </property>
+ <item>
+ <widget class="QListView" name="thumbnailsView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>128</width>
+ <height>128</height>
+ </size>
+ </property>
+ <property name="movement">
+ <enum>QListView::Static</enum>
+ </property>
+ <property name="resizeMode">
+ <enum>QListView::Adjust</enum>
+ </property>
+ <property name="viewMode">
+ <enum>QListView::IconMode</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="searchResultsTab">
+ <attribute name="title">
+ <string>Search Results</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="leftMargin">
+ <number>2</number>
+ </property>
+ <property name="topMargin">
+ <number>2</number>
+ </property>
+ <property name="rightMargin">
+ <number>2</number>
+ </property>
+ <property name="bottomMargin">
+ <number>2</number>
+ </property>
+ <item>
+ <widget class="QListView" name="searchResultsView">
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
</widget>
</widget>
<widget class="QPdfView" name="pdfView" native="true">
@@ -134,7 +202,7 @@
<x>0</x>
<y>0</y>
<width>700</width>
- <height>22</height>
+ <height>23</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@@ -184,12 +252,27 @@
<addaction name="actionZoom_Out"/>
<addaction name="actionZoom_In"/>
<addaction name="separator"/>
+ <addaction name="actionBack"/>
+ <addaction name="actionForward"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
+ <widget class="QToolBar" name="searchToolBar">
+ <property name="windowTitle">
+ <string>toolBar</string>
+ </property>
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionFindPrevious"/>
+ <addaction name="actionFindNext"/>
+ </widget>
<action name="actionOpen">
<property name="icon">
- <iconset resource="resources.qrc">
- <normaloff>:/icons/images/fileopen.png</normaloff>:/icons/images/fileopen.png</iconset>
+ <iconset theme="document-open" resource="resources.qrc">
+ <normaloff>:/icons/images/document-open.svgz</normaloff>:/icons/images/document-open.svgz</iconset>
</property>
<property name="text">
<string>Open...</string>
@@ -199,6 +282,9 @@
</property>
</action>
<action name="actionQuit">
+ <property name="icon">
+ <iconset theme="application-exit"/>
+ </property>
<property name="text">
<string>Quit</string>
</property>
@@ -207,6 +293,9 @@
</property>
</action>
<action name="actionAbout">
+ <property name="icon">
+ <iconset theme="help-about"/>
+ </property>
<property name="text">
<string>About</string>
</property>
@@ -218,8 +307,8 @@
</action>
<action name="actionZoom_In">
<property name="icon">
- <iconset resource="resources.qrc">
- <normaloff>:/icons/images/zoom-in-24.png</normaloff>:/icons/images/zoom-in-24.png</iconset>
+ <iconset theme="zoom-in" resource="resources.qrc">
+ <normaloff>:/icons/images/zoom-in.svgz</normaloff>:/icons/images/zoom-in.svgz</iconset>
</property>
<property name="text">
<string>Zoom In</string>
@@ -230,8 +319,8 @@
</action>
<action name="actionZoom_Out">
<property name="icon">
- <iconset resource="resources.qrc">
- <normaloff>:/icons/images/zoom-out-24.png</normaloff>:/icons/images/zoom-out-24.png</iconset>
+ <iconset theme="zoom-out" resource="resources.qrc">
+ <normaloff>:/icons/images/zoom-out.svgz</normaloff>:/icons/images/zoom-out.svgz</iconset>
</property>
<property name="text">
<string>Zoom Out</string>
@@ -241,6 +330,10 @@
</property>
</action>
<action name="actionPrevious_Page">
+ <property name="icon">
+ <iconset theme="go-previous-view-page" resource="resources.qrc">
+ <normaloff>:/icons/images/go-previous-view-page.svgz</normaloff>:/icons/images/go-previous-view-page.svgz</iconset>
+ </property>
<property name="text">
<string>Previous Page</string>
</property>
@@ -249,6 +342,10 @@
</property>
</action>
<action name="actionNext_Page">
+ <property name="icon">
+ <iconset theme="go-next-view-page" resource="resources.qrc">
+ <normaloff>:/icons/images/go-next-view-page.svgz</normaloff>:/icons/images/go-next-view-page.svgz</iconset>
+ </property>
<property name="text">
<string>Next Page</string>
</property>
@@ -264,6 +361,66 @@
<string>Continuous</string>
</property>
</action>
+ <action name="actionBack">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="icon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/icons/images/go-previous-view.svgz</normaloff>:/icons/images/go-previous-view.svgz</iconset>
+ </property>
+ <property name="text">
+ <string>Back</string>
+ </property>
+ <property name="toolTip">
+ <string>back to previous view</string>
+ </property>
+ </action>
+ <action name="actionForward">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="icon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/icons/images/go-next-view.svgz</normaloff>:/icons/images/go-next-view.svgz</iconset>
+ </property>
+ <property name="text">
+ <string>Forward</string>
+ </property>
+ <property name="toolTip">
+ <string>forward to next view</string>
+ </property>
+ </action>
+ <action name="actionFindNext">
+ <property name="icon">
+ <iconset theme="go-down" resource=".rcc/resources.qrc">
+ <normaloff>:/icons/images/go-down-search.svgz</normaloff>:/icons/images/go-down-search.svgz</iconset>
+ </property>
+ <property name="text">
+ <string>Find Next</string>
+ </property>
+ <property name="toolTip">
+ <string>Find the next occurrence of the phrase</string>
+ </property>
+ <property name="shortcut">
+ <string>F3</string>
+ </property>
+ </action>
+ <action name="actionFindPrevious">
+ <property name="icon">
+ <iconset theme="go-up" resource=".rcc/resources.qrc">
+ <normaloff>:/icons/images/go-up-search.svgz</normaloff>:/icons/images/go-up-search.svgz</iconset>
+ </property>
+ <property name="text">
+ <string>Find Previous</string>
+ </property>
+ <property name="toolTip">
+ <string>Find the previous occurrence of the phrase</string>
+ </property>
+ <property name="shortcut">
+ <string>Shift+F3</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
diff --git a/examples/pdfwidgets/pdfviewer/pageselector.cpp b/examples/pdfwidgets/pdfviewer/pageselector.cpp
deleted file mode 100644
index 28bff1359..000000000
--- a/examples/pdfwidgets/pdfviewer/pageselector.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "pageselector.h"
-
-#include <QHBoxLayout>
-#include <QLabel>
-#include <QLineEdit>
-#include <QPdfPageNavigation>
-#include <QToolButton>
-
-PageSelector::PageSelector(QWidget *parent)
- : QWidget(parent)
- , m_pageNavigation(nullptr)
-{
- QHBoxLayout *layout = new QHBoxLayout(this);
-
- m_previousPageButton = new QToolButton(this);
- m_previousPageButton->setText("<");
- m_previousPageButton->setEnabled(false);
-
- m_pageNumberEdit = new QLineEdit(this);
- m_pageNumberEdit->setAlignment(Qt::AlignRight);
-
- m_pageCountLabel = new QLabel(this);
- m_pageCountLabel->setText("0");
-
- m_nextPageButton = new QToolButton(this);
- m_nextPageButton->setText(">");
- m_nextPageButton->setEnabled(false);
-
- layout->addWidget(m_previousPageButton);
- layout->addWidget(m_pageNumberEdit);
- layout->addWidget(m_pageCountLabel);
- layout->addWidget(m_nextPageButton);
-}
-
-void PageSelector::setPageNavigation(QPdfPageNavigation *pageNavigation)
-{
- m_pageNavigation = pageNavigation;
-
- connect(m_previousPageButton, &QToolButton::clicked, m_pageNavigation, &QPdfPageNavigation::goToPreviousPage);
- connect(m_pageNavigation, &QPdfPageNavigation::canGoToPreviousPageChanged, m_previousPageButton, &QToolButton::setEnabled);
-
- connect(m_pageNavigation, &QPdfPageNavigation::currentPageChanged, this, &PageSelector::onCurrentPageChanged);
- connect(m_pageNavigation, &QPdfPageNavigation::pageCountChanged, this, [this](int pageCount){ m_pageCountLabel->setText(QString::fromLatin1("/ %1").arg(pageCount)); });
-
- connect(m_pageNumberEdit, &QLineEdit::editingFinished, this, &PageSelector::pageNumberEdited);
-
- connect(m_nextPageButton, &QToolButton::clicked, m_pageNavigation, &QPdfPageNavigation::goToNextPage);
- connect(m_pageNavigation, &QPdfPageNavigation::canGoToNextPageChanged, m_nextPageButton, &QToolButton::setEnabled);
-
- onCurrentPageChanged(m_pageNavigation->currentPage());
-}
-
-void PageSelector::onCurrentPageChanged(int page)
-{
- if (m_pageNavigation->pageCount() == 0)
- m_pageNumberEdit->setText(QString::number(0));
- else
- m_pageNumberEdit->setText(QString::number(page + 1));
-}
-
-void PageSelector::pageNumberEdited()
-{
- if (!m_pageNavigation)
- return;
-
- const QString text = m_pageNumberEdit->text();
-
- bool ok = false;
- const int pageNumber = text.toInt(&ok);
-
- if (!ok)
- onCurrentPageChanged(m_pageNavigation->currentPage());
- else
- m_pageNavigation->setCurrentPage(qBound(0, pageNumber - 1, m_pageNavigation->pageCount() - 1));
-}
diff --git a/examples/pdfwidgets/pdfviewer/pageselector.h b/examples/pdfwidgets/pdfviewer/pageselector.h
deleted file mode 100644
index 58fc6d2f0..000000000
--- a/examples/pdfwidgets/pdfviewer/pageselector.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef PAGESELECTOR_H
-#define PAGESELECTOR_H
-
-#include <QWidget>
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-class QLineEdit;
-class QPdfDocument;
-class QPdfPageNavigation;
-class QToolButton;
-QT_END_NAMESPACE
-
-class PageSelector : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit PageSelector(QWidget *parent = nullptr);
-
- void setPageNavigation(QPdfPageNavigation *pageNavigation);
-
-private slots:
- void onCurrentPageChanged(int page);
- void pageNumberEdited();
-
-private:
- QPdfPageNavigation *m_pageNavigation;
-
- QLineEdit *m_pageNumberEdit;
- QLabel *m_pageCountLabel;
- QToolButton *m_previousPageButton;
- QToolButton *m_nextPageButton;
-};
-
-#endif // PAGESELECTOR_H
diff --git a/examples/pdfwidgets/pdfviewer/pdfviewer.pro b/examples/pdfwidgets/pdfviewer/pdfviewer.pro
index ad0607ea5..5e48edeb9 100644
--- a/examples/pdfwidgets/pdfviewer/pdfviewer.pro
+++ b/examples/pdfwidgets/pdfviewer/pdfviewer.pro
@@ -5,12 +5,12 @@ QT += core gui widgets pdfwidgets
SOURCES += \
main.cpp \
mainwindow.cpp \
- pageselector.cpp \
+ searchresultdelegate.cpp \
zoomselector.cpp
HEADERS += \
mainwindow.h \
- pageselector.h \
+ searchresultdelegate.h \
zoomselector.h
FORMS += \
diff --git a/examples/pdfwidgets/pdfviewer/resources.qrc b/examples/pdfwidgets/pdfviewer/resources.qrc
index 02d9655b4..ea408b825 100644
--- a/examples/pdfwidgets/pdfviewer/resources.qrc
+++ b/examples/pdfwidgets/pdfviewer/resources.qrc
@@ -1,12 +1,13 @@
<RCC>
<qresource prefix="/icons">
- <file>images/fileopen.png</file>
- <file>images/go-next-24.png</file>
- <file>images/go-previous-24.png</file>
- <file>images/zoom-in-24.png</file>
- <file>images/zoom-in-32.png</file>
- <file>images/zoom-out-24.png</file>
- <file>images/zoom-out-32.png</file>
- <file>images/busy.png</file>
+ <file>images/document-open.svgz</file>
+ <file>images/go-down-search.svgz</file>
+ <file>images/go-next-view.svgz</file>
+ <file>images/go-previous-view.svgz</file>
+ <file>images/go-next-view-page.svgz</file>
+ <file>images/go-previous-view-page.svgz</file>
+ <file>images/go-up-search.svgz</file>
+ <file>images/zoom-in.svgz</file>
+ <file>images/zoom-out.svgz</file>
</qresource>
</RCC>
diff --git a/examples/pdfwidgets/pdfviewer/searchresultdelegate.cpp b/examples/pdfwidgets/pdfviewer/searchresultdelegate.cpp
new file mode 100644
index 000000000..87efd916d
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/searchresultdelegate.cpp
@@ -0,0 +1,46 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QFontMetrics>
+#include <QPainter>
+#include <QPdfSearchModel>
+
+#include "searchresultdelegate.h"
+
+SearchResultDelegate::SearchResultDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{
+}
+
+void SearchResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ const QString displayText = index.data().toString();
+ const auto boldBegin = displayText.indexOf(u"<b>", 0, Qt::CaseInsensitive) + 3;
+ const auto boldEnd = displayText.indexOf(u"</b>", boldBegin, Qt::CaseInsensitive);
+ if (boldBegin >= 3 && boldEnd > boldBegin) {
+ const QString pageLabel = tr("Page %1: ").arg(index.data(int(QPdfSearchModel::Role::Page)).toInt());
+ const QString boldText = displayText.mid(boldBegin, boldEnd - boldBegin);
+ if (option.state & QStyle::State_Selected)
+ painter->fillRect(option.rect, option.palette.highlight());
+ const QFont defaultFont = painter->font();
+ QFontMetrics fm = painter->fontMetrics();
+ auto pageLabelWidth = fm.horizontalAdvance(pageLabel);
+ const int yOffset = (option.rect.height() - fm.height()) / 2 + fm.ascent();
+ painter->drawText(0, option.rect.y() + yOffset, pageLabel);
+ QFont boldFont = defaultFont;
+ boldFont.setBold(true);
+ auto boldWidth = QFontMetrics(boldFont).horizontalAdvance(boldText);
+ auto prefixSuffixWidth = (option.rect.width() - pageLabelWidth - boldWidth) / 2;
+ painter->setFont(boldFont);
+ painter->drawText(pageLabelWidth + prefixSuffixWidth, option.rect.y() + yOffset, boldText);
+ painter->setFont(defaultFont);
+ const QString suffix = fm.elidedText(displayText.mid(boldEnd + 4), Qt::ElideRight, prefixSuffixWidth);
+ painter->drawText(pageLabelWidth + prefixSuffixWidth + boldWidth, option.rect.y() + yOffset, suffix);
+ const QString prefix = fm.elidedText(displayText.left(boldBegin - 3), Qt::ElideLeft, prefixSuffixWidth);
+ painter->drawText(pageLabelWidth + prefixSuffixWidth - fm.horizontalAdvance(prefix),
+ option.rect.y() + yOffset, prefix);
+ } else {
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+}
diff --git a/examples/pdfwidgets/pdfviewer/searchresultdelegate.h b/examples/pdfwidgets/pdfviewer/searchresultdelegate.h
new file mode 100644
index 000000000..dcf886111
--- /dev/null
+++ b/examples/pdfwidgets/pdfviewer/searchresultdelegate.h
@@ -0,0 +1,20 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef SEARCHRESULTDELEGATE_H
+#define SEARCHRESULTDELEGATE_H
+
+#include <QStyledItemDelegate>
+
+//! [0]
+class SearchResultDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ SearchResultDelegate(QObject *parent = nullptr);
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override;
+};
+
+#endif // SEARCHRESULTDELEGATE_H
diff --git a/examples/pdfwidgets/pdfviewer/zoomselector.cpp b/examples/pdfwidgets/pdfviewer/zoomselector.cpp
index 4ccf87460..0b314129a 100644
--- a/examples/pdfwidgets/pdfviewer/zoomselector.cpp
+++ b/examples/pdfwidgets/pdfviewer/zoomselector.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "zoomselector.h"
@@ -91,9 +44,9 @@ void ZoomSelector::reset()
void ZoomSelector::onCurrentTextChanged(const QString &text)
{
if (text == QLatin1String("Fit Width")) {
- emit zoomModeChanged(QPdfView::FitToWidth);
+ emit zoomModeChanged(QPdfView::ZoomMode::FitToWidth);
} else if (text == QLatin1String("Fit Page")) {
- emit zoomModeChanged(QPdfView::FitInView);
+ emit zoomModeChanged(QPdfView::ZoomMode::FitInView);
} else {
qreal factor = 1.0;
@@ -105,7 +58,7 @@ void ZoomSelector::onCurrentTextChanged(const QString &text)
if (ok)
factor = zoomLevel / 100.0;
- emit zoomModeChanged(QPdfView::CustomZoom);
+ emit zoomModeChanged(QPdfView::ZoomMode::Custom);
emit zoomFactorChanged(factor);
}
}
diff --git a/examples/pdfwidgets/pdfviewer/zoomselector.h b/examples/pdfwidgets/pdfviewer/zoomselector.h
index 50a97ee88..7c35bdab7 100644
--- a/examples/pdfwidgets/pdfviewer/zoomselector.h
+++ b/examples/pdfwidgets/pdfviewer/zoomselector.h
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtPDF module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef ZOOMSELECTOR_H
#define ZOOMSELECTOR_H