blob: 7d7e7b11e8809cdad0d3a4c7a715f638c58fd287 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qpdfpageselector.h"
#include "qpdfpageselector_p.h"
#include <QPdfDocument>
QT_BEGIN_NAMESPACE
QPdfPageSelectorPrivate::QPdfPageSelectorPrivate(QPdfPageSelector *q)
: q_ptr(q)
{
}
void QPdfPageSelectorPrivate::documentStatusChanged()
{
Q_Q(QPdfPageSelector);
if (!document.isNull() && document->status() == QPdfDocument::Status::Ready) {
q->setMaximum(document->pageCount());
q->setValue(0);
}
}
/*!
\class QPdfPageSelector
\inmodule QtPdf
\brief A QSpinBox for selecting a PDF page.
QPdfPageSelector is a QSpinBox specialized for selecting a page label
from a QPdfDocument.
\sa QPdfDocument::pageLabel()
*/
/*!
Constructs a PDF page selector with parent widget \a parent.
*/
QPdfPageSelector::QPdfPageSelector(QWidget *parent)
: QSpinBox(parent)
, d_ptr(new QPdfPageSelectorPrivate(this))
{
}
/*!
Destroys the page selector.
*/
QPdfPageSelector::~QPdfPageSelector()
{
}
/*!
\property QPdfPageSelector::document
This property holds the document to be viewed.
*/
void QPdfPageSelector::setDocument(QPdfDocument *document)
{
Q_D(QPdfPageSelector);
if (d->document == document)
return;
if (d->document)
disconnect(d->documentStatusChangedConnection);
d->document = document;
emit documentChanged(d->document);
if (d->document)
d->documentStatusChangedConnection =
connect(d->document.data(), &QPdfDocument::statusChanged, this,
[d](){ d->documentStatusChanged(); });
d->documentStatusChanged();
}
QPdfDocument *QPdfPageSelector::document() const
{
Q_D(const QPdfPageSelector);
return d->document;
}
int QPdfPageSelector::valueFromText(const QString &text) const
{
Q_D(const QPdfPageSelector);
if (d->document.isNull())
return 0;
return d->document->pageIndexForLabel(text.trimmed());
}
QString QPdfPageSelector::textFromValue(int value) const
{
Q_D(const QPdfPageSelector);
if (d->document.isNull())
return {};
return d->document->pageLabel(value);
}
QValidator::State QPdfPageSelector::validate(QString &text, int &pos) const
{
Q_UNUSED(pos);
return valueFromText(text) >= 0 ? QValidator::Acceptable : QValidator::Intermediate;
}
QT_END_NAMESPACE
#include "moc_qpdfpageselector.cpp"
|