mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Rework Per Object Settings selection mechanism
This commit is contained in:
parent
d9098ff06d
commit
2ebeb72fac
2 changed files with 101 additions and 186 deletions
|
@ -10,224 +10,117 @@ import UM 1.1 as UM
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: base;
|
id: base;
|
||||||
|
property int currentIndex: UM.ActiveTool.properties.SelectedIndex;
|
||||||
|
|
||||||
width: 0;
|
width: childrenRect.width;
|
||||||
height: 0;
|
height: childrenRect.height;
|
||||||
|
|
||||||
property variant position: mapToItem(null, 0, 0)
|
Column {
|
||||||
|
id: items
|
||||||
|
anchors.top: parent.top;
|
||||||
|
anchors.left: parent.left;
|
||||||
|
|
||||||
property real viewportWidth: UM.Application.mainWindow.width * UM.Application.mainWindow.viewportRect.width;
|
spacing: UM.Theme.sizes.default_lining.height;
|
||||||
property real viewportHeight: UM.Application.mainWindow.height * UM.Application.mainWindow.viewportRect.height;
|
|
||||||
|
|
||||||
property int currentIndex;
|
UM.SettingItem {
|
||||||
|
id: profileSelection
|
||||||
|
|
||||||
Rectangle {
|
width: UM.Theme.sizes.setting.width;
|
||||||
id: settingsPanel;
|
height: UM.Theme.sizes.setting.height;
|
||||||
|
|
||||||
z: 3;
|
name: catalog.i18nc("@label", "Profile")
|
||||||
|
type: "enum"
|
||||||
|
indent: false
|
||||||
|
|
||||||
width: UM.Theme.sizes.per_object_settings_panel.width;
|
style: UM.Theme.styles.setting_item;
|
||||||
height: items.height + UM.Theme.sizes.default_margin.height * 2;
|
|
||||||
|
|
||||||
opacity: 0;
|
options: UM.ProfilesModel { addUseGlobal: true }
|
||||||
Behavior on opacity { NumberAnimation { } }
|
|
||||||
|
|
||||||
border.width: UM.Theme.sizes.per_object_settings_panel_border.width;
|
value: UM.ActiveTool.properties.Model.getItem(base.currentIndex).profile
|
||||||
border.color: UM.Theme.colors.per_object_settings_panel_border;
|
|
||||||
|
|
||||||
color: UM.Theme.colors.per_object_settings_panel_background;
|
onItemValueChanged: {
|
||||||
|
var item = UM.ActiveTool.properties.Model.getItem(base.currentIndex);
|
||||||
DropArea {
|
UM.ActiveTool.properties.Model.setObjectProfile(item.id, value)
|
||||||
anchors.fill: parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
Button {
|
|
||||||
id: closeButton;
|
|
||||||
width: UM.Theme.sizes.message_close.width;
|
|
||||||
height: UM.Theme.sizes.message_close.height;
|
|
||||||
anchors {
|
|
||||||
right: parent.right;
|
|
||||||
rightMargin: UM.Theme.sizes.default_margin.width / 2;
|
|
||||||
top: parent.top;
|
|
||||||
topMargin: UM.Theme.sizes.default_margin.width / 2;
|
|
||||||
}
|
|
||||||
UM.RecolorImage {
|
|
||||||
anchors.fill: parent;
|
|
||||||
sourceSize.width: width
|
|
||||||
sourceSize.height: width
|
|
||||||
color: UM.Theme.colors.message_dismiss
|
|
||||||
source: UM.Theme.icons.cross2;
|
|
||||||
}
|
|
||||||
|
|
||||||
onClicked: settingsPanel.opacity = 0
|
|
||||||
|
|
||||||
style: ButtonStyle {
|
|
||||||
background: Rectangle {
|
|
||||||
color: UM.Theme.colors.message_background
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Item
|
||||||
id: items
|
{
|
||||||
anchors.top: parent.top;
|
height: UM.Theme.sizes.default_margin.height
|
||||||
anchors.topMargin: UM.Theme.sizes.default_margin.height;
|
width: parent.width
|
||||||
|
}
|
||||||
|
|
||||||
spacing: UM.Theme.sizes.default_lining.height;
|
Repeater {
|
||||||
|
id: settings;
|
||||||
|
|
||||||
|
model: UM.ActiveTool.properties.Model.getItem(base.currentIndex).settings
|
||||||
|
|
||||||
UM.SettingItem {
|
UM.SettingItem {
|
||||||
id: profileSelection
|
|
||||||
|
|
||||||
x: UM.Theme.sizes.per_object_settings_panel_border.width + 1
|
|
||||||
|
|
||||||
width: UM.Theme.sizes.setting.width;
|
width: UM.Theme.sizes.setting.width;
|
||||||
height: UM.Theme.sizes.setting.height;
|
height: UM.Theme.sizes.setting.height;
|
||||||
|
|
||||||
name: catalog.i18nc("@label", "Profile")
|
name: model.label;
|
||||||
type: "enum"
|
type: model.type;
|
||||||
|
value: model.value;
|
||||||
|
description: model.description;
|
||||||
|
unit: model.unit;
|
||||||
|
valid: model.valid;
|
||||||
|
options: model.options
|
||||||
|
indent: false
|
||||||
|
|
||||||
style: UM.Theme.styles.setting_item;
|
style: UM.Theme.styles.setting_item;
|
||||||
|
|
||||||
options: UM.ProfilesModel { addUseGlobal: true }
|
|
||||||
|
|
||||||
value: UM.ActiveTool.properties.Model.getItem(base.currentIndex).profile
|
|
||||||
|
|
||||||
onItemValueChanged: {
|
onItemValueChanged: {
|
||||||
var item = UM.ActiveTool.properties.Model.getItem(base.currentIndex);
|
settings.model.setSettingValue(model.key, value)
|
||||||
UM.ActiveTool.properties.Model.setObjectProfile(item.id, value)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Repeater {
|
Button
|
||||||
id: settings;
|
{
|
||||||
|
anchors.left: parent.left;
|
||||||
|
anchors.leftMargin: UM.Theme.sizes.default_margin.width;
|
||||||
|
|
||||||
model: UM.ActiveTool.properties.Model.getItem(base.currentIndex).settings
|
width: UM.Theme.sizes.setting.height;
|
||||||
|
|
||||||
UM.SettingItem {
|
|
||||||
width: UM.Theme.sizes.setting.width;
|
|
||||||
height: UM.Theme.sizes.setting.height;
|
height: UM.Theme.sizes.setting.height;
|
||||||
x: UM.Theme.sizes.per_object_settings_panel_border.width + 1
|
|
||||||
|
|
||||||
name: model.label;
|
opacity: parent.hovered || hovered ? 1 : 0;
|
||||||
type: model.type;
|
onClicked: UM.ActiveTool.properties.Model.removeSettingOverride(UM.ActiveTool.properties.Model.getItem(base.currentIndex).id, model.key)
|
||||||
value: model.value;
|
|
||||||
description: model.description;
|
|
||||||
unit: model.unit;
|
|
||||||
valid: model.valid;
|
|
||||||
options: model.options
|
|
||||||
|
|
||||||
style: UM.Theme.styles.setting_item;
|
style: ButtonStyle
|
||||||
|
|
||||||
onItemValueChanged: {
|
|
||||||
settings.model.setSettingValue(model.key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
Button
|
|
||||||
{
|
{
|
||||||
anchors.left: parent.horizontalCenter;
|
background: Rectangle
|
||||||
anchors.leftMargin: UM.Theme.sizes.default_margin.width;
|
|
||||||
|
|
||||||
width: UM.Theme.sizes.setting.height;
|
|
||||||
height: UM.Theme.sizes.setting.height;
|
|
||||||
|
|
||||||
opacity: parent.hovered || hovered ? 1 : 0;
|
|
||||||
onClicked: UM.ActiveTool.properties.Model.removeSettingOverride(UM.ActiveTool.properties.Model.getItem(base.currentIndex).id, model.key)
|
|
||||||
|
|
||||||
style: ButtonStyle
|
|
||||||
{
|
{
|
||||||
background: Rectangle
|
color: control.hovered ? control.parent.style.controlHighlightColor : control.parent.style.controlColor;
|
||||||
|
UM.RecolorImage
|
||||||
{
|
{
|
||||||
color: control.hovered ? control.parent.style.controlHighlightColor : control.parent.style.controlColor;
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
UM.RecolorImage
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
{
|
width: parent.width/2
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
height: parent.height/2
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
sourceSize.width: width
|
||||||
width: parent.width/2
|
sourceSize.height: width
|
||||||
height: parent.height/2
|
color: UM.Theme.colors.setting_control_revert
|
||||||
sourceSize.width: width
|
source: UM.Theme.icons.cross1
|
||||||
sourceSize.height: width
|
|
||||||
color: UM.Theme.colors.setting_control_revert
|
|
||||||
source: UM.Theme.icons.cross1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
height: UM.Theme.sizes.default_margin.height / 2
|
|
||||||
width: parent.width
|
|
||||||
}
|
|
||||||
|
|
||||||
Button
|
|
||||||
{
|
|
||||||
id: customise_settings_button;
|
|
||||||
anchors.right: profileSelection.right;
|
|
||||||
visible: parseInt(UM.Preferences.getValue("cura/active_mode")) == 1
|
|
||||||
|
|
||||||
text: catalog.i18nc("@action:button", "Customize Settings");
|
|
||||||
|
|
||||||
style: ButtonStyle
|
|
||||||
{
|
|
||||||
background: Rectangle
|
|
||||||
{
|
|
||||||
width: control.width;
|
|
||||||
height: control.height;
|
|
||||||
color: control.hovered ? UM.Theme.colors.load_save_button_hover : UM.Theme.colors.load_save_button;
|
|
||||||
}
|
|
||||||
label: Label
|
|
||||||
{
|
|
||||||
text: control.text;
|
|
||||||
color: UM.Theme.colors.load_save_button_text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onClicked: settingPickDialog.visible = true;
|
|
||||||
|
|
||||||
Connections
|
|
||||||
{
|
|
||||||
target: UM.Preferences;
|
|
||||||
|
|
||||||
onPreferenceChanged:
|
|
||||||
{
|
|
||||||
customise_settings_button.visible = parseInt(UM.Preferences.getValue("cura/active_mode"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UM.I18nCatalog { id: catalog; name: "uranium"; }
|
Item
|
||||||
}
|
{
|
||||||
|
height: UM.Theme.sizes.default_margin.height
|
||||||
|
width: parent.width
|
||||||
|
}
|
||||||
|
|
||||||
Repeater {
|
Button
|
||||||
model: UM.ActiveTool.properties.Model;
|
{
|
||||||
delegate: Button {
|
id: customise_settings_button;
|
||||||
x: ((model.x + 1.0) / 2.0) * base.viewportWidth - base.position.x - width / 2
|
anchors.right: profileSelection.right;
|
||||||
y: -((model.y + 1.0) / 2.0) * base.viewportHeight + (base.viewportHeight - base.position.y) + height / 2
|
height: UM.Theme.sizes.setting.height;
|
||||||
|
visible: parseInt(UM.Preferences.getValue("cura/active_mode")) == 1
|
||||||
|
|
||||||
width: UM.Theme.sizes.per_object_settings_button.width
|
text: catalog.i18nc("@action:button", "Add Setting");
|
||||||
height: UM.Theme.sizes.per_object_settings_button.height
|
|
||||||
|
|
||||||
tooltip: catalog.i18nc("@info:tooltip", "Customise settings for this object");
|
|
||||||
|
|
||||||
checkable: true;
|
|
||||||
onClicked: {
|
|
||||||
if(settingsPanel.opacity < 0.5) //Per-object panel is not currently displayed.
|
|
||||||
{
|
|
||||||
base.currentIndex = index;
|
|
||||||
|
|
||||||
settingsPanel.anchors.left = right;
|
|
||||||
settingsPanel.anchors.top = top;
|
|
||||||
|
|
||||||
settingsPanel.opacity = 1;
|
|
||||||
}
|
|
||||||
else //Per-object panel is already displayed. Deactivate it (same behaviour as the close button).
|
|
||||||
{
|
|
||||||
settingsPanel.opacity = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
style: ButtonStyle
|
style: ButtonStyle
|
||||||
{
|
{
|
||||||
|
@ -235,20 +128,36 @@ Item {
|
||||||
{
|
{
|
||||||
width: control.width;
|
width: control.width;
|
||||||
height: control.height;
|
height: control.height;
|
||||||
|
border.width: UM.Theme.sizes.default_lining.width;
|
||||||
color: control.hovered ? UM.Theme.colors.button_active : UM.Theme.colors.button_hover;
|
border.color: control.pressed ? UM.Theme.colors.action_button_active_border :
|
||||||
|
control.hovered ? UM.Theme.colors.action_button_hovered_border : UM.Theme.colors.action_button_border
|
||||||
|
color: control.pressed ? UM.Theme.colors.action_button_active :
|
||||||
|
control.hovered ? UM.Theme.colors.action_button_hovered : UM.Theme.colors.action_button
|
||||||
}
|
}
|
||||||
label: Image {
|
label: Label
|
||||||
width: control.width;
|
{
|
||||||
height: control.height;
|
text: control.text;
|
||||||
sourceSize.width: width;
|
color: UM.Theme.colors.setting_control_text;
|
||||||
sourceSize.height: height;
|
anchors.centerIn: parent
|
||||||
source: UM.Theme.icons.plus;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onClicked: settingPickDialog.visible = true;
|
||||||
|
|
||||||
|
Connections
|
||||||
|
{
|
||||||
|
target: UM.Preferences;
|
||||||
|
|
||||||
|
onPreferenceChanged:
|
||||||
|
{
|
||||||
|
customise_settings_button.visible = parseInt(UM.Preferences.getValue("cura/active_mode"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UM.I18nCatalog { id: catalog; name: "uranium"; }
|
||||||
|
|
||||||
UM.Dialog {
|
UM.Dialog {
|
||||||
id: settingPickDialog
|
id: settingPickDialog
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# Uranium is released under the terms of the AGPLv3 or higher.
|
# Uranium is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
from UM.Tool import Tool
|
from UM.Tool import Tool
|
||||||
|
from UM.Scene.Selection import Selection
|
||||||
|
|
||||||
from . import PerObjectSettingsModel
|
from . import PerObjectSettingsModel
|
||||||
|
|
||||||
|
@ -9,10 +10,15 @@ class PerObjectSettingsTool(Tool):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.setExposedProperties("Model")
|
self.setExposedProperties("Model", "SelectedIndex")
|
||||||
|
|
||||||
def event(self, event):
|
def event(self, event):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getModel(self):
|
def getModel(self):
|
||||||
return PerObjectSettingsModel.PerObjectSettingsModel()
|
return PerObjectSettingsModel.PerObjectSettingsModel()
|
||||||
|
|
||||||
|
def getSelectedIndex(self):
|
||||||
|
selected_object_id = id(Selection.getSelectedObject(0));
|
||||||
|
index = self.getModel().find("id", selected_object_id)
|
||||||
|
return index
|
Loading…
Add table
Add a link
Reference in a new issue