mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 01:39:03 +08:00
Add a new ToolbarButton
Now also the Extruder button is a toolbar button since it will show in the toolbar.
This commit is contained in:
parent
4fab546425
commit
309061ce31
@ -7,7 +7,7 @@ import QtQuick.Controls 2.0
|
|||||||
import UM 1.2 as UM
|
import UM 1.2 as UM
|
||||||
import Cura 1.0 as Cura
|
import Cura 1.0 as Cura
|
||||||
|
|
||||||
Button
|
Cura.ToolbarButton
|
||||||
{
|
{
|
||||||
id: base
|
id: base
|
||||||
|
|
||||||
@ -18,22 +18,16 @@ Button
|
|||||||
checked: Cura.ExtruderManager.selectedObjectExtruders.indexOf(extruder.id) != -1
|
checked: Cura.ExtruderManager.selectedObjectExtruders.indexOf(extruder.id) != -1
|
||||||
enabled: UM.Selection.hasSelection && extruder.stack.isEnabled
|
enabled: UM.Selection.hasSelection && extruder.stack.isEnabled
|
||||||
|
|
||||||
background: Item {}
|
toolItem: ExtruderIcon
|
||||||
contentItem: Item
|
|
||||||
{
|
{
|
||||||
// For some reason if the extruder icon is not enclosed to the item, the size changes to fill the size of the button
|
materialColor: extruder.color
|
||||||
ExtruderIcon
|
extruderEnabled: extruder.stack.isEnabled
|
||||||
{
|
property int index: extruder.index
|
||||||
anchors.centerIn: parent
|
|
||||||
materialColor: model.color
|
|
||||||
extruderEnabled: extruder.stack.isEnabled
|
|
||||||
property int index: extruder.index
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
forceActiveFocus() //First grab focus, so all the text fields are updated
|
forceActiveFocus() //First grab focus, so all the text fields are updated
|
||||||
CuraActions.setExtruderForSelection(extruder.id);
|
CuraActions.setExtruderForSelection(extruder.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,17 +55,25 @@ Item
|
|||||||
model: UM.ToolModel { id: toolsModel }
|
model: UM.ToolModel { id: toolsModel }
|
||||||
width: childrenRect.width
|
width: childrenRect.width
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
Button
|
|
||||||
|
delegate: ToolbarButton
|
||||||
{
|
{
|
||||||
text: model.name + (model.shortcut ? (" (" + model.shortcut + ")") : "")
|
text: model.name + (model.shortcut ? (" (" + model.shortcut + ")") : "")
|
||||||
iconSource: (UM.Theme.getIcon(model.icon) != "") ? UM.Theme.getIcon(model.icon) : "file:///" + model.location + "/" + model.icon
|
|
||||||
checkable: true
|
checkable: true
|
||||||
checked: model.active
|
checked: model.active
|
||||||
enabled: model.enabled && UM.Selection.hasSelection && UM.Controller.toolsEnabled
|
enabled: model.enabled && UM.Selection.hasSelection && UM.Controller.toolsEnabled
|
||||||
style: UM.Theme.styles.toolbar_button
|
|
||||||
|
|
||||||
property bool isFirstElement: toolsModel.getItem(0).id == model.id
|
topElement: toolsModel.getItem(0).id == model.id
|
||||||
property bool isLastElement: toolsModel.getItem(toolsModel.rowCount() - 1).id == model.id
|
bottomElement: toolsModel.getItem(toolsModel.rowCount() - 1).id == model.id
|
||||||
|
|
||||||
|
toolItem: UM.RecolorImage
|
||||||
|
{
|
||||||
|
opacity: parent.enabled ? 1.0 : 0.2
|
||||||
|
source: (UM.Theme.getIcon(model.icon) != "") ? UM.Theme.getIcon(model.icon) : "file:///" + model.location + "/" + model.icon
|
||||||
|
color: UM.Theme.getColor("toolbar_button_text")
|
||||||
|
|
||||||
|
sourceSize: UM.Theme.getSize("button_icon")
|
||||||
|
}
|
||||||
|
|
||||||
onCheckedChanged:
|
onCheckedChanged:
|
||||||
{
|
{
|
||||||
@ -128,11 +136,12 @@ Item
|
|||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
property var _model: Cura.ExtrudersModel { id: extrudersModel }
|
property var _model: Cura.ExtrudersModel { id: extrudersModel }
|
||||||
model: _model.items.length > 1 ? _model : 0
|
model: _model.items.length > 1 ? _model : 0
|
||||||
ExtruderButton
|
|
||||||
|
delegate: ExtruderButton
|
||||||
{
|
{
|
||||||
extruder: model
|
extruder: model
|
||||||
height: UM.Theme.getSize("button").width
|
topElement: extrudersModel.getItem(0).id == model.id
|
||||||
width: UM.Theme.getSize("button").width
|
bottomElement: extrudersModel.getItem(extrudersModel.rowCount() - 1).id == model.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
92
resources/qml/ToolbarButton.qml
Normal file
92
resources/qml/ToolbarButton.qml
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// Copyright (c) 2018 Ultimaker B.V.
|
||||||
|
// Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
import QtQuick 2.7
|
||||||
|
import QtQuick.Controls 2.3
|
||||||
|
|
||||||
|
import UM 1.2 as UM
|
||||||
|
import Cura 1.0 as Cura
|
||||||
|
|
||||||
|
Button
|
||||||
|
{
|
||||||
|
id: base
|
||||||
|
|
||||||
|
property alias toolItem: contentItemLoader.sourceComponent
|
||||||
|
property bool topElement: false
|
||||||
|
property bool bottomElement: false
|
||||||
|
|
||||||
|
hoverEnabled: true
|
||||||
|
|
||||||
|
background: Rectangle
|
||||||
|
{
|
||||||
|
implicitWidth: UM.Theme.getSize("button").width
|
||||||
|
implicitHeight: UM.Theme.getSize("button").height
|
||||||
|
color:
|
||||||
|
{
|
||||||
|
if (base.checked && base.hovered)
|
||||||
|
{
|
||||||
|
return UM.Theme.getColor("toolbar_button_active_hover")
|
||||||
|
}
|
||||||
|
else if (base.checked)
|
||||||
|
{
|
||||||
|
return "red" //UM.Theme.getColor("toolbar_button_active")
|
||||||
|
}
|
||||||
|
else if(base.hovered)
|
||||||
|
{
|
||||||
|
return UM.Theme.getColor("toolbar_button_hover")
|
||||||
|
}
|
||||||
|
return UM.Theme.getColor("toolbar_background")
|
||||||
|
}
|
||||||
|
radius: UM.Theme.getSize("default_radius").width
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
id: topSquare
|
||||||
|
anchors
|
||||||
|
{
|
||||||
|
left: parent.left
|
||||||
|
right: parent.right
|
||||||
|
top: parent.top
|
||||||
|
}
|
||||||
|
height: parent.radius
|
||||||
|
color: base.topElement ? "transparent" : parent.color
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
id: bottomSquare
|
||||||
|
anchors
|
||||||
|
{
|
||||||
|
left: parent.left
|
||||||
|
right: parent.right
|
||||||
|
bottom: parent.bottom
|
||||||
|
}
|
||||||
|
height: parent.radius
|
||||||
|
color: base.bottomElement ? "transparent" : parent.color
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle
|
||||||
|
{
|
||||||
|
id: leftSquare
|
||||||
|
anchors
|
||||||
|
{
|
||||||
|
left: parent.left
|
||||||
|
top: parent.top
|
||||||
|
bottom: parent.bottom
|
||||||
|
}
|
||||||
|
width: parent.radius
|
||||||
|
color: parent.color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contentItem: Item
|
||||||
|
{
|
||||||
|
Loader
|
||||||
|
{
|
||||||
|
id: contentItemLoader
|
||||||
|
anchors.centerIn: parent
|
||||||
|
width: UM.Theme.getSize("button_icon").width
|
||||||
|
height: UM.Theme.getSize("button_icon").height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,3 +13,4 @@ OutputDevicesActionButton 1.0 OutputDevicesActionButton.qml
|
|||||||
ExpandableComponent 1.0 ExpandableComponent.qml
|
ExpandableComponent 1.0 ExpandableComponent.qml
|
||||||
PrinterTypeLabel 1.0 PrinterTypeLabel.qml
|
PrinterTypeLabel 1.0 PrinterTypeLabel.qml
|
||||||
ViewsSelector 1.0 ViewsSelector.qml
|
ViewsSelector 1.0 ViewsSelector.qml
|
||||||
|
ToolbarButton 1.0 ToolbarButton.qml
|
Loading…
x
Reference in New Issue
Block a user