Merge pull request #43 from Karry/printer-page-refactoring
refactor printer page: replace SilicaListView by Column
This commit is contained in:
commit
ec0f7848b9
6 changed files with 155 additions and 130 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -36,126 +37,129 @@ Page {
|
|||
}
|
||||
}
|
||||
|
||||
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}
|
||||
}
|
||||
VerticalScrollDecorator {}
|
||||
|
||||
SilicaListView {
|
||||
id: listView
|
||||
model: mod
|
||||
clip: true
|
||||
|
||||
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)
|
||||
function isValid(name) {
|
||||
return printer.attrs.hasOwnProperty(name+"-supported");
|
||||
}
|
||||
loaderItem.choiceMade.connect(function(tag, choice) {
|
||||
console.log("choice changed", tag, JSON.stringify(choice))
|
||||
if(choice != undefined)
|
||||
{
|
||||
jobParams[name] = {tag: tag, value: choice};
|
||||
function getChoices(name) {
|
||||
return isValid(name) ? printer.attrs[name+"-supported"].value : [];
|
||||
}
|
||||
else
|
||||
{
|
||||
jobParams[name] = undefined
|
||||
}
|
||||
console.log(JSON.stringify(jobParams));
|
||||
})
|
||||
function getDefaultChoice(name) {
|
||||
return printer.attrs.hasOwnProperty(name+"-default") ? printer.attrs[name+"-default"].value : "";
|
||||
}
|
||||
}
|
||||
|
||||
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 : "",
|
||||
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)
|
||||
})
|
||||
break
|
||||
case IppMsg.BeginCollection:
|
||||
loader.setSource("../components/MediaColSetting.qml",
|
||||
{name: name,
|
||||
prettyName: prettyName,
|
||||
tag: tag,
|
||||
valid: false,
|
||||
printer: printer
|
||||
})
|
||||
}
|
||||
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
|
||||
}
|
||||
VerticalScrollDecorator {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue