Add a object list panel instead of the open file button

This commit is contained in:
Diego Prado Gesto 2019-02-15 17:50:52 +01:00
parent 75b185d462
commit 86c7d3e5ab
7 changed files with 240 additions and 59 deletions

View file

@ -864,7 +864,7 @@ class CuraApplication(QtApplication):
def getObjectsModel(self, *args):
if self._object_manager is None:
self._object_manager = ObjectsModel.createObjectsModel()
self._object_manager = ObjectsModel(self)
return self._object_manager
@pyqtSlot(result = QObject)
@ -967,7 +967,7 @@ class CuraApplication(QtApplication):
qmlRegisterType(NetworkMJPGImage, "Cura", 1, 0, "NetworkMJPGImage")
qmlRegisterSingletonType(ObjectsModel, "Cura", 1, 0, "ObjectsModel", self.getObjectsModel)
qmlRegisterType(ObjectsModel, "Cura", 1, 0, "ObjectsModel")
qmlRegisterType(BuildPlateModel, "Cura", 1, 0, "BuildPlateModel")
qmlRegisterType(MultiBuildPlateModel, "Cura", 1, 0, "MultiBuildPlateModel")
qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer")

View file

@ -1,7 +1,7 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import QTimer
from PyQt5.QtCore import QTimer, Qt
from UM.Application import Application
from UM.Qt.ListModel import ListModel
@ -16,8 +16,20 @@ catalog = i18nCatalog("cura")
## Keep track of all objects in the project
class ObjectsModel(ListModel):
def __init__(self):
super().__init__()
NameRole = Qt.UserRole + 1
SelectedRole = Qt.UserRole + 2
OutsideAreaRole = Qt.UserRole + 3
BuilplateNumberRole = Qt.UserRole + 4
NodeRole = Qt.UserRole + 5
def __init__(self, parent = None):
super().__init__(parent)
self.addRoleName(self.NameRole, "name")
self.addRoleName(self.SelectedRole, "selected")
self.addRoleName(self.OutsideAreaRole, "outside_build_area")
self.addRoleName(self.BuilplateNumberRole, "buildplate_number")
self.addRoleName(self.SelectedRole, "node")
Application.getInstance().getController().getScene().sceneChanged.connect(self._updateDelayed)
Application.getInstance().getPreferences().preferenceChanged.connect(self._updateDelayed)
@ -78,9 +90,9 @@ class ObjectsModel(ListModel):
nodes.append({
"name": name,
"isSelected": Selection.isSelected(node),
"isOutsideBuildArea": is_outside_build_area,
"buildPlateNumber": node_build_plate_number,
"selected": Selection.isSelected(node),
"outside_build_area": is_outside_build_area,
"buildplate_number": node_build_plate_number,
"node": node
})
@ -88,7 +100,3 @@ class ObjectsModel(ListModel):
self.setItems(nodes)
self.itemsChanged.emit()
@staticmethod
def createObjectsModel():
return ObjectsModel()

View file

@ -24,14 +24,14 @@ Item
Item
{
anchors.horizontalCenter: parent.horizontalCenter
width: openFileButton.width + itemRow.width + UM.Theme.getSize("default_margin").width
width: objectSelector.width + itemRow.width + UM.Theme.getSize("default_margin").width
height: parent.height
RowLayout
{
id: itemRow
anchors.left: openFileButton.right
anchors.left: objectSelector.right
anchors.leftMargin: UM.Theme.getSize("default_margin").width
width: Math.round(0.9 * prepareMenu.width)
@ -82,53 +82,60 @@ Item
}
}
Button
Cura.ObjectSelector
{
id: openFileButton
id: objectSelector
height: UM.Theme.getSize("stage_menu").height
width: UM.Theme.getSize("stage_menu").height
onClicked: Cura.Actions.open.trigger()
hoverEnabled: true
contentItem: Item
{
anchors.fill: parent
UM.RecolorImage
{
id: buttonIcon
anchors.centerIn: parent
source: UM.Theme.getIcon("load")
width: UM.Theme.getSize("button_icon").width
height: UM.Theme.getSize("button_icon").height
color: UM.Theme.getColor("icon")
sourceSize.height: height
}
}
background: Rectangle
{
id: background
height: UM.Theme.getSize("stage_menu").height
width: UM.Theme.getSize("stage_menu").height
radius: UM.Theme.getSize("default_radius").width
color: openFileButton.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
}
DropShadow
{
id: shadow
// Don't blur the shadow
radius: 0
anchors.fill: background
source: background
verticalOffset: 2
visible: true
color: UM.Theme.getColor("action_button_shadow")
// Should always be drawn behind the background.
z: background.z - 1
}
}
// Button
// {
// id: openFileButton
// height: UM.Theme.getSize("stage_menu").height
// width: UM.Theme.getSize("stage_menu").height
// onClicked: Cura.Actions.open.trigger()
// hoverEnabled: true
//
// contentItem: Item
// {
// anchors.fill: parent
// UM.RecolorImage
// {
// id: buttonIcon
// anchors.centerIn: parent
// source: UM.Theme.getIcon("load")
// width: UM.Theme.getSize("button_icon").width
// height: UM.Theme.getSize("button_icon").height
// color: UM.Theme.getColor("icon")
//
// sourceSize.height: height
// }
// }
//
// background: Rectangle
// {
// id: background
// height: UM.Theme.getSize("stage_menu").height
// width: UM.Theme.getSize("stage_menu").height
//
// radius: UM.Theme.getSize("default_radius").width
// color: openFileButton.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
// }
//
// DropShadow
// {
// id: shadow
// // Don't blur the shadow
// radius: 0
// anchors.fill: background
// source: background
// verticalOffset: 2
// visible: true
// color: UM.Theme.getColor("action_button_shadow")
// // Should always be drawn behind the background.
// z: background.z - 1
// }
// }
}
}

View file

@ -0,0 +1,58 @@
// 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.1
import UM 1.1 as UM
import Cura 1.0 as Cura
Button
{
id: objectItemButton
width: parent.width
height: UM.Theme.getSize("action_button").height
leftPadding: UM.Theme.getSize("thick_margin").width
rightPadding: UM.Theme.getSize("thick_margin").width
checkable: true
hoverEnabled: true
contentItem: Item
{
width: objectItemButton.width - objectItemButton.leftPadding
height: UM.Theme.getSize("action_button").height
Label
{
id: buttonText
anchors
{
left: parent.left
right: printerTypes.left
verticalCenter: parent.verticalCenter
}
text: {
print("HOLAAAAAAAA", objectItemButton.text)
return objectItemButton.text
}
color: UM.Theme.getColor("text")
font: UM.Theme.getFont("medium")
visible: text != ""
renderType: Text.NativeRendering
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
}
background: Rectangle
{
id: backgroundRect
color: objectItemButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
radius: UM.Theme.getSize("action_button_radius").width
border.width: UM.Theme.getSize("default_lining").width
border.color: objectItemButton.checked ? UM.Theme.getColor("primary") : "transparent"
}
onClicked: Cura.SceneController.changeSelection(index)
}

View file

@ -0,0 +1,108 @@
// Copyright (c) 2019 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
Cura.ExpandableComponent
{
id: base
headerCornerSide: Cura.RoundedRectangle.Direction.All
contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft
contentHeaderTitle: catalog.i18nc("@label", "Object list")
headerItem: Item
{
anchors.fill: parent
UM.RecolorImage
{
id: buttonIcon
anchors.centerIn: parent
source: UM.Theme.getIcon("load")
width: UM.Theme.getSize("button_icon").width
height: UM.Theme.getSize("button_icon").height
color: UM.Theme.getColor("icon")
sourceSize.height: height
}
}
contentItem: Item
{
id: popup
width: UM.Theme.getSize("machine_selector_widget_content").width
ScrollView
{
id: scroll
width: parent.width
clip: true
leftPadding: UM.Theme.getSize("default_lining").width
rightPadding: UM.Theme.getSize("default_lining").width
ListView
{
id: listView
// Can't use parent.width since the parent is the flickable component and not the ScrollView
width: scroll.width - scroll.leftPadding - scroll.rightPadding
property real maximumHeight: UM.Theme.getSize("machine_selector_widget_content").height - buttonRow.height
// We use an extra property here, since we only want to to be informed about the content size changes.
onContentHeightChanged:
{
scroll.height = Math.min(contentHeight, maximumHeight)
popup.height = scroll.height + buttonRow.height
}
Component.onCompleted:
{
scroll.height = Math.min(contentHeight, maximumHeight)
popup.height = scroll.height + buttonRow.height
}
model: Cura.ObjectsModel {}
delegate: ObjectItemButton
{
text: model.name
width: listView.width
checked: model.selected
}
}
}
Rectangle
{
id: separator
anchors.top: scroll.bottom
width: parent.width
height: UM.Theme.getSize("default_lining").height
color: UM.Theme.getColor("lining")
}
Row
{
id: buttonRow
// The separator is inside the buttonRow. This is to avoid some weird behaviours with the scroll bar.
anchors.top: separator.top
anchors.horizontalCenter: parent.horizontalCenter
padding: UM.Theme.getSize("default_margin").width
spacing: UM.Theme.getSize("default_margin").width
Cura.SecondaryButton
{
leftPadding: UM.Theme.getSize("default_margin").width
rightPadding: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@button", "Add file")
onClicked: Cura.Actions.open.trigger()
}
}
}
}

View file

@ -130,7 +130,6 @@ Cura.ExpandablePopup
scroll.height = Math.min(contentHeight, maximumHeight)
popup.height = scroll.height + buttonRow.height
}
}
}

View file

@ -1,6 +1,7 @@
module Cura
MachineSelector 1.0 MachineSelector.qml
objectSelector 1.0 objectSelector.qml
CustomConfigurationSelector 1.0 CustomConfigurationSelector.qml
PrintSetupSelector 1.0 PrintSetupSelector.qml
ActionButton 1.0 ActionButton.qml