mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-11-02 20:52:20 -07:00
Update API of Printer output device handling so we can handle multiple devices
This commit is contained in:
parent
dab74e524a
commit
a4b09d3dac
3 changed files with 130 additions and 32 deletions
|
|
@ -13,9 +13,38 @@ Button {
|
|||
property real progress: UM.Backend.progress;
|
||||
Behavior on progress { NumberAnimation { duration: 250; } }
|
||||
|
||||
enabled: progress >= 0.95;
|
||||
// enabled: progress >= 0.95;
|
||||
|
||||
iconSource: UM.Theme.icons[Printer.outputDeviceIcon];
|
||||
property string currentDevice: 'local_file'
|
||||
property bool defaultOverride: false;
|
||||
property bool defaultAmbiguous: false;
|
||||
|
||||
iconSource: UM.Theme.icons[Printer.outputDevices[base.currentDevice].icon];
|
||||
tooltip: Printer.outputDevices[base.currentDevice].description;
|
||||
|
||||
Connections {
|
||||
target: Printer;
|
||||
onOutputDevicesChanged: {
|
||||
if(!base.defaultOverride) {
|
||||
base.defaultAmbiguous = false;
|
||||
var device = null;
|
||||
for(var i in Printer.outputDevices) {
|
||||
console.log(i);
|
||||
if(device == null) {
|
||||
device = i;
|
||||
} else if(Printer.outputDevices[i].priority > Printer.outputDevices[device].priority) {
|
||||
device = i;
|
||||
} else if(Printer.outputDevices[i].priority == Printer.outputDevices[device].priority) {
|
||||
base.defaultAmbiguous = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(device != null) {
|
||||
base.currentDevice = device;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
style: ButtonStyle {
|
||||
background: UM.AngledCornerRectangle {
|
||||
|
|
@ -101,6 +130,40 @@ Button {
|
|||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent;
|
||||
|
||||
acceptedButtons: Qt.RightButton;
|
||||
|
||||
onClicked: devicesMenu.popup();
|
||||
}
|
||||
|
||||
Menu {
|
||||
id: devicesMenu;
|
||||
|
||||
Instantiator {
|
||||
model: Printer.outputDeviceNames;
|
||||
MenuItem {
|
||||
text: Printer.outputDevices[modelData].description;
|
||||
checkable: true;
|
||||
checked: base.defaultAmbiguous ? false : modelData == base.currentDevice;
|
||||
exclusiveGroup: devicesMenuGroup;
|
||||
onTriggered: {
|
||||
base.defaultOverride = true;
|
||||
base.currentDevice = modelData;
|
||||
if(base.defaultAmbiguous) {
|
||||
base.defaultAmbiguous = false;
|
||||
Printer.writeToOutputDevice(modelData);
|
||||
}
|
||||
}
|
||||
}
|
||||
onObjectAdded: devicesMenu.insertItem(index, object)
|
||||
onObjectRemoved: devicesMenu.removeItem(object)
|
||||
}
|
||||
|
||||
ExclusiveGroup { id: devicesMenuGroup; }
|
||||
}
|
||||
|
||||
text: {
|
||||
if(base.progress < 0) {
|
||||
return qsTr("Please load a 3D model");
|
||||
|
|
@ -112,10 +175,10 @@ Button {
|
|||
}
|
||||
|
||||
onClicked: {
|
||||
if(Printer.outputDevice != "local_file") {
|
||||
Printer.writeToOutputDevice();
|
||||
} else if(base.saveAction) {
|
||||
base.saveAction.trigger();
|
||||
if(base.defaultAmbiguous) {
|
||||
devicesMenu.popup();
|
||||
} else {
|
||||
Printer.writeToOutputDevice(base.currentDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue