diff --git a/qml/Printer.qml b/qml/Printer.qml index 88bc7eff69..59ac3fde10 100644 --- a/qml/Printer.qml +++ b/qml/Printer.qml @@ -143,7 +143,7 @@ UM.MainWindow { } } - UM.Sidebar { + Sidebar { id: sidebar; anchors { diff --git a/qml/SaveButton.qml b/qml/SaveButton.qml new file mode 100644 index 0000000000..5216886e90 --- /dev/null +++ b/qml/SaveButton.qml @@ -0,0 +1,183 @@ +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Controls.Styles 1.1 +import QtQuick.Layouts 1.1 + +import UM 1.0 as UM + +Button { + id: base; + + property Action saveAction; + + property real progress: UM.Backend.progress; + Behavior on progress { NumberAnimation { duration: 250; } } + + enabled: progress >= 0.95; + + property string currentDevice: 'local_file' + property bool defaultOverride: false; + property bool defaultAmbiguous: false; + + iconSource: UM.Theme.icons[Printer.outputDevices[base.currentDevice].icon]; + tooltip: Printer.outputDevices[base.currentDevice].description; + + 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; + } + } + } + } + + style: ButtonStyle { + background: UM.AngledCornerRectangle { + implicitWidth: control.width; + implicitHeight: control.height; + + color: UM.Theme.colors.save_button_border; + cornerSize: UM.Theme.sizes.default_margin.width; + + UM.AngledCornerRectangle { + anchors.fill: parent; + anchors.margins: UM.Theme.sizes.save_button_border.width; + cornerSize: UM.Theme.sizes.default_margin.width; + color: UM.Theme.colors.save_button; + } + + UM.AngledCornerRectangle { + anchors { + left: parent.left; + top: parent.top; + bottom: parent.bottom; + } + + width: Math.max(parent.height + (parent.width - parent.height) * control.progress, parent.height); + cornerSize: UM.Theme.sizes.default_margin.width; + + color: !control.enabled ? UM.Theme.colors.save_button_inactive : control.hovered ? UM.Theme.colors.save_button_active_hover : UM.Theme.colors.save_button_active; + Behavior on color { ColorAnimation { duration: 50; } } + } + + UM.AngledCornerRectangle { + anchors.left: parent.left; + width: parent.height + UM.Theme.sizes.save_button_border.width; + height: parent.height; + cornerSize: UM.Theme.sizes.default_margin.width; + color: UM.Theme.colors.save_button; + } + + UM.AngledCornerRectangle { + anchors.left: parent.left; + width: parent.height + UM.Theme.sizes.save_button_border.width; + height: parent.height; + cornerSize: UM.Theme.sizes.default_margin.width; + + color: UM.Theme.colors.save_button; + } + + UM.AngledCornerRectangle { + id: icon; + + anchors.left: parent.left; + width: parent.height; + height: parent.height; + cornerSize: UM.Theme.sizes.default_margin.width; + color: !control.enabled ? UM.Theme.colors.save_button_inactive : control.hovered ? UM.Theme.colors.save_button_active_hover : UM.Theme.colors.save_button_active; + Behavior on color { ColorAnimation { duration: 50; } } + + Image { + anchors.centerIn: parent; + + width: UM.Theme.sizes.button_icon.width; + height: UM.Theme.sizes.button_icon.height; + + sourceSize.width: width; + sourceSize.height: height; + + source: control.iconSource; + } + } + } + + label: Label { + id: label; + anchors.top: parent.top; + anchors.topMargin: UM.Theme.sizes.save_button_label_margin.height; + anchors.left: parent.left; + anchors.leftMargin: control.height + UM.Theme.sizes.save_button_label_margin.width; + + color: UM.Theme.colors.save_button_text; + font: UM.Theme.fonts.default; + + text: control.text; + } + } + + MouseArea { + anchors.fill: parent; + + acceptedButtons: Qt.RightButton; + + onClicked: devicesMenu.popup(); + } + + Menu { + id: devicesMenu; + + Instantiator { + model: Printer.outputDeviceNames; + MenuItem { + text: Printer.outputDevices[modelData].description; + checkable: true; + checked: base.defaultAmbiguous ? false : modelData == base.currentDevice; + exclusiveGroup: devicesMenuGroup; + onTriggered: { + base.defaultOverride = true; + base.currentDevice = modelData; + if(base.defaultAmbiguous) { + base.defaultAmbiguous = false; + Printer.writeToOutputDevice(modelData); + } + } + } + onObjectAdded: devicesMenu.insertItem(index, object) + onObjectRemoved: devicesMenu.removeItem(object) + } + + ExclusiveGroup { id: devicesMenuGroup; } + } + + text: { + if(base.progress < 0) { + return qsTr("Please load a 3D model"); + } else if (base.progress < 0.95) { + return qsTr("Calculating Print-time"); + } else { + return qsTr("Estimated Print-time"); + } + } + + onClicked: { + if(base.defaultAmbiguous) { + devicesMenu.popup(); + } else { + Printer.writeToOutputDevice(base.currentDevice); + } + } +} diff --git a/qml/Sidebar.qml b/qml/Sidebar.qml new file mode 100644 index 0000000000..43b6c43bbb --- /dev/null +++ b/qml/Sidebar.qml @@ -0,0 +1,76 @@ +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Controls.Styles 1.1 +import QtQuick.Layouts 1.1 + +import UM 1.0 as UM + +UM.AngledCornerRectangle { + id: base; + + property Action addMachineAction; + property Action configureMachinesAction; + property alias saveAction: saveButton.saveAction; + + cornerSize: UM.Theme.sizes.default_margin.width; + + function showTooltip(item, position, text) { + tooltip.text = text; + position = item.mapToItem(base, position.x, position.y); + tooltip.show(position); + } + + function hideTooltip() { + tooltip.hide(); + } + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.AllButtons; + + onWheel: { + wheel.accepted = true; + } + } + + ColumnLayout { + anchors.fill: parent; + anchors.topMargin: UM.Theme.sizes.default_margin.height; + anchors.bottomMargin: UM.Theme.sizes.window_margin.height; + + spacing: UM.Theme.sizes.default_margin.height; + + SidebarHeader { + id: header; + + Layout.fillWidth: true; + + addMachineAction: base.addMachineAction; + configureMachinesAction: base.configureMachinesAction; + } + + Loader { + id: sidebarContents; + + Layout.fillWidth: true; + Layout.fillHeight: true; + + source: header.currentModeFile; + + property Item sidebar: base; + + onLoaded: if(item) item.configureSettings = base.configureMachinesAction + } + + SaveButton { + id: saveButton; + Layout.preferredWidth: base.width - UM.Theme.sizes.default_margin.width * 2; + Layout.preferredHeight: UM.Theme.sizes.button.height; + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter; + } + } + + SidebarTooltip { + id: tooltip; + } +} diff --git a/qml/SidebarHeader.qml b/qml/SidebarHeader.qml new file mode 100644 index 0000000000..d3417fd66c --- /dev/null +++ b/qml/SidebarHeader.qml @@ -0,0 +1,120 @@ +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Controls.Styles 1.1 +import QtQuick.Layouts 1.1 + +import UM 1.0 as UM + +Column { + id: base; + + property string currentModeFile: modeModel.get(modeMenu.currentIndex).file; + property Action addMachineAction; + property Action configureMachinesAction; + + spacing: UM.Theme.sizes.default_margin.height; + + RowLayout { + anchors.horizontalCenter: parent.horizontalCenter; + + width: parent.width - UM.Theme.sizes.default_margin.width * 2; + height: UM.Theme.sizes.line.height; + + Label { + text: qsTr("Mode:"); + + font: UM.Theme.fonts.sidebar_header; + color: UM.Theme.colors.text_inactive; + } + + ToolButton { + text: qsTr(modeModel.get(modeMenu.currentIndex).text); + + style: UM.Theme.styles.sidebar_header_button; + + Layout.preferredWidth: base.width * 0.25; + + menu: Menu { + id: modeMenu; + + property int currentIndex: 0; + + Instantiator { + model: ListModel { + id: modeModel; + ListElement { text: QT_TR_NOOP("Simple"); file: "SidebarSimple.qml" } + ListElement { text: QT_TR_NOOP("Advanced"); file: "../../UM/Qt/qml/UM/SettingView.qml" } + } + + MenuItem { + text: qsTr(model.text); + checkable: true; + checked: modeMenu.currentIndex == index; + exclusiveGroup: modeMenuGroup; + onTriggered: modeMenu.currentIndex = index; + } + onObjectAdded: modeMenu.insertItem(index, object) + onObjectRemoved: modeMenu.removeItem(object) + } + + ExclusiveGroup { id: modeMenuGroup; } + } + } + + Rectangle { + width: 1; + height: parent.height; + color: UM.Theme.colors.border; + } + + Label { + text: qsTr("Machine:"); + + font: UM.Theme.fonts.sidebar_header; + color: UM.Theme.colors.text_inactive; + } + + ToolButton { + id: machineButton; + text: UM.Application.machineName; + + style: UM.Theme.styles.sidebar_header_button; + + Layout.fillWidth: true; + + menu: Menu { + id: machineMenu; + Instantiator { + model: UM.Models.machinesModel + MenuItem { + text: model.name; + checkable: true; + checked: model.active; + exclusiveGroup: machineMenuGroup; + onTriggered: UM.Models.machinesModel.setActive(index) + } + onObjectAdded: machineMenu.insertItem(index, object) + onObjectRemoved: machineMenu.removeItem(object) + } + + ExclusiveGroup { id: machineMenuGroup; } + + MenuSeparator { } + + MenuItem { action: base.addMachineAction; } + MenuItem { action: base.configureMachinesAction; } + } + } + } + + UM.SidebarCategoryHeader { + width: parent.width; + height: UM.Theme.sizes.section.height; + + iconSource: UM.Theme.icons.printsetup; + text: qsTr("Setup"); + enabled: false; + + color: UM.Theme.colors.primary; + } +} diff --git a/qml/SidebarSimple.qml b/qml/SidebarSimple.qml new file mode 100644 index 0000000000..53dbb5a48a --- /dev/null +++ b/qml/SidebarSimple.qml @@ -0,0 +1,82 @@ +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Controls.Styles 1.1 +import QtQuick.Layouts 1.1 + +import UM 1.0 as UM + +Item { + anchors.fill: parent; + anchors.leftMargin: UM.Theme.sizes.default_margin.width; + anchors.rightMargin: UM.Theme.sizes.default_margin.width; + + property Action configureSettings; + + ColumnLayout { + anchors.fill: parent; + + Item { + Layout.fillWidth: true; + Layout.preferredHeight: UM.Theme.sizes.section.height; + + Label { + anchors.left: parent.left; + anchors.verticalCenter: parent.verticalCenter; + text: "00:00"; + font: UM.Theme.fonts.timeslider_time; + color: UM.Theme.colors.primary; + } + Label { anchors.centerIn: parent; text: "Estimated Print Time"; color: UM.Theme.colors.text; font: UM.Theme.fonts.default; } + Label { + anchors.right: parent.right; + anchors.verticalCenter: parent.verticalCenter; + text: "21:00"; + font: UM.Theme.fonts.timeslider_time; + color: UM.Theme.colors.primary; + } + } + + Slider { + Layout.fillWidth: true; + Layout.preferredHeight: UM.Theme.sizes.section.height; + + minimumValue: 0; + maximumValue: 100; + + style: UM.Theme.styles.slider; + } + + Item { + Layout.fillWidth: true; + Layout.preferredHeight: UM.Theme.sizes.section.height; + + Label { + anchors.left: parent.left; + anchors.verticalCenter: parent.verticalCenter; + text: "Minimum\nDraft"; + color: UM.Theme.colors.text; + font: UM.Theme.fonts.default; + } + + Label { + anchors.right: parent.right; + anchors.verticalCenter: parent.verticalCenter; + text: "Maximum\nQuality"; + horizontalAlignment: Text.AlignRight; + color: UM.Theme.colors.text; + font: UM.Theme.fonts.default; + } + } + + CheckBox { + Layout.fillWidth: true; + Layout.preferredHeight: UM.Theme.sizes.section.height; + + text: "Enable Support"; + + style: UM.Theme.styles.checkbox; + } + + Item { Layout.fillWidth: true; Layout.fillHeight: true; } + } +} diff --git a/qml/SidebarTooltip.qml b/qml/SidebarTooltip.qml new file mode 100644 index 0000000000..643e6b75e0 --- /dev/null +++ b/qml/SidebarTooltip.qml @@ -0,0 +1,48 @@ +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Controls.Styles 1.1 +import QtQuick.Layouts 1.1 + +import UM 1.0 as UM + +Rectangle { + id: base; + + width: UM.Theme.sizes.tooltip.width; + height: label.height + UM.Theme.sizes.tooltip_margins.height * 2; + color: UM.Theme.colors.tooltip; + + opacity: 0; + Behavior on opacity { NumberAnimation { duration: 100; } } + + property alias text: label.text; + + function show(position) { + if(position.y + base.height > parent.height) { + x = position.x; + y = parent.height - base.height; + } else { + x = position.x; + y = position.y; + } + base.opacity = 1; + } + + function hide() { + base.opacity = 0; + } + + Label { + id: label; + anchors { + top: parent.top; + topMargin: UM.Theme.sizes.tooltip_margins.height; + left: parent.left; + leftMargin: UM.Theme.sizes.tooltip_margins.width; + right: parent.right; + rightMargin: UM.Theme.sizes.tooltip_margins.width; + } + wrapMode: Text.Wrap; + font: UM.Theme.fonts.default; + } +}