Warning, /network/angelfish/lib/contents/ui/PrintPreview.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Michael Lang <criticaltemp@protonmail.com>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 import QtQuick 2.15
0006 import QtQuick.Controls 2.15 as QQC2
0007 import QtQuick.Layouts 1.15
0008 import QtWebEngine 1.10
0009 
0010 import org.kde.kirigami 2.19 as Kirigami
0011 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0012 
0013 import org.kde.angelfish 1.0
0014 
0015 Kirigami.OverlaySheet {
0016     id: printPreview
0017     parent: webEngineView
0018     topPadding: 0
0019     bottomPadding: 0
0020     leftPadding: 0
0021     rightPadding: 0
0022 
0023     header: Kirigami.Heading {
0024         text: i18n("Print")
0025     }
0026 
0027     contentItem: Loader {
0028         active: printPreview.opened
0029         sourceComponent: RowLayout {
0030             height: webEngineView.height - printPreview.header.height - Kirigami.Units.largeSpacing * 4
0031             spacing: 1
0032 
0033             Item {
0034                 Layout.preferredWidth: webEngineView.width / 2
0035                 Layout.fillHeight: true
0036 
0037                 WebEngineView {
0038                     id: webEnginePreview
0039                     visible: !webEngineView.generatingPdf
0040                     anchors.fill: parent
0041                     url: webEngineView.printPreviewUrl
0042                     settings.pluginsEnabled: true
0043                     settings.pdfViewerEnabled: true
0044                     settings.javascriptEnabled: false
0045                     onContextMenuRequested: request.accepted = true // disable context menu
0046                     onPdfPrintingFinished: printPreview.close()
0047                 }
0048 
0049                 QQC2.BusyIndicator {
0050                     visible: webEngineView.generatingPdf
0051                     anchors.centerIn: parent
0052                 }
0053             }
0054 
0055             ColumnLayout {
0056                 Layout.preferredWidth:  Kirigami.Units.gridUnit * 12
0057                 Layout.fillHeight: true
0058                 Layout.alignment: Qt.AlignTop
0059 
0060                 FormCard.FormCard {
0061                     Layout.fillWidth: true
0062 
0063                     FormCard.FormHeader {
0064                         title: i18n("Destination")
0065                     }
0066 
0067                     FormCard.FormTextDelegate {
0068                         text: i18n("Save to PDF")
0069                     }
0070 
0071                     FormCard.FormDelegateSeparator {}
0072 
0073                     FormCard.FormHeader {
0074                         title: i18n("Orientation")
0075                     }
0076 
0077                     ColumnLayout {
0078                         FormCard.FormRadioDelegate {
0079                             text: "Portrait"
0080                             checked: webEngineView.printedPageOrientation === WebEngineView.Portrait
0081                             onClicked: {
0082                                 webEngineView.printedPageOrientation = WebEngineView.Portrait;
0083                                 webEngineView.printRequested();
0084                             }
0085                         }
0086                         FormCard.FormRadioDelegate {
0087                             text: "Landscape"
0088                             checked: webEngineView.printedPageOrientation === WebEngineView.Landscape
0089                             onClicked: {
0090                                 webEngineView.printedPageOrientation = WebEngineView.Landscape;
0091                                 webEngineView.printRequested();
0092                             }
0093                         }
0094                     }
0095 
0096                     FormCard.FormDelegateSeparator {}
0097 
0098                     FormCard.FormHeader {
0099                         title: i18n("Paper size")
0100                     }
0101 
0102                     FormCard.FormComboBoxDelegate {
0103                         textRole: "text"
0104                         valueRole: "value"
0105                         model: ListModel {
0106                             ListElement { text: "Executive"; value: WebEngineView.Executive }
0107                             ListElement { text: "Folio"; value: WebEngineView.Folio }
0108                             ListElement { text: "Ledger"; value: WebEngineView.Ledger }
0109                             ListElement { text: "Legal"; value: WebEngineView.Legal }
0110                             ListElement { text: "Letter"; value: WebEngineView.Letter }
0111                             ListElement { text: "Tabloid"; value: WebEngineView.Tabloid }
0112                             ListElement { text: "A0"; value: WebEngineView.A0 }
0113                             ListElement { text: "A1"; value: WebEngineView.A1 }
0114                             ListElement { text: "A2"; value: WebEngineView.A2 }
0115                             ListElement { text: "A3"; value: WebEngineView.A3 }
0116                             ListElement { text: "A4"; value: WebEngineView.A4 }
0117                             ListElement { text: "A5"; value: WebEngineView.A5 }
0118                             ListElement { text: "A6"; value: WebEngineView.A6 }
0119                             ListElement { text: "A7"; value: WebEngineView.A7 }
0120                             ListElement { text: "A8"; value: WebEngineView.A8 }
0121                             ListElement { text: "A9"; value: WebEngineView.A9 }
0122                             ListElement { text: "B0"; value: WebEngineView.B0 }
0123                             ListElement { text: "B1"; value: WebEngineView.B1 }
0124                             ListElement { text: "B2"; value: WebEngineView.B2 }
0125                             ListElement { text: "B3"; value: WebEngineView.B3 }
0126                             ListElement { text: "B4"; value: WebEngineView.B4 }
0127                             ListElement { text: "B5"; value: WebEngineView.B5 }
0128                             ListElement { text: "B6"; value: WebEngineView.B6 }
0129                             ListElement { text: "B7"; value: WebEngineView.B7 }
0130                             ListElement { text: "B8"; value: WebEngineView.B8 }
0131                             ListElement { text: "B9"; value: WebEngineView.B9 }
0132                             ListElement { text: "B10"; value: WebEngineView.B10 }
0133                         }
0134                         onActivated: {
0135                             webEngineView.printedPageSizeId = currentValue;
0136                             webEngineView.printRequested();
0137                         }
0138 
0139                         Component.onCompleted: currentIndex = indexOfValue(webEngineView.printedPageSizeId)
0140                     }
0141 
0142                     FormCard.FormDelegateSeparator {}
0143 
0144                     FormCard.FormHeader {
0145                         title: i18n("Options")
0146                     }
0147 
0148                     FormCard.FormCheckDelegate {
0149                         text: i18n("Print backgrounds")
0150                         checked: webEngineView.settings.printElementBackgrounds
0151                         onClicked: {
0152                             webEngineView.settings.printElementBackgrounds = checked;
0153                             webEngineView.printRequested();
0154                         }
0155                     }
0156                 }
0157 
0158                 Item { Layout.fillHeight: true }
0159 
0160                 Row {
0161                     spacing: Kirigami.Units.largeSpacing
0162                     QQC2.Button {
0163                         text: i18n("Cancel")
0164                         onClicked: printPreview.close()
0165                     }
0166 
0167                     QQC2.Button {
0168                         text: i18n("Save")
0169                         onClicked: {
0170                             const filePath = BrowserManager.downloadDirectory() + "/" + webEngineView.title + ".pdf";
0171                             webEnginePreview.printToPdf(filePath, webEnginePreview.printedPageSizeId, webEnginePreview.printedPageOrientation);
0172                         }
0173                     }
0174                 }
0175             }
0176         }
0177     }
0178 }