|
| 1 | +// Copyright (c) 2022 Aldo Hoeben / fieldOfView |
| 2 | +// SidebarGUIPlugin is released under the terms of the AGPLv3 or higher. |
| 3 | + |
| 4 | +import QtQuick 2.9 |
| 5 | +import QtQuick.Layouts 1.1 |
| 6 | +import QtQuick.Controls 2.3 |
| 7 | + |
| 8 | +import UM 1.3 as UM |
| 9 | +import Cura 1.1 as Cura |
| 10 | + |
| 11 | +Button |
| 12 | +{ |
| 13 | + id: openFileButton |
| 14 | + |
| 15 | + property var fileProviderModel: CuraApplication.getFileProviderModel() |
| 16 | + |
| 17 | + height: UM.Theme.getSize("button").height |
| 18 | + width: height |
| 19 | + x: -4 * UM.Theme.getSize("default_lining").width |
| 20 | + onClicked: |
| 21 | + { |
| 22 | + if (fileProviderModel.count <= 1) |
| 23 | + { |
| 24 | + Cura.Actions.open.trigger() |
| 25 | + } |
| 26 | + else |
| 27 | + { |
| 28 | + toggleContent() |
| 29 | + } |
| 30 | + } |
| 31 | + function toggleContent() |
| 32 | + { |
| 33 | + if (openFileButtonMenu.visible) |
| 34 | + { |
| 35 | + openFileButtonMenu.close() |
| 36 | + } |
| 37 | + else |
| 38 | + { |
| 39 | + openFileButtonMenu.open() |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + hoverEnabled: true |
| 44 | + |
| 45 | + contentItem: Rectangle |
| 46 | + { |
| 47 | + anchors.left: parent.left |
| 48 | + anchors.leftMargin: UM.Theme.getSize("thin_margin").width |
| 49 | + |
| 50 | + opacity: parent.enabled ? 1.0 : 0.2 |
| 51 | + radius: Math.round(width * 0.5) |
| 52 | + |
| 53 | + color: |
| 54 | + { |
| 55 | + if(parent.hovered) |
| 56 | + { |
| 57 | + return UM.Theme.getColor("toolbar_button_hover") |
| 58 | + } |
| 59 | + return UM.Theme.getColor("toolbar_background") |
| 60 | + } |
| 61 | + |
| 62 | + UM.ColorImage |
| 63 | + { |
| 64 | + id: buttonIcon |
| 65 | + anchors.centerIn: parent |
| 66 | + width: height |
| 67 | + height: parent.height - UM.Theme.getSize("default_margin").height |
| 68 | + source: UM.Theme.getIcon("Folder", "medium") |
| 69 | + color: UM.Theme.getColor("icon") |
| 70 | + } |
| 71 | + |
| 72 | + UM.ColorImage |
| 73 | + { |
| 74 | + anchors |
| 75 | + { |
| 76 | + right: parent.right |
| 77 | + rightMargin: -4 * UM.Theme.getSize("default_lining").width |
| 78 | + bottom: parent.bottom |
| 79 | + bottomMargin: -2 * UM.Theme.getSize("default_lining").height |
| 80 | + } |
| 81 | + source: UM.Theme.getIcon("ChevronSingleDown") |
| 82 | + visible: fileProviderModel.count > 1 |
| 83 | + width: UM.Theme.getSize("standard_arrow").width |
| 84 | + height: UM.Theme.getSize("standard_arrow").height |
| 85 | + color: UM.Theme.getColor("icon") |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + background: Cura.RoundedRectangle |
| 90 | + { |
| 91 | + id: buttonBackground |
| 92 | + height: UM.Theme.getSize("button").height |
| 93 | + width: UM.Theme.getSize("button").width + UM.Theme.getSize("narrow_margin").width |
| 94 | + |
| 95 | + radius: UM.Theme.getSize("default_radius").width |
| 96 | + cornerSide: Cura.RoundedRectangle.Direction.Right |
| 97 | + |
| 98 | + color: UM.Theme.getColor("toolbar_background") |
| 99 | + border.width: UM.Theme.getSize("default_lining").width |
| 100 | + border.color: UM.Theme.getColor("lining") |
| 101 | + } |
| 102 | + |
| 103 | + Popup |
| 104 | + { |
| 105 | + id: openFileButtonMenu |
| 106 | + |
| 107 | + // Make the content aligned with the rest, using the property contentAlignment to decide whether is right or left. |
| 108 | + // In case of right alignment, the 3x padding is due to left, right and padding between the button & text. |
| 109 | + y: buttonBackground.height + 2 * UM.Theme.getSize("default_lining").height |
| 110 | + padding: UM.Theme.getSize("default_margin").width |
| 111 | + closePolicy: Popup.CloseOnPressOutsideParent |
| 112 | + |
| 113 | + background: Cura.RoundedRectangle |
| 114 | + { |
| 115 | + cornerSide: Cura.RoundedRectangle.Direction.All |
| 116 | + color: UM.Theme.getColor("action_button") |
| 117 | + border.width: UM.Theme.getSize("default_lining").width |
| 118 | + border.color: UM.Theme.getColor("lining") |
| 119 | + radius: UM.Theme.getSize("default_radius").width |
| 120 | + } |
| 121 | + |
| 122 | + contentItem: Item |
| 123 | + { |
| 124 | + id: popup |
| 125 | + |
| 126 | + Column |
| 127 | + { |
| 128 | + id: openProviderColumn |
| 129 | + |
| 130 | + //The column doesn't automatically listen to its children rect if the children change internally, so we need to explicitly update the size. |
| 131 | + onChildrenRectChanged: |
| 132 | + { |
| 133 | + popup.height = childrenRect.height |
| 134 | + popup.width = childrenRect.width |
| 135 | + } |
| 136 | + onPositioningComplete: |
| 137 | + { |
| 138 | + popup.height = childrenRect.height |
| 139 | + popup.width = childrenRect.width |
| 140 | + } |
| 141 | + |
| 142 | + Repeater |
| 143 | + { |
| 144 | + model: openFileButton.fileProviderModel |
| 145 | + delegate: Button |
| 146 | + { |
| 147 | + leftPadding: UM.Theme.getSize("default_margin").width |
| 148 | + rightPadding: UM.Theme.getSize("default_margin").width |
| 149 | + width: contentItem.width + leftPadding + rightPadding |
| 150 | + height: UM.Theme.getSize("action_button").height |
| 151 | + hoverEnabled: true |
| 152 | + |
| 153 | + contentItem: Label |
| 154 | + { |
| 155 | + text: model.displayText |
| 156 | + color: UM.Theme.getColor("text") |
| 157 | + font: UM.Theme.getFont("medium") |
| 158 | + renderType: Text.NativeRendering |
| 159 | + verticalAlignment: Text.AlignVCenter |
| 160 | + |
| 161 | + width: contentWidth |
| 162 | + height: parent.height |
| 163 | + } |
| 164 | + |
| 165 | + onClicked: |
| 166 | + { |
| 167 | + if(model.index == 0) //The 0th element is the "From Disk" option, which should activate the open local file dialog. |
| 168 | + { |
| 169 | + Cura.Actions.open.trigger(); |
| 170 | + } |
| 171 | + else |
| 172 | + { |
| 173 | + openFileButton.fileProviderModel.trigger(model.name); |
| 174 | + } |
| 175 | + openFileButton.toggleContent(); |
| 176 | + } |
| 177 | + |
| 178 | + background: Rectangle |
| 179 | + { |
| 180 | + color: parent.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent" |
| 181 | + radius: UM.Theme.getSize("action_button_radius").width |
| 182 | + width: popup.width |
| 183 | + } |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | +} |
0 commit comments