From 94f96d9ba1eae886f7a92c72384c24bf60fa7175 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 26 Aug 2019 10:13:55 +0200 Subject: 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 --- examples/pdf/multipage/viewer.qml | 12 +++++------- examples/pdf/pdfviewer/viewer.qml | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'examples') 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 @@ -192,16 +192,36 @@ ApplicationWindow { onAccepted: document.source = selectedFile } + 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 } -- cgit v1.2.3