|
@@ -9,13 +9,22 @@ import QtQuick.Dialogs 1.2
|
|
|
import UM 1.2 as UM
|
|
|
import Cura 1.0 as Cura
|
|
|
|
|
|
-
|
|
|
Item
|
|
|
{
|
|
|
id: base
|
|
|
|
|
|
property QtObject materialManager: CuraApplication.getMaterialManager()
|
|
|
- property var resetEnabled: false // Keep PreferencesDialog happy
|
|
|
+ // Keep PreferencesDialog happy
|
|
|
+ property var resetEnabled: false
|
|
|
+ property var currentItem: null
|
|
|
+ property var isCurrentItemActivated:
|
|
|
+ {
|
|
|
+ const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
|
|
|
+ const root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position];
|
|
|
+ return base.currentItem.root_material_id == root_material_id;
|
|
|
+ }
|
|
|
+ property string newRootMaterialIdToSwitchTo: ""
|
|
|
+ property bool toActivateNewMaterial: false
|
|
|
|
|
|
UM.I18nCatalog
|
|
|
{
|
|
@@ -30,11 +39,72 @@ Item
|
|
|
{
|
|
|
id: genericMaterialsModel
|
|
|
}
|
|
|
+ // Component.onCompleted:
|
|
|
+ // {
|
|
|
+ // // Select the activated material when this page shows up
|
|
|
+ // const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
|
|
|
+ // const active_root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position];
|
|
|
+ // var itemIndex = -1;
|
|
|
+ // for (var i = 0; i < materialsModel.rowCount(); ++i)
|
|
|
+ // {
|
|
|
+ // var item = materialsModel.getItem(i);
|
|
|
+ // if (item.root_material_id == active_root_material_id)
|
|
|
+ // {
|
|
|
+ // itemIndex = i;
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // materialListView.currentIndex = itemIndex;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // This connection makes sure that we will switch to the new
|
|
|
+ Connections
|
|
|
+ {
|
|
|
+ target: materialsModel
|
|
|
+ onItemsChanged:
|
|
|
+ {
|
|
|
+ var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id;
|
|
|
+ var position = Cura.ExtruderManager.activeExtruderIndex;
|
|
|
+
|
|
|
+ // try to pick the currently selected item; it may have been moved
|
|
|
+ if (base.newRootMaterialIdToSwitchTo == "")
|
|
|
+ {
|
|
|
+ base.newRootMaterialIdToSwitchTo = currentItemId;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (var idx = 0; idx < materialsModel.rowCount(); ++idx)
|
|
|
+ {
|
|
|
+ var item = materialsModel.getItem(idx);
|
|
|
+ if (item.root_material_id == base.newRootMaterialIdToSwitchTo)
|
|
|
+ {
|
|
|
+ // Switch to the newly created profile if needed
|
|
|
+ materialListView.currentIndex = idx;
|
|
|
+ materialListView.activateDetailsWithIndex(materialListView.currentIndex);
|
|
|
+ if (base.toActivateNewMaterial)
|
|
|
+ {
|
|
|
+ Cura.MachineManager.setMaterial(position, item.container_node);
|
|
|
+ }
|
|
|
+ base.newRootMaterialIdToSwitchTo = "";
|
|
|
+ base.toActivateNewMaterial = false;
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ materialListView.currentIndex = 0;
|
|
|
+ materialListView.activateDetailsWithIndex(materialListView.currentIndex);
|
|
|
+ if (base.toActivateNewMaterial)
|
|
|
+ {
|
|
|
+ Cura.MachineManager.setMaterial(position, materialsModel.getItem(0).container_node);
|
|
|
+ }
|
|
|
+ base.newRootMaterialIdToSwitchTo = "";
|
|
|
+ base.toActivateNewMaterial = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ // Main layout
|
|
|
Label
|
|
|
{
|
|
|
id: titleLabel
|
|
|
-
|
|
|
anchors
|
|
|
{
|
|
|
top: parent.top
|
|
@@ -42,45 +112,12 @@ Item
|
|
|
right: parent.right
|
|
|
margins: 5 * screenScaleFactor
|
|
|
}
|
|
|
-
|
|
|
font.pointSize: 18
|
|
|
text: catalog.i18nc("@title:tab", "Materials")
|
|
|
}
|
|
|
|
|
|
- property var hasCurrentItem: materialListView.currentItem != null
|
|
|
-
|
|
|
- property var currentItem:
|
|
|
- { // is soon to be overwritten
|
|
|
- var current_index = materialListView.currentIndex;
|
|
|
- return materialsModel.getItem(current_index);
|
|
|
- }
|
|
|
-
|
|
|
- property var isCurrentItemActivated:
|
|
|
- {
|
|
|
- const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
|
|
|
- const root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position];
|
|
|
- return base.currentItem.root_material_id == root_material_id;
|
|
|
- }
|
|
|
-
|
|
|
- Component.onCompleted:
|
|
|
- {
|
|
|
- // Select the activated material when this page shows up
|
|
|
- const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
|
|
|
- const active_root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position];
|
|
|
- var itemIndex = -1;
|
|
|
- for (var i = 0; i < materialsModel.rowCount(); ++i)
|
|
|
- {
|
|
|
- var item = materialsModel.getItem(i);
|
|
|
- if (item.root_material_id == active_root_material_id)
|
|
|
- {
|
|
|
- itemIndex = i;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- materialListView.currentIndex = itemIndex;
|
|
|
- }
|
|
|
-
|
|
|
- Row // Button Row
|
|
|
+ // Button Row
|
|
|
+ Row
|
|
|
{
|
|
|
id: buttonRow
|
|
|
anchors
|
|
@@ -173,63 +210,102 @@ Item
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- property string newRootMaterialIdToSwitchTo: ""
|
|
|
- property bool toActivateNewMaterial: false
|
|
|
+ Item {
|
|
|
+ id: contentsItem
|
|
|
+ anchors
|
|
|
+ {
|
|
|
+ top: titleLabel.bottom
|
|
|
+ left: parent.left
|
|
|
+ right: parent.right
|
|
|
+ bottom: parent.bottom
|
|
|
+ margins: 5 * screenScaleFactor
|
|
|
+ bottomMargin: 0
|
|
|
+ }
|
|
|
+ clip: true
|
|
|
+ }
|
|
|
|
|
|
- // This connection makes sure that we will switch to the new
|
|
|
- Connections
|
|
|
+ Item
|
|
|
{
|
|
|
- target: materialsModel
|
|
|
- onItemsChanged:
|
|
|
+ anchors
|
|
|
{
|
|
|
- var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id;
|
|
|
- var position = Cura.ExtruderManager.activeExtruderIndex;
|
|
|
+ top: buttonRow.bottom
|
|
|
+ topMargin: UM.Theme.getSize("default_margin").height
|
|
|
+ left: parent.left
|
|
|
+ right: parent.right
|
|
|
+ bottom: parent.bottom
|
|
|
+ }
|
|
|
|
|
|
- // try to pick the currently selected item; it may have been moved
|
|
|
- if (base.newRootMaterialIdToSwitchTo == "")
|
|
|
+ SystemPalette { id: palette }
|
|
|
+
|
|
|
+ Label
|
|
|
+ {
|
|
|
+ id: captionLabel
|
|
|
+ anchors
|
|
|
{
|
|
|
- base.newRootMaterialIdToSwitchTo = currentItemId;
|
|
|
+ top: parent.top
|
|
|
+ left: parent.left
|
|
|
}
|
|
|
-
|
|
|
- for (var idx = 0; idx < materialsModel.rowCount(); ++idx)
|
|
|
+ visible: text != ""
|
|
|
+ text:
|
|
|
{
|
|
|
- var item = materialsModel.getItem(idx);
|
|
|
- if (item.root_material_id == base.newRootMaterialIdToSwitchTo)
|
|
|
+ var caption = catalog.i18nc("@action:label", "Printer") + ": " + Cura.MachineManager.activeMachineName;
|
|
|
+ if (Cura.MachineManager.hasVariants)
|
|
|
{
|
|
|
- // Switch to the newly created profile if needed
|
|
|
- materialListView.currentIndex = idx;
|
|
|
- materialListView.activateDetailsWithIndex(materialListView.currentIndex);
|
|
|
- if (base.toActivateNewMaterial)
|
|
|
- {
|
|
|
- Cura.MachineManager.setMaterial(position, item.container_node);
|
|
|
- }
|
|
|
- base.newRootMaterialIdToSwitchTo = "";
|
|
|
- base.toActivateNewMaterial = false;
|
|
|
- return
|
|
|
+ caption += ", " + Cura.MachineManager.activeDefinitionVariantsName + ": " + Cura.MachineManager.activeVariantName;
|
|
|
}
|
|
|
+ return caption;
|
|
|
}
|
|
|
+ width: materialScrollView.width
|
|
|
+ elide: Text.ElideRight
|
|
|
+ }
|
|
|
|
|
|
- materialListView.currentIndex = 0;
|
|
|
- materialListView.activateDetailsWithIndex(materialListView.currentIndex);
|
|
|
- if (base.toActivateNewMaterial)
|
|
|
+ ScrollView
|
|
|
+ {
|
|
|
+ id: materialScrollView
|
|
|
+ anchors
|
|
|
{
|
|
|
- Cura.MachineManager.setMaterial(position, materialsModel.getItem(0).container_node);
|
|
|
+ top: captionLabel.visible ? captionLabel.bottom : parent.top
|
|
|
+ topMargin: captionLabel.visible ? UM.Theme.getSize("default_margin").height : 0
|
|
|
+ bottom: parent.bottom
|
|
|
+ left: parent.left
|
|
|
}
|
|
|
- base.newRootMaterialIdToSwitchTo = "";
|
|
|
- base.toActivateNewMaterial = false;
|
|
|
+
|
|
|
+ Rectangle
|
|
|
+ {
|
|
|
+ parent: viewport
|
|
|
+ anchors.fill: parent
|
|
|
+ color: palette.light
|
|
|
+ }
|
|
|
+
|
|
|
+ width: true ? (parent.width * 0.4) | 0 : parent.width
|
|
|
+ frameVisible: true
|
|
|
+ verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn
|
|
|
+
|
|
|
+ MaterialsList {}
|
|
|
}
|
|
|
+
|
|
|
+ // MaterialsDetailsPanel
|
|
|
+ // {
|
|
|
+ // anchors
|
|
|
+ // {
|
|
|
+ // left: materialScrollView.right
|
|
|
+ // leftMargin: UM.Theme.getSize("default_margin").width
|
|
|
+ // top: parent.top
|
|
|
+ // bottom: parent.bottom
|
|
|
+ // right: parent.right
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
+ // Dialogs
|
|
|
MessageDialog
|
|
|
{
|
|
|
id: confirmRemoveMaterialDialog
|
|
|
-
|
|
|
icon: StandardIcon.Question;
|
|
|
title: catalog.i18nc("@title:window", "Confirm Remove")
|
|
|
text: catalog.i18nc("@label (%1 is object name)", "Are you sure you wish to remove %1? This cannot be undone!").arg(base.currentItem.name)
|
|
|
standardButtons: StandardButton.Yes | StandardButton.No
|
|
|
modality: Qt.ApplicationModal
|
|
|
-
|
|
|
onYes:
|
|
|
{
|
|
|
base.materialManager.removeMaterial(base.currentItem.container_node);
|
|
@@ -299,184 +375,4 @@ Item
|
|
|
{
|
|
|
id: messageDialog
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- Item {
|
|
|
- id: contentsItem
|
|
|
-
|
|
|
- anchors
|
|
|
- {
|
|
|
- top: titleLabel.bottom
|
|
|
- left: parent.left
|
|
|
- right: parent.right
|
|
|
- bottom: parent.bottom
|
|
|
- margins: 5 * screenScaleFactor
|
|
|
- bottomMargin: 0
|
|
|
- }
|
|
|
-
|
|
|
- clip: true
|
|
|
- }
|
|
|
-
|
|
|
- Item
|
|
|
- {
|
|
|
- anchors
|
|
|
- {
|
|
|
- top: buttonRow.bottom
|
|
|
- topMargin: UM.Theme.getSize("default_margin").height
|
|
|
- left: parent.left
|
|
|
- right: parent.right
|
|
|
- bottom: parent.bottom
|
|
|
- }
|
|
|
-
|
|
|
- SystemPalette { id: palette }
|
|
|
-
|
|
|
- Label
|
|
|
- {
|
|
|
- id: captionLabel
|
|
|
- anchors
|
|
|
- {
|
|
|
- top: parent.top
|
|
|
- left: parent.left
|
|
|
- }
|
|
|
- visible: text != ""
|
|
|
- text:
|
|
|
- {
|
|
|
- var caption = catalog.i18nc("@action:label", "Printer") + ": " + Cura.MachineManager.activeMachineName;
|
|
|
- if (Cura.MachineManager.hasVariants)
|
|
|
- {
|
|
|
- caption += ", " + Cura.MachineManager.activeDefinitionVariantsName + ": " + Cura.MachineManager.activeVariantName;
|
|
|
- }
|
|
|
- return caption;
|
|
|
- }
|
|
|
- width: materialScrollView.width
|
|
|
- elide: Text.ElideRight
|
|
|
- }
|
|
|
-
|
|
|
- ScrollView
|
|
|
- {
|
|
|
- id: materialScrollView
|
|
|
- anchors
|
|
|
- {
|
|
|
- top: captionLabel.visible ? captionLabel.bottom : parent.top
|
|
|
- topMargin: captionLabel.visible ? UM.Theme.getSize("default_margin").height : 0
|
|
|
- bottom: parent.bottom
|
|
|
- left: parent.left
|
|
|
- }
|
|
|
-
|
|
|
- Rectangle
|
|
|
- {
|
|
|
- parent: viewport
|
|
|
- anchors.fill: parent
|
|
|
- color: palette.light
|
|
|
- }
|
|
|
-
|
|
|
- width: true ? (parent.width * 0.4) | 0 : parent.width
|
|
|
- frameVisible: true
|
|
|
-
|
|
|
- MaterialsList {}
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- Item
|
|
|
- {
|
|
|
- id: detailsPanel
|
|
|
-
|
|
|
- anchors
|
|
|
- {
|
|
|
- left: materialScrollView.right
|
|
|
- leftMargin: UM.Theme.getSize("default_margin").width
|
|
|
- top: parent.top
|
|
|
- bottom: parent.bottom
|
|
|
- right: parent.right
|
|
|
- }
|
|
|
-
|
|
|
- function updateMaterialPropertiesObject( currentItem )
|
|
|
- {
|
|
|
-// var currentItem = materialsModel.getItem(materialListView.currentIndex);
|
|
|
-
|
|
|
- materialProperties.name = currentItem.name ? currentItem.name : "Unknown";
|
|
|
- materialProperties.guid = currentItem.guid;
|
|
|
- materialProperties.container_id = currentItem.container_id;
|
|
|
-
|
|
|
- materialProperties.brand = currentItem.brand ? currentItem.brand : "Unknown";
|
|
|
- materialProperties.material = currentItem.material ? currentItem.material : "Unknown";
|
|
|
- materialProperties.color_name = currentItem.color_name ? currentItem.color_name : "Yellow";
|
|
|
- materialProperties.color_code = currentItem.color_code ? currentItem.color_code : "yellow";
|
|
|
-
|
|
|
- materialProperties.description = currentItem.description ? currentItem.description : "";
|
|
|
- materialProperties.adhesion_info = currentItem.adhesion_info ? currentItem.adhesion_info : "";
|
|
|
-
|
|
|
- materialProperties.density = currentItem.density ? currentItem.density : 0.0;
|
|
|
- materialProperties.diameter = currentItem.diameter ? currentItem.diameter : 0.0;
|
|
|
- materialProperties.approximate_diameter = currentItem.approximate_diameter ? currentItem.approximate_diameter : "0";
|
|
|
- }
|
|
|
-
|
|
|
- Item
|
|
|
- {
|
|
|
- anchors.fill: parent
|
|
|
-
|
|
|
- Item // Material title Label
|
|
|
- {
|
|
|
- id: profileName
|
|
|
-
|
|
|
- width: parent.width
|
|
|
- height: childrenRect.height
|
|
|
-
|
|
|
- Label {
|
|
|
- text: materialProperties.name
|
|
|
- font: UM.Theme.getFont("large")
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- MaterialView // Material detailed information view below the title Label
|
|
|
- {
|
|
|
- id: materialDetailsView
|
|
|
- anchors
|
|
|
- {
|
|
|
- left: parent.left
|
|
|
- right: parent.right
|
|
|
- top: profileName.bottom
|
|
|
- topMargin: UM.Theme.getSize("default_margin").height
|
|
|
- bottom: parent.bottom
|
|
|
- }
|
|
|
-
|
|
|
- editingEnabled: base.currentItem != null && !base.currentItem.is_read_only
|
|
|
-
|
|
|
- properties: materialProperties
|
|
|
- containerId: base.currentItem != null ? base.currentItem.container_id : ""
|
|
|
- currentMaterialNode: base.currentItem.container_node
|
|
|
-
|
|
|
- property alias pane: base
|
|
|
- }
|
|
|
-
|
|
|
- QtObject
|
|
|
- {
|
|
|
- id: materialProperties
|
|
|
-
|
|
|
- property string guid: "00000000-0000-0000-0000-000000000000"
|
|
|
- property string container_id: "Unknown";
|
|
|
- property string name: "Unknown";
|
|
|
- property string profile_type: "Unknown";
|
|
|
- property string brand: "Unknown";
|
|
|
- property string material: "Unknown"; // This needs to be named as "material" to be consistent with
|
|
|
- // the material container's metadata entry
|
|
|
-
|
|
|
- property string color_name: "Yellow";
|
|
|
- property color color_code: "yellow";
|
|
|
-
|
|
|
- property real density: 0.0;
|
|
|
- property real diameter: 0.0;
|
|
|
- property string approximate_diameter: "0";
|
|
|
-
|
|
|
- property real spool_cost: 0.0;
|
|
|
- property real spool_weight: 0.0;
|
|
|
- property real spool_length: 0.0;
|
|
|
- property real cost_per_meter: 0.0;
|
|
|
-
|
|
|
- property string description: "";
|
|
|
- property string adhesion_info: "";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|