Show context menu at the right times

Contributes to CL-1126
This commit is contained in:
Ian Paschal 2018-11-06 16:37:47 +01:00
parent 1abd0b3499
commit dc4b69c386
2 changed files with 42 additions and 7 deletions

View file

@ -34,7 +34,13 @@ Item {
hoverEnabled: true; hoverEnabled: true;
onClicked: parent.switchPopupState(); onClicked: parent.switchPopupState();
text: "\u22EE"; //Unicode; Three stacked points. text: "\u22EE"; //Unicode; Three stacked points.
visible: printJob.state == "queued" || printJob.state == "aborted" || started ? true : false; visible: {
if (!printJob) {
return false;
}
var states = ["queued", "sent_to_printer", "pre_print", "printing", "pausing", "paused", "resuming"];
return states.indexOf(printJob.state) !== -1;
}
width: 35 * screenScaleFactor; // TODO: Theme! width: 35 * screenScaleFactor; // TODO: Theme!
} }
@ -123,11 +129,17 @@ Item {
popup.close(); popup.close();
} }
text: catalog.i18nc("@label", "Delete"); text: catalog.i18nc("@label", "Delete");
visible: printJob && !started && printJob.state !== "aborted" && printJob.state !== "finished"; visible: {
if (!printJob) {
return false;
}
var states = ["queued", "sent_to_printer"];
return states.indexOf(printJob.state) !== -1;
}
} }
PrintJobContextMenuItem { PrintJobContextMenuItem {
enabled: !(printJob.state == "pausing" || printJob.state == "resuming"); enabled: visible && !(printJob.state == "pausing" || printJob.state == "resuming");
onClicked: { onClicked: {
if (printJob.state == "paused") { if (printJob.state == "paused") {
printJob.setState("print"); printJob.setState("print");
@ -155,17 +167,29 @@ Item {
catalog.i18nc("@label", "Pause"); catalog.i18nc("@label", "Pause");
} }
} }
visible: printJob && started && printJob.state; visible: {
if (!printJob) {
return false;
}
var states = ["printing", "pausing", "paused", "resuming"];
return states.indexOf(printJob.state) !== -1;
}
} }
PrintJobContextMenuItem { PrintJobContextMenuItem {
enabled: printJob.state !== "aborting"; enabled: visible && printJob.state !== "aborting";
onClicked: { onClicked: {
abortConfirmationDialog.visible = true; abortConfirmationDialog.visible = true;
popup.close(); popup.close();
} }
text: printJob.state == "aborting" ? catalog.i18nc("@label", "Aborting...") : catalog.i18nc("@label", "Abort"); text: printJob.state == "aborting" ? catalog.i18nc("@label", "Aborting...") : catalog.i18nc("@label", "Abort");
visible: printJob && started; visible: {
if (!printJob) {
return false;
}
var states = ["pre_print", "printing", "pausing", "paused", "resuming"];
return states.indexOf(printJob.state) !== -1;
}
} }
} }
enter: Transition { enter: Transition {
@ -224,6 +248,8 @@ Item {
// Utils // Utils
function switchPopupState() { function switchPopupState() {
popup.visible ? popup.close() : popup.open(); popup.visible ? popup.close() : popup.open();
console.log("printJob.state is:", printJob.state);
console.log("children.length is:", getMenuLength());
} }
function isStarted(job) { function isStarted(job) {
if (!job) { if (!job) {
@ -237,4 +263,13 @@ Item {
} }
return job.assignedPrinter ? true : false; return job.assignedPrinter ? true : false;
} }
function getMenuLength() {
var visible = 0;
for (var i = 0; i < popupOptions.children.length; i++) {
if (popupOptions.children[i].visible) {
visible++;
}
}
return visible;
}
} }

View file

@ -17,7 +17,7 @@ Button {
horizontalAlignment: Text.AlignLeft; horizontalAlignment: Text.AlignLeft;
verticalAlignment: Text.AlignVCenter; verticalAlignment: Text.AlignVCenter;
} }
height: 39 * screenScaleFactor; // TODO: Theme! height: visible ? 39 * screenScaleFactor : 0; // TODO: Theme!
hoverEnabled: true; hoverEnabled: true;
width: parent.width; width: parent.width;
} }