Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpdfpageselector.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qpdfpageselector.h"
6
7#include <QPdfDocument>
8
9#include <QtWidgets/qboxlayout.h>
10
11using namespace Qt::StringLiterals;
12
14
31 : QWidget(parent), d_ptr(new QPdfPageSelectorPrivate)
32{
34 d->spinBox = new QPdfPageSelectorSpinBox(this);
35 d->spinBox->setObjectName(u"_q_spinBox"_s);
36 auto vlay = new QVBoxLayout(this);
37 vlay->setContentsMargins({});
38 vlay->addWidget(d->spinBox);
39
44}
45
50 = default;
51
59{
61 d->spinBox->setDocument(doc);
62}
63
65{
66 Q_D(const QPdfPageSelector);
67 return d->spinBox->document();
68}
69
78{
79 Q_D(const QPdfPageSelector);
80 return d->spinBox->value();
81}
82
84{
86 d->spinBox->setValue(index);
87}
88
101{
102 Q_D(const QPdfPageSelector);
103 return d->spinBox->text();
104}
105
106//
107// QPdfPageSelectorSpinBox:
108//
109
110void QPdfPageSelectorSpinBox::documentStatusChanged()
111{
112 if (m_document && m_document->status() == QPdfDocument::Status::Ready) {
113 setMaximum(m_document->pageCount());
114 setValue(0);
115 }
116}
117
119{
120 if (m_document == document)
121 return;
122
123 if (m_document)
124 disconnect(m_documentStatusChangedConnection);
125
126 m_document = document;
128
129 if (m_document) {
130 m_documentStatusChangedConnection =
132 this, &QPdfPageSelectorSpinBox::documentStatusChanged);
133 }
134
135 documentStatusChanged();
136}
137
142
144 = default;
145
147{
148 if (!m_document)
149 return 0;
150
151 return m_document->pageIndexForLabel(text.trimmed());
152}
153
155{
156 if (!m_document)
157 return {};
158
159 return m_document->pageLabel(value);
160}
161
167
169
170#include "moc_qpdfpageselector_p.cpp"
171#include "moc_qpdfpageselector.cpp"
QString text
the spin box's text, including any prefix and suffix
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QPdfDocument class loads a PDF document and renders pages from it.
Status status
This property holds the current status of the document.
int pageCount
This property holds the number of pages in the loaded document or 0 if no document is loaded.
Q_INVOKABLE int pageIndexForLabel(const QString &label)
Returns the index of the page that has the label, or -1 if not found.
Q_INVOKABLE QString pageLabel(int page)
Returns the page number to be used for display purposes.
void statusChanged(QPdfDocument::Status status)
QValidator::State validate(QString &text, int &pos) const override
This virtual function is called by the QAbstractSpinBox to determine whether input is valid.
int valueFromText(const QString &text) const override
This virtual function is used by the spin box whenever it needs to interpret text entered by the user...
void _q_documentChanged(QPdfDocument *document)
QPdfDocument * document() const
void setDocument(QPdfDocument *document)
QString textFromValue(int value) const override
This virtual function is used by the spin box whenever it needs to display the given value.
\inmodule QtPdf
int currentPage
This property holds the index ({0}-based) of the current page in the document.
void setCurrentPage(int index)
QPdfDocument * document
This property holds the document to be viewed.
void setDocument(QPdfDocument *document)
void currentPageLabelChanged(const QString &label)
void currentPageChanged(int index)
QString currentPageLabel
This property holds the page label corresponding to the current page in the document.
~QPdfPageSelector() override
Destroys the page selector.
void documentChanged(QPdfDocument *document)
T * get() const noexcept
Definition qpointer.h:75
The QSpinBox class provides a spin box widget.
Definition qspinbox.h:16
void setValue(int val)
Definition qspinbox.cpp:192
void textChanged(const QString &)
void valueChanged(int)
This signal is emitted whenever the spin box's value is changed.
void setMaximum(int max)
Definition qspinbox.cpp:363
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString trimmed() const &
Definition qstring.h:447
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
State
This enum type defines the states in which a validated string can exist.
Definition qvalidator.h:30
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
QString text
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint index
[2]
#define emit
#define Q_UNUSED(x)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
myObject disconnect()
[26]