From ef1fc4b7424798262880e1447f121d7457c10feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Mon, 23 Nov 2020 18:34:38 +0100 Subject: [PATCH] refactor printer page: replace SilicaListView by Column --- qml/components/ChoiceSetting.qml | 8 +- qml/components/IntegerSetting.qml | 11 +- qml/components/MediaColSetting.qml | 9 +- qml/components/RangeSetting.qml | 9 +- qml/components/Setting.qml | 2 +- qml/pages/PrinterPage.qml | 246 +++++++++++++++-------------- 6 files changed, 155 insertions(+), 130 deletions(-) diff --git a/qml/components/ChoiceSetting.qml b/qml/components/ChoiceSetting.qml index e60f547..f4589db 100644 --- a/qml/components/ChoiceSetting.qml +++ b/qml/components/ChoiceSetting.qml @@ -4,6 +4,9 @@ import seaprint.convertchecker 1.0 import "../pages/utils.js" as Utils Setting { + id: settingEntry + height: button.height + menu.height + property var choices property string mime_type @@ -12,8 +15,8 @@ Setting { property int num_large_choices: 8 ValueButton { + id: button enabled: valid - anchors.verticalCenter: parent.verticalCenter label: prettyName value: Utils.ippName(name, choice ? choice : default_choice) onClicked: parent.clicked() @@ -28,9 +31,10 @@ Setting { choice = dialog.choice }) } + menu.open(settingEntry) } - property var menu: ContextMenu { + ContextMenu { id: menu enabled: valid && limited_choices.length <= num_large_choices Repeater { diff --git a/qml/components/IntegerSetting.qml b/qml/components/IntegerSetting.qml index 02d50cb..3095405 100644 --- a/qml/components/IntegerSetting.qml +++ b/qml/components/IntegerSetting.qml @@ -2,19 +2,26 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 Setting { + id: settingEntry + height: button.height + menu.height property int low property int high ValueButton { + id: button enabled: valid - anchors.verticalCenter: parent.verticalCenter label: prettyName value: choice ? choice : default_choice onClicked: parent.clicked() + Component.onCompleted: { + console.log("button height: " + button.height) + } } - property var menu: ContextMenu { + onClicked: menu.open(settingEntry) + + ContextMenu { id: menu enabled: valid MenuItem { diff --git a/qml/components/MediaColSetting.qml b/qml/components/MediaColSetting.qml index 026da5f..c2667d8 100644 --- a/qml/components/MediaColSetting.qml +++ b/qml/components/MediaColSetting.qml @@ -5,6 +5,9 @@ import seaprint.ippmsg 1.0 import "../pages/utils.js" as Utils Setting { + id: settingEntry + + height: button.height + menu.height property var printer Component.onCompleted: { @@ -18,14 +21,16 @@ Setting { } ValueButton { + id: button enabled: valid - anchors.verticalCenter: parent.verticalCenter label: prettyName value: choice ? qsTr("true") : qsTr("false") onClicked: parent.clicked() } - property var menu: ContextMenu { + onClicked: menu.open(settingEntry) + + ContextMenu { id: menu enabled: true MenuItem { diff --git a/qml/components/RangeSetting.qml b/qml/components/RangeSetting.qml index 2a1d932..2e99f5f 100644 --- a/qml/components/RangeSetting.qml +++ b/qml/components/RangeSetting.qml @@ -2,6 +2,9 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 Setting { + id: settingEntry + + height: button.height + menu.height property int high property int choice_low: 1 @@ -34,14 +37,16 @@ Setting { } ValueButton { + id: button enabled: valid - anchors.verticalCenter: parent.verticalCenter label: prettyName value: choice_high==0 ? qsTr("all") : ""+choice_low+" - "+choice_high onClicked: parent.clicked() } - property var menu: ContextMenu { + onClicked: menu.open(settingEntry) + + ContextMenu { id: menu enabled: valid diff --git a/qml/components/Setting.qml b/qml/components/Setting.qml index e8832a6..f4d07a7 100644 --- a/qml/components/Setting.qml +++ b/qml/components/Setting.qml @@ -2,7 +2,7 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 Item { - anchors.verticalCenter: parent.verticalCenter + width: parent.width property string name property string prettyName diff --git a/qml/pages/PrinterPage.qml b/qml/pages/PrinterPage.qml index 9de3746..03c5e0d 100644 --- a/qml/pages/PrinterPage.qml +++ b/qml/pages/PrinterPage.qml @@ -4,6 +4,7 @@ import seaprint.mimer 1.0 import seaprint.ippmsg 1.0 import seaprint.convertchecker 1.0 import "utils.js" as Utils +import "../components" Page { allowedOrientations: Orientation.All @@ -19,143 +20,146 @@ Page { // To enable PullDownMenu, place our content in a SilicaFlickable SilicaFlickable { - anchors.fill: parent + anchors.fill: parent - // PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView - PullDownMenu { - MenuItem { - text: qsTr("Print") - onClicked: { - console.log(JSON.stringify(jobParams)) - pageStack.replace(Qt.resolvedUrl("BusyPage.qml"),{printer:printer}, - PageStackAction.Immediate) - printer.print(jobParams, page.selectedFile, - alwaysConvertSetting.value, - alwaysUseMediaColSetting.value) - } + // PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView + PullDownMenu { + MenuItem { + text: qsTr("Print") + onClicked: { + console.log(JSON.stringify(jobParams)) + pageStack.replace(Qt.resolvedUrl("BusyPage.qml"),{printer:printer}, + PageStackAction.Immediate) + printer.print(jobParams, page.selectedFile, + alwaysConvertSetting.value, + alwaysUseMediaColSetting.value) } } - - ListModel { - id:mod - ListElement {name: "sides"; prettyName: qsTr("Sides"); tag: IppMsg.Keyword} - ListElement {name: "media"; prettyName: qsTr("Print media"); tag: IppMsg.Keyword} - ListElement {name: "copies"; prettyName: qsTr("Copies"); tag: IppMsg.Integer} - ListElement {name: "multiple-document-handling"; prettyName: qsTr("Collated copies"); tag: IppMsg.Keyword} - ListElement {name: "page-ranges"; prettyName: qsTr("Page range"); tag: IppMsg.IntegerRange} - ListElement {name: "print-color-mode"; prettyName: qsTr("Color mode"); tag: IppMsg.Keyword} -// ListElement {name: "orientation-requested"; prettyName: qsTr("Orientation"); tag: IppMsg.Enum} - ListElement {name: "print-quality"; prettyName: qsTr("Quality"); tag: IppMsg.Enum} - ListElement {name: "printer-resolution"; prettyName: qsTr("Resolution"); tag: IppMsg.Resolution} - ListElement {name: "document-format"; prettyName: qsTr("Transfer format"); tag: IppMsg.MimeMediaType} - ListElement {name: "media-source"; prettyName: qsTr("Media source"); tag: IppMsg.Keyword} - ListElement {name: "media-col"; prettyName: qsTr("Zero margins"); tag: IppMsg.BeginCollection} } - SilicaListView { - id: listView - model: mod - clip: true + VerticalScrollDecorator {} - anchors.fill: parent + Column { + id: settingColumn width: parent.width - header: PageHeader { + + PageHeader { id: pageHeader title: printer.attrs["printer-name"].value description: selectedFile - } + Item { + id: utils - - delegate: ListItem { - id: delegate - property alias loaderItem: loader.item - - openMenuOnPressAndHold: false - - Loader { - id: loader - anchors.fill: parent - - onLoaded: { - delegate.visible = true - if(loaderItem.menu.enabled) - { - menu = loaderItem.menu - loaderItem.clicked.connect(openMenu) - } - loaderItem.choiceMade.connect(function(tag, choice) { - console.log("choice changed", tag, JSON.stringify(choice)) - if(choice != undefined) - { - jobParams[name] = {tag: tag, value: choice}; - } - else - { - jobParams[name] = undefined - } - console.log(JSON.stringify(jobParams)); - }) - } + function isValid(name) { + return printer.attrs.hasOwnProperty(name+"-supported"); } - - Component.onCompleted: { - switch(tag) { - case IppMsg.Integer: - var valid = printer.attrs.hasOwnProperty(name+"-supported") - loader.setSource("../components/IntegerSetting.qml", - {name: name, - prettyName: prettyName, - tag: tag, - valid: valid, - low: valid ? printer.attrs[name+"-supported"].value.low : 0, - high: valid ? printer.attrs[name+"-supported"].value.high : 0, - default_choice: printer.attrs.hasOwnProperty(name+"-default") ? printer.attrs[name+"-default"].value : undefined - }) - break - case IppMsg.IntegerRange: - var valid = (printer.attrs.hasOwnProperty(name+"-supported") || ConvertChecker.pdf)&& - name=="page-ranges" && Mimer.get_type(selectedFile) == "application/pdf"; - var pdfpages = ConvertChecker.pdfPages(selectedFile); - loader.setSource("../components/RangeSetting.qml", - {name: name, - prettyName: prettyName, - tag: tag, - valid: valid, - high: name=="page-ranges" ? (pdfpages == 0 ? 65535 : pdfpages) : 0 - }) - break - case IppMsg.Resolution: - case IppMsg.Enum: - case IppMsg.Keyword: - case IppMsg.MimeMediaType: - var valid = printer.attrs.hasOwnProperty(name+"-supported") - loader.setSource("../components/ChoiceSetting.qml", - {name: name, - prettyName: prettyName, - tag: tag, - valid: valid, - choices: valid ? printer.attrs[name+"-supported"].value : [], - default_choice: printer.attrs.hasOwnProperty(name+"-default") ? printer.attrs[name+"-default"].value : "", - mime_type: Mimer.get_type(selectedFile) - }) - break - case IppMsg.BeginCollection: - loader.setSource("../components/MediaColSetting.qml", - {name: name, - prettyName: prettyName, - tag: tag, - valid: false, - printer: printer - }) - } + function getChoices(name) { + return isValid(name) ? printer.attrs[name+"-supported"].value : []; + } + function getDefaultChoice(name) { + return printer.attrs.hasOwnProperty(name+"-default") ? printer.attrs[name+"-default"].value : ""; } - } - VerticalScrollDecorator {} + + ChoiceSetting { + tag: IppMsg.Keyword + name: "sides" + prettyName: qsTr("Sides") + valid: utils.isValid(name) + choices: utils.getChoices(name) + default_choice: utils.getDefaultChoice(name) + mime_type: Mimer.get_type(selectedFile) + } + ChoiceSetting { + tag: IppMsg.Keyword + name: "media" + prettyName: qsTr("Print media") + valid: utils.isValid(name) + choices: utils.getChoices(name) + default_choice: utils.getDefaultChoice(name) + mime_type: Mimer.get_type(selectedFile) + } + IntegerSetting { + tag: IppMsg.Integer + name: "copies" + prettyName: qsTr("Copies") + valid: utils.isValid(name) + low: valid ? printer.attrs[name+"-supported"].value.low : 0 + high: valid ? printer.attrs[name+"-supported"].value.high : 0 + default_choice: printer.attrs.hasOwnProperty(name+"-default") ? printer.attrs[name+"-default"].value : undefined + } + ChoiceSetting { + tag: IppMsg.Keyword + name: "multiple-document-handling" + prettyName: qsTr("Collated copies") + valid: utils.isValid(name) + choices: utils.getChoices(name) + default_choice: utils.getDefaultChoice(name) + mime_type: Mimer.get_type(selectedFile) + } + RangeSetting { + tag: IppMsg.IntegerRange + name: "page-ranges" + prettyName: qsTr("Page range") + valid: (utils.isValid(name) || ConvertChecker.pdf) && Mimer.get_type(selectedFile) == "application/pdf" + + property var pdfpages: ConvertChecker.pdfPages(selectedFile) + high: name=="page-ranges" ? (pdfpages == 0 ? 65535 : pdfpages) : 0 + } + ChoiceSetting { + tag: IppMsg.Keyword + name: "print-color-mode" + prettyName: qsTr("Color mode") + valid: utils.isValid(name) + choices: utils.getChoices(name) + default_choice: utils.getDefaultChoice(name) + mime_type: Mimer.get_type(selectedFile) + } + ChoiceSetting { + tag: IppMsg.Enum + name: "print-quality" + prettyName: qsTr("Quality") + valid: utils.isValid(name) + choices: utils.getChoices(name) + default_choice: utils.getDefaultChoice(name) + mime_type: Mimer.get_type(selectedFile) + } + ChoiceSetting { + tag: IppMsg.Resolution + name: "printer-resolution" + prettyName: qsTr("Resolution") + valid: utils.isValid(name) + choices: utils.getChoices(name) + default_choice: utils.getDefaultChoice(name) + mime_type: Mimer.get_type(selectedFile) + } + ChoiceSetting { + tag: IppMsg.MimeMediaType + name: "document-format" + prettyName: qsTr("Transfer format") + valid: utils.isValid(name) + choices: utils.getChoices(name) + default_choice: utils.getDefaultChoice(name) + mime_type: Mimer.get_type(selectedFile) + } + ChoiceSetting { + tag: IppMsg.Keyword + name: "media-source" + prettyName: qsTr("Media source") + valid: utils.isValid(name) + choices: utils.getChoices(name) + default_choice: utils.getDefaultChoice(name) + mime_type: Mimer.get_type(selectedFile) + } + MediaColSetting { + tag: IppMsg.BeginCollection + name: "media-col" + prettyName: qsTr("Zero margins") + valid: false + printer: page.printer + } } - } - }