refactor printer page: replace SilicaListView by Column
This commit is contained in:
parent
5c6a2a824c
commit
ef1fc4b742
6 changed files with 155 additions and 130 deletions
|
@ -4,6 +4,9 @@ import seaprint.convertchecker 1.0
|
||||||
import "../pages/utils.js" as Utils
|
import "../pages/utils.js" as Utils
|
||||||
|
|
||||||
Setting {
|
Setting {
|
||||||
|
id: settingEntry
|
||||||
|
height: button.height + menu.height
|
||||||
|
|
||||||
property var choices
|
property var choices
|
||||||
property string mime_type
|
property string mime_type
|
||||||
|
|
||||||
|
@ -12,8 +15,8 @@ Setting {
|
||||||
property int num_large_choices: 8
|
property int num_large_choices: 8
|
||||||
|
|
||||||
ValueButton {
|
ValueButton {
|
||||||
|
id: button
|
||||||
enabled: valid
|
enabled: valid
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
label: prettyName
|
label: prettyName
|
||||||
value: Utils.ippName(name, choice ? choice : default_choice)
|
value: Utils.ippName(name, choice ? choice : default_choice)
|
||||||
onClicked: parent.clicked()
|
onClicked: parent.clicked()
|
||||||
|
@ -28,9 +31,10 @@ Setting {
|
||||||
choice = dialog.choice
|
choice = dialog.choice
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
menu.open(settingEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
property var menu: ContextMenu {
|
ContextMenu {
|
||||||
id: menu
|
id: menu
|
||||||
enabled: valid && limited_choices.length <= num_large_choices
|
enabled: valid && limited_choices.length <= num_large_choices
|
||||||
Repeater {
|
Repeater {
|
||||||
|
|
|
@ -2,19 +2,26 @@ import QtQuick 2.0
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
|
|
||||||
Setting {
|
Setting {
|
||||||
|
id: settingEntry
|
||||||
|
height: button.height + menu.height
|
||||||
|
|
||||||
property int low
|
property int low
|
||||||
property int high
|
property int high
|
||||||
|
|
||||||
ValueButton {
|
ValueButton {
|
||||||
|
id: button
|
||||||
enabled: valid
|
enabled: valid
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
label: prettyName
|
label: prettyName
|
||||||
value: choice ? choice : default_choice
|
value: choice ? choice : default_choice
|
||||||
onClicked: parent.clicked()
|
onClicked: parent.clicked()
|
||||||
|
Component.onCompleted: {
|
||||||
|
console.log("button height: " + button.height)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
property var menu: ContextMenu {
|
onClicked: menu.open(settingEntry)
|
||||||
|
|
||||||
|
ContextMenu {
|
||||||
id: menu
|
id: menu
|
||||||
enabled: valid
|
enabled: valid
|
||||||
MenuItem {
|
MenuItem {
|
||||||
|
|
|
@ -5,6 +5,9 @@ import seaprint.ippmsg 1.0
|
||||||
import "../pages/utils.js" as Utils
|
import "../pages/utils.js" as Utils
|
||||||
|
|
||||||
Setting {
|
Setting {
|
||||||
|
id: settingEntry
|
||||||
|
|
||||||
|
height: button.height + menu.height
|
||||||
property var printer
|
property var printer
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
@ -18,14 +21,16 @@ Setting {
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueButton {
|
ValueButton {
|
||||||
|
id: button
|
||||||
enabled: valid
|
enabled: valid
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
label: prettyName
|
label: prettyName
|
||||||
value: choice ? qsTr("true") : qsTr("false")
|
value: choice ? qsTr("true") : qsTr("false")
|
||||||
onClicked: parent.clicked()
|
onClicked: parent.clicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
property var menu: ContextMenu {
|
onClicked: menu.open(settingEntry)
|
||||||
|
|
||||||
|
ContextMenu {
|
||||||
id: menu
|
id: menu
|
||||||
enabled: true
|
enabled: true
|
||||||
MenuItem {
|
MenuItem {
|
||||||
|
|
|
@ -2,6 +2,9 @@ import QtQuick 2.0
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
|
|
||||||
Setting {
|
Setting {
|
||||||
|
id: settingEntry
|
||||||
|
|
||||||
|
height: button.height + menu.height
|
||||||
|
|
||||||
property int high
|
property int high
|
||||||
property int choice_low: 1
|
property int choice_low: 1
|
||||||
|
@ -34,14 +37,16 @@ Setting {
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueButton {
|
ValueButton {
|
||||||
|
id: button
|
||||||
enabled: valid
|
enabled: valid
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
label: prettyName
|
label: prettyName
|
||||||
value: choice_high==0 ? qsTr("all") : ""+choice_low+" - "+choice_high
|
value: choice_high==0 ? qsTr("all") : ""+choice_low+" - "+choice_high
|
||||||
onClicked: parent.clicked()
|
onClicked: parent.clicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
property var menu: ContextMenu {
|
onClicked: menu.open(settingEntry)
|
||||||
|
|
||||||
|
ContextMenu {
|
||||||
id: menu
|
id: menu
|
||||||
enabled: valid
|
enabled: valid
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import QtQuick 2.0
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
width: parent.width
|
||||||
|
|
||||||
property string name
|
property string name
|
||||||
property string prettyName
|
property string prettyName
|
||||||
|
|
|
@ -4,6 +4,7 @@ import seaprint.mimer 1.0
|
||||||
import seaprint.ippmsg 1.0
|
import seaprint.ippmsg 1.0
|
||||||
import seaprint.convertchecker 1.0
|
import seaprint.convertchecker 1.0
|
||||||
import "utils.js" as Utils
|
import "utils.js" as Utils
|
||||||
|
import "../components"
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
allowedOrientations: Orientation.All
|
allowedOrientations: Orientation.All
|
||||||
|
@ -19,143 +20,146 @@ Page {
|
||||||
|
|
||||||
// To enable PullDownMenu, place our content in a SilicaFlickable
|
// To enable PullDownMenu, place our content in a SilicaFlickable
|
||||||
SilicaFlickable {
|
SilicaFlickable {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
|
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
|
||||||
PullDownMenu {
|
PullDownMenu {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: qsTr("Print")
|
text: qsTr("Print")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
console.log(JSON.stringify(jobParams))
|
console.log(JSON.stringify(jobParams))
|
||||||
pageStack.replace(Qt.resolvedUrl("BusyPage.qml"),{printer:printer},
|
pageStack.replace(Qt.resolvedUrl("BusyPage.qml"),{printer:printer},
|
||||||
PageStackAction.Immediate)
|
PageStackAction.Immediate)
|
||||||
printer.print(jobParams, page.selectedFile,
|
printer.print(jobParams, page.selectedFile,
|
||||||
alwaysConvertSetting.value,
|
alwaysConvertSetting.value,
|
||||||
alwaysUseMediaColSetting.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 {
|
VerticalScrollDecorator {}
|
||||||
id: listView
|
|
||||||
model: mod
|
|
||||||
clip: true
|
|
||||||
|
|
||||||
anchors.fill: parent
|
Column {
|
||||||
|
id: settingColumn
|
||||||
width: parent.width
|
width: parent.width
|
||||||
header: PageHeader {
|
|
||||||
|
PageHeader {
|
||||||
id: pageHeader
|
id: pageHeader
|
||||||
title: printer.attrs["printer-name"].value
|
title: printer.attrs["printer-name"].value
|
||||||
description: selectedFile
|
description: selectedFile
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: utils
|
||||||
|
|
||||||
|
function isValid(name) {
|
||||||
delegate: ListItem {
|
return printer.attrs.hasOwnProperty(name+"-supported");
|
||||||
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 getChoices(name) {
|
||||||
Component.onCompleted: {
|
return isValid(name) ? printer.attrs[name+"-supported"].value : [];
|
||||||
switch(tag) {
|
}
|
||||||
case IppMsg.Integer:
|
function getDefaultChoice(name) {
|
||||||
var valid = printer.attrs.hasOwnProperty(name+"-supported")
|
return printer.attrs.hasOwnProperty(name+"-default") ? printer.attrs[name+"-default"].value : "";
|
||||||
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue