diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-08-26 10:13:55 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-03-07 17:40:20 +0100 |
commit | 94f96d9ba1eae886f7a92c72384c24bf60fa7175 (patch) | |
tree | 5869fa82414b28496e298c0ff33f94d393db56f7 /examples/pdf | |
parent | 85f82185ef5102a2dbe3b2e437b9723e1652ce57 (diff) |
PDF viewer and manual test: support password-protected documents
The multipage example was OK already; this adds the same password-prompt
dialog to the single-page-at-a-time pdfviewer example and to the
withdoc.qml manual test. Also, the dialogs seem to size themselves
better if we explicitly set the contentItem properties. And an
error dialog should not have an OK button but a Close button:
the error is not OK, but the example does not provide a way to
try to fix it either.
Fixes: QTBUG-83988
Fixes: QTBUG-96574
Change-Id: I9d8c3cbe1f955cea4319982869ec9180d7c8666c
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples/pdf')
-rw-r--r-- | examples/pdf/multipage/viewer.qml | 12 | ||||
-rw-r--r-- | examples/pdf/pdfviewer/viewer.qml | 25 |
2 files changed, 28 insertions, 9 deletions
diff --git a/examples/pdf/multipage/viewer.qml b/examples/pdf/multipage/viewer.qml index f0eb4a432..51b648378 100644 --- a/examples/pdf/multipage/viewer.qml +++ b/examples/pdf/multipage/viewer.qml @@ -199,26 +199,27 @@ ApplicationWindow { anchors.centerIn: parent width: 300 - TextField { + contentItem: TextField { id: passwordField placeholderText: qsTr("Please provide the password") echoMode: TextInput.Password width: parent.width onAccepted: passwordDialog.accept() } + onOpened: function() { passwordField.forceActiveFocus() } onAccepted: document.password = passwordField.text } Dialog { id: errorDialog title: "Error loading " + document.source - standardButtons: Dialog.Ok + standardButtons: Dialog.Close modal: true closePolicy: Popup.CloseOnEscape anchors.centerIn: parent width: 300 - Label { + contentItem: Label { id: errorField text: document.error } @@ -231,10 +232,7 @@ ApplicationWindow { if (status === PdfDocument.Error) errorDialog.open() view.document = (status === PdfDocument.Ready ? document : null) } - onPasswordRequired: { - passwordDialog.open() - passwordField.forceActiveFocus() - } + onPasswordRequired: function() { passwordDialog.open() } } PdfMultiPageView { diff --git a/examples/pdf/pdfviewer/viewer.qml b/examples/pdf/pdfviewer/viewer.qml index c174a79ed..0454d533f 100644 --- a/examples/pdf/pdfviewer/viewer.qml +++ b/examples/pdf/pdfviewer/viewer.qml @@ -193,15 +193,35 @@ ApplicationWindow { } Dialog { + id: passwordDialog + title: "Password" + standardButtons: Dialog.Ok | Dialog.Cancel + modal: true + closePolicy: Popup.CloseOnEscape + anchors.centerIn: parent + width: 300 + + contentItem: TextField { + id: passwordField + placeholderText: qsTr("Please provide the password") + echoMode: TextInput.Password + width: parent.width + onAccepted: passwordDialog.accept() + } + onOpened: function() { passwordField.forceActiveFocus() } + onAccepted: document.password = passwordField.text + } + + Dialog { id: errorDialog title: "Error loading " + document.source - standardButtons: Dialog.Ok + standardButtons: Dialog.Close modal: true closePolicy: Popup.CloseOnEscape anchors.centerIn: parent width: 300 - Label { + contentItem: Label { id: errorField text: document.error } @@ -215,6 +235,7 @@ ApplicationWindow { id: document source: Qt.resolvedUrl(root.source) onStatusChanged: if (status === PdfDocument.Error) errorDialog.open() + onPasswordRequired: passwordDialog.open() } searchString: searchField.text } |