harbour-seaprint/qml/pages/PrinterPage.qml

145 lines
6.3 KiB
QML
Raw Normal View History

2019-12-01 22:27:00 +03:00
import QtQuick 2.0
import Sailfish.Silica 1.0
2020-06-04 22:31:46 +03:00
import seaprint.mimer 1.0
2020-06-06 18:20:30 +03:00
import seaprint.ippmsg 1.0
2019-12-01 22:27:00 +03:00
import "utils.js" as Utils
Page {
id: page
property var printer
property var jobParams: new Object();
property string selectedFile
Component.onCompleted: {
console.log(JSON.stringify(printer.attrs))
}
// To enable PullDownMenu, place our content in a SilicaFlickable
SilicaFlickable {
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,
2020-06-07 15:33:35 +03:00
alwaysConvertSetting.value,
forceIncluDeDocumentFormatSetting.value,
removeRedundantConvertAttrsSetting.value)
2019-12-01 22:27:00 +03:00
}
}
}
ListModel {
id:mod
2020-06-06 18:20:30 +03:00
ListElement {name: "sides"; prettyName: qsTr("Sides"); tag: IppMsg.Enum}
ListElement {name: "media"; prettyName: qsTr("Print media"); tag: IppMsg.Keyword}
ListElement {name: "copies"; prettyName: qsTr("Copies"); tag: IppMsg.Integer}
// ListElement {name: "page-ranges"; prettyName: qsTr("Page range"); tag: IppMsg.IntegerRange}
ListElement {name: "print-color-mode"; prettyName: qsTr("Color mode"); tag: IppMsg.Enum}
// 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}
2019-12-01 22:27:00 +03:00
}
SilicaListView {
id: listView
model: mod
clip: true
anchors.fill: parent
width: parent.width
header: PageHeader {
id: pageHeader
title: printer.attrs["printer-name"].value
description: selectedFile
}
delegate: ListItem {
id: delegate
property alias loaderItem: loader.item
openMenuOnPressAndHold: false
Loader {
id: loader
anchors.fill: parent
onLoaded: {
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))
jobParams[name] = {tag: tag, value: choice};
console.log(JSON.stringify(jobParams));
})
}
2019-12-01 22:27:00 +03:00
}
Component.onCompleted: {
switch(tag) {
2020-06-06 18:20:30 +03:00
case IppMsg.Integer:
2019-12-17 23:10:05 +03:00
loader.setSource("../components/IntegerSetting.qml",
2019-12-01 22:27:00 +03:00
{name: name,
prettyName: prettyName,
tag: tag,
valid: printer.attrs.hasOwnProperty(name+"-supported"),
2019-12-01 22:27:00 +03:00
low: printer.attrs[name+"-supported"].value.low,
high: printer.attrs[name+"-supported"].value.high,
default_choice: printer.attrs[name+"-default"].value
})
break
2020-06-06 18:20:30 +03:00
case IppMsg.IntegerRange:
2019-12-17 23:10:05 +03:00
loader.setSource("../components/RangeSetting.qml",
2019-12-01 22:27:00 +03:00
{name: name,
prettyName: prettyName,
tag: tag,
valid: false //TODO printer.attrs.hasOwnProperty(name+"-supported"),
2019-12-01 22:27:00 +03:00
})
break
2020-06-06 18:20:30 +03:00
case IppMsg.Resolution:
case IppMsg.Enum:
case IppMsg.Keyword:
case IppMsg.MimeMediaType:
2019-12-17 23:10:05 +03:00
loader.setSource("../components/ChoiceSetting.qml",
2019-12-01 22:27:00 +03:00
{name: name,
prettyName: prettyName,
tag: tag,
valid: printer.attrs.hasOwnProperty(name+"-supported"),
choices: maybeSupplementChoices(name, printer.attrs[name+"-supported"].value),
2020-06-04 22:31:46 +03:00
default_choice: printer.attrs[name+"-default"].value,
mime_type: Mimer.get_type(selectedFile)
2019-12-01 22:27:00 +03:00
})
break
}
}
function maybeSupplementChoices(name, choices)
{
if(name == "document-format" && considerAdditionalFormatsSetting.value)
{
return choices.concat(printer.additionalDocumentFormats)
}
return choices
}
2019-12-01 22:27:00 +03:00
}
VerticalScrollDecorator {}
}
}
}