Cura/resources/qml/PrintSetupSelector/PrintSetupSelectorContents.qml

202 lines
6.6 KiB
QML

// 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.3 as UM
import Cura 1.0 as Cura
import "Recommended"
import "Custom"
Item
{
id: content
width: UM.Theme.getSize("print_setup_widget").width - 2 * UM.Theme.getSize("default_margin").width
height: contents.height + buttonRow.height
enum Mode
{
Recommended = 0,
Custom = 1
}
// Set the current mode index to the value that is stored in the preferences or Recommended mode otherwise.
property int currentModeIndex:
{
var index = Math.round(UM.Preferences.getValue("cura/active_mode"))
if (index != null && !isNaN(index))
{
return index
}
return PrintSetupSelectorContents.Mode.Recommended
}
onCurrentModeIndexChanged: UM.Preferences.setValue("cura/active_mode", currentModeIndex)
Item
{
id: contents
// Use the visible property instead of checking the currentModeIndex. That creates a binding that
// evaluates the new height every time the visible property changes.
height: recommendedPrintSetup.visible ? recommendedPrintSetup.height : customPrintSetup.height
anchors
{
top: parent.top
left: parent.left
right: parent.right
}
RecommendedPrintSetup
{
id: recommendedPrintSetup
anchors
{
left: parent.left
right: parent.right
top: parent.top
}
visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended
}
CustomPrintSetup
{
id: customPrintSetup
anchors
{
left: parent.left
right: parent.right
top: parent.top
}
height: UM.Preferences.getValue("view/settings_list_height") - UM.Theme.getSize("default_margin").height
Connections
{
target: UM.Preferences
onPreferenceChanged:
{
if (preference !== "view/settings_list_height" && preference !== "general/window_height" && preference !== "general/window_state")
{
return;
}
customPrintSetup.height =
Math.min
(
UM.Preferences.getValue("view/settings_list_height"),
base.height - (customPrintSetup.mapToItem(null, 0, 0).y + buttonRow.height + UM.Theme.getSize("default_margin").height)
);
}
}
visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
}
}
Rectangle
{
id: buttonsSeparator
// The buttonsSeparator is inside the contents. This is to avoid a double line in the bottom
anchors.bottom: contents.bottom
width: parent.width
height: UM.Theme.getSize("default_lining").height
color: UM.Theme.getColor("lining")
}
Item
{
id: buttonRow
property real padding: UM.Theme.getSize("default_margin").width
height: childrenRect.height + 2 * padding
anchors
{
bottom: parent.bottom
left: parent.left
right: parent.right
}
Cura.SecondaryButton
{
id: recommendedButton
anchors.top: parent.top
anchors.left: parent.left
anchors.margins: parent.padding
leftPadding: UM.Theme.getSize("default_margin").width
rightPadding: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@button", "Recommended")
iconSource: UM.Theme.getIcon("arrow_left")
visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Recommended
}
Cura.SecondaryButton
{
anchors.top: parent.top
anchors.right: parent.right
anchors.margins: UM.Theme.getSize("default_margin").width
leftPadding: UM.Theme.getSize("default_margin").width
rightPadding: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@button", "Custom")
iconSource: UM.Theme.getIcon("arrow_right")
isIconOnRightSide: true
visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended
onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Custom
}
//Invisible area at the bottom with which you can resize the panel.
MouseArea
{
anchors
{
left: parent.left
right: parent.right
bottom: parent.bottom
top: recommendedButton.bottom
topMargin: UM.Theme.getSize("default_lining").height
}
cursorShape: Qt.SplitVCursor
visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
drag
{
target: parent
axis: Drag.YAxis
}
onMouseYChanged:
{
if(drag.active)
{
// position of mouse relative to dropdown align vertical centre of mouse area to cursor
// v------------------------------v v------------v
var h = mouseY + buttonRow.y + content.y - height / 2 | 0;
if(h < 200 * screenScaleFactor) //Enforce a minimum size.
{
h = 200 * screenScaleFactor;
}
//Absolute mouse Y position in the window, to prevent it from going outside the window.
var mouse_absolute_y = mapToGlobal(mouseX, mouseY).y - UM.Preferences.getValue("general/window_top");
if(mouse_absolute_y > base.height)
{
h -= mouse_absolute_y - base.height;
}
UM.Preferences.setValue("view/settings_list_height", h);
}
}
UM.RecolorImage
{
width: parent.width * 0.05
height: parent.height * 0.3
anchors.centerIn: parent
source: UM.Theme.getIcon("grip_lines")
color: UM.Theme.getColor("lining")
}
}
}
}