mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 20:39:01 +08:00
Use the OutputDeviceModel for selecting output device
Replaces the stuff in CuraApplication which really should not be there
This commit is contained in:
parent
6e4300b299
commit
baf4ea9523
@ -6,46 +6,17 @@ import QtQuick.Controls 1.1
|
|||||||
import QtQuick.Controls.Styles 1.1
|
import QtQuick.Controls.Styles 1.1
|
||||||
import QtQuick.Layouts 1.1
|
import QtQuick.Layouts 1.1
|
||||||
|
|
||||||
import UM 1.0 as UM
|
import UM 1.1 as UM
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: base;
|
id: base;
|
||||||
|
|
||||||
property Action saveAction;
|
|
||||||
|
|
||||||
property real progress: UM.Backend.progress;
|
property real progress: UM.Backend.progress;
|
||||||
Behavior on progress { NumberAnimation { duration: 250; } }
|
Behavior on progress { NumberAnimation { duration: 250; } }
|
||||||
|
|
||||||
property string currentDevice: "local_file"
|
|
||||||
property bool defaultOverride: false;
|
|
||||||
property bool defaultAmbiguous: false;
|
|
||||||
|
|
||||||
property variant printDuration: PrintInformation.currentPrintTime;
|
property variant printDuration: PrintInformation.currentPrintTime;
|
||||||
property real printMaterialAmount: PrintInformation.materialAmount;
|
property real printMaterialAmount: PrintInformation.materialAmount;
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: Printer;
|
|
||||||
onOutputDevicesChanged: {
|
|
||||||
if(!base.defaultOverride) {
|
|
||||||
base.defaultAmbiguous = false;
|
|
||||||
var device = null;
|
|
||||||
for(var i in Printer.outputDevices) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle{
|
Rectangle{
|
||||||
id: background
|
id: background
|
||||||
implicitWidth: base.width;
|
implicitWidth: base.width;
|
||||||
@ -113,7 +84,7 @@ Rectangle {
|
|||||||
elide: mediumLengthDuration ? Text.ElideRight : Text.ElideNone
|
elide: mediumLengthDuration ? Text.ElideRight : Text.ElideNone
|
||||||
visible: base.progress < 0.99 ? false : true
|
visible: base.progress < 0.99 ? false : true
|
||||||
//: Print material amount save button label
|
//: Print material amount save button label
|
||||||
text: base.printMaterialAmount < 0 ? "" : qsTr("%1m material").arg(base.printMaterialAmount);
|
text: base.printMaterialAmount < 0 ? "" : qsTr("%1m of Material").arg(base.printMaterialAmount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Rectangle {
|
Rectangle {
|
||||||
@ -134,29 +105,28 @@ Rectangle {
|
|||||||
anchors.topMargin: UM.Theme.sizes.save_button_text_margin.height;
|
anchors.topMargin: UM.Theme.sizes.save_button_text_margin.height;
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: UM.Theme.sizes.default_margin.width;
|
anchors.leftMargin: UM.Theme.sizes.default_margin.width;
|
||||||
tooltip: ''
|
tooltip: devicesModel.currentDevice.description;
|
||||||
enabled: progress >= 0.99;
|
enabled: progress >= 0.99;
|
||||||
|
|
||||||
width: infoBox.width/6*4.5
|
width: infoBox.width/6*4.5
|
||||||
height: UM.Theme.sizes.save_button_save_to_button.height
|
height: UM.Theme.sizes.save_button_save_to_button.height
|
||||||
|
|
||||||
|
text: devicesModel.currentDevice.short_description;
|
||||||
|
|
||||||
style: ButtonStyle {
|
style: ButtonStyle {
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: !control.enabled ? UM.Theme.colors.save_button_inactive : control.hovered ? UM.Theme.colors.save_button_active_hover : UM.Theme.colors.save_button_active;
|
color: !control.enabled ? UM.Theme.colors.save_button_inactive : control.hovered ? UM.Theme.colors.save_button_active_hover : UM.Theme.colors.save_button_active;
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.centerIn: parent
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
color: UM.Theme.colors.save_button_safe_to_text;
|
color: UM.Theme.colors.save_button_safe_to_text;
|
||||||
font: UM.Theme.fonts.sidebar_save_to;
|
font: UM.Theme.fonts.sidebar_save_to;
|
||||||
text: Printer.outputDevices[base.currentDevice].shortDescription;
|
text: control.text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
label: Item { }
|
||||||
}
|
}
|
||||||
onClicked:
|
onClicked: devicesModel.requestWriteToCurrentDevice()
|
||||||
if(base.defaultAmbiguous) {
|
|
||||||
devicesMenu.popup();
|
|
||||||
} else {
|
|
||||||
Printer.writeToOutputDevice(base.currentDevice);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
@ -165,16 +135,20 @@ Rectangle {
|
|||||||
anchors.topMargin: UM.Theme.sizes.save_button_text_margin.height
|
anchors.topMargin: UM.Theme.sizes.save_button_text_margin.height
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: UM.Theme.sizes.default_margin.width;
|
anchors.rightMargin: UM.Theme.sizes.default_margin.width;
|
||||||
tooltip: ''
|
|
||||||
|
tooltip: qsTr("Select the active output device");
|
||||||
|
|
||||||
width: infoBox.width/6*1.3 - UM.Theme.sizes.save_button_text_margin.height;
|
width: infoBox.width/6*1.3 - UM.Theme.sizes.save_button_text_margin.height;
|
||||||
height: UM.Theme.sizes.save_button_save_to_button.height
|
height: UM.Theme.sizes.save_button_save_to_button.height
|
||||||
|
|
||||||
|
iconSource: UM.Theme.icons[devicesModel.currentDevice.icon_name];
|
||||||
|
|
||||||
style: ButtonStyle {
|
style: ButtonStyle {
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: UM.Theme.colors.save_button_background;
|
color: UM.Theme.colors.save_button_background;
|
||||||
border.width: control.hovered ? UM.Theme.sizes.save_button_border.width : 0
|
border.width: control.hovered ? UM.Theme.sizes.save_button_border.width : 0
|
||||||
border.color: UM.Theme.colors.save_button_border
|
border.color: UM.Theme.colors.save_button_border
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: deviceSelectionIcon
|
id: deviceSelectionIcon
|
||||||
color: UM.Theme.colors.save_button_background;
|
color: UM.Theme.colors.save_button_background;
|
||||||
@ -183,14 +157,13 @@ Rectangle {
|
|||||||
anchors.verticalCenter: parent.verticalCenter;
|
anchors.verticalCenter: parent.verticalCenter;
|
||||||
width: parent.height - UM.Theme.sizes.save_button_text_margin.width ;
|
width: parent.height - UM.Theme.sizes.save_button_text_margin.width ;
|
||||||
height: parent.height - UM.Theme.sizes.save_button_text_margin.width;
|
height: parent.height - UM.Theme.sizes.save_button_text_margin.width;
|
||||||
|
|
||||||
UM.RecolorImage {
|
UM.RecolorImage {
|
||||||
anchors.centerIn: parent;
|
anchors.fill: parent;
|
||||||
width: parent.width;
|
|
||||||
height: parent.height;
|
|
||||||
sourceSize.width: width;
|
sourceSize.width: width;
|
||||||
sourceSize.height: height;
|
sourceSize.height: height;
|
||||||
color: UM.Theme.colors.save_button_active
|
color: UM.Theme.colors.save_button_active
|
||||||
source: UM.Theme.icons[Printer.outputDevices[base.currentDevice].icon];
|
source: control.iconSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
@ -203,24 +176,20 @@ Rectangle {
|
|||||||
color: UM.Theme.colors.save_button_active;
|
color: UM.Theme.colors.save_button_active;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
label: Item { }
|
||||||
}
|
}
|
||||||
|
|
||||||
menu: Menu {
|
menu: Menu {
|
||||||
id: devicesMenu;
|
id: devicesMenu;
|
||||||
Instantiator {
|
Instantiator {
|
||||||
model: Printer.outputDeviceNames;
|
model: devicesModel;
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: Printer.outputDevices[modelData].description;
|
text: model.description
|
||||||
checkable: true;
|
checkable: true;
|
||||||
checked: base.defaultAmbiguous ? false : modelData == base.currentDevice;
|
checked: model.id == devicesModel.currentDevice.id;
|
||||||
exclusiveGroup: devicesMenuGroup;
|
exclusiveGroup: devicesMenuGroup;
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
base.defaultOverride = true;
|
devicesModel.setCurrentDevice(model.id);
|
||||||
base.currentDevice = modelData;
|
|
||||||
if(base.defaultAmbiguous) {
|
|
||||||
base.defaultAmbiguous = false;
|
|
||||||
Printer.writeToOutputDevice(modelData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onObjectAdded: devicesMenu.insertItem(index, object)
|
onObjectAdded: devicesMenu.insertItem(index, object)
|
||||||
@ -230,4 +199,8 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
UM.OutputDevicesModel {
|
||||||
|
id: devicesModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user