Skip to content

Commit 5338def

Browse files
committed
Add open file dropdown
1 parent 348d06a commit 5338def

1 file changed

Lines changed: 118 additions & 3 deletions

File tree

resources/qml/OpenFileButton411.qml

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright (c) 2020 Aldo Hoeben / fieldOfView
22
// SidebarGUIPlugin is released under the terms of the AGPLv3 or higher.
33

4-
import QtQuick 2.7
4+
import QtQuick 2.9
5+
import QtQuick.Layouts 1.1
56
import QtQuick.Controls 2.3
67

78
import UM 1.3 as UM
@@ -11,9 +12,33 @@ Button
1112
{
1213
id: openFileButton
1314

15+
property var fileProviderModel: CuraApplication.getFileProviderModel()
16+
1417
height: UM.Theme.getSize("button").height
1518
width: height + 4 * UM.Theme.getSize("default_lining").width // There's some magic going on here
16-
onClicked: Cura.Actions.open.trigger()
19+
onClicked:
20+
{
21+
if (fileProviderModel.count <= 1)
22+
{
23+
Cura.Actions.open.trigger()
24+
}
25+
else
26+
{
27+
toggleContent()
28+
}
29+
}
30+
function toggleContent()
31+
{
32+
if (openFileButtonMenu.visible)
33+
{
34+
openFileButtonMenu.close()
35+
}
36+
else
37+
{
38+
openFileButtonMenu.open()
39+
}
40+
}
41+
1742
hoverEnabled: true
1843

1944
contentItem: Rectangle
@@ -48,7 +73,7 @@ Button
4873

4974
background: Cura.RoundedRectangle
5075
{
51-
id: background
76+
id: buttonBackground
5277
height: UM.Theme.getSize("button").height
5378
width: UM.Theme.getSize("button").width + UM.Theme.getSize("narrow_margin").width
5479

@@ -59,4 +84,94 @@ Button
5984
border.width: UM.Theme.getSize("default_lining").width
6085
border.color: UM.Theme.getColor("lining")
6186
}
87+
88+
Popup
89+
{
90+
id: openFileButtonMenu
91+
92+
// Ensure that the content is located directly below the headerItem
93+
//y: background.height + base.popupOffset
94+
95+
// Make the content aligned with the rest, using the property contentAlignment to decide whether is right or left.
96+
// In case of right alignment, the 3x padding is due to left, right and padding between the button & text.
97+
y: buttonBackground.height + 2 * UM.Theme.getSize("default_lining").height
98+
padding: UM.Theme.getSize("default_margin").width
99+
closePolicy: Popup.CloseOnPressOutsideParent
100+
101+
background: Cura.RoundedRectangle
102+
{
103+
cornerSide: Cura.RoundedRectangle.Direction.All
104+
color: UM.Theme.getColor("action_button")
105+
border.width: UM.Theme.getSize("default_lining").width
106+
border.color: UM.Theme.getColor("lining")
107+
radius: UM.Theme.getSize("default_radius").width
108+
}
109+
110+
contentItem: Item
111+
{
112+
id: popup
113+
114+
Column
115+
{
116+
id: openProviderColumn
117+
118+
//The column doesn't automatically listen to its children rect if the children change internally, so we need to explicitly update the size.
119+
onChildrenRectChanged:
120+
{
121+
popup.height = childrenRect.height
122+
popup.width = childrenRect.width
123+
}
124+
onPositioningComplete:
125+
{
126+
popup.height = childrenRect.height
127+
popup.width = childrenRect.width
128+
}
129+
130+
Repeater
131+
{
132+
model: openFileButton.fileProviderModel
133+
delegate: Button
134+
{
135+
leftPadding: UM.Theme.getSize("default_margin").width
136+
rightPadding: UM.Theme.getSize("default_margin").width
137+
width: contentItem.width + leftPadding + rightPadding
138+
height: UM.Theme.getSize("action_button").height
139+
hoverEnabled: true
140+
141+
contentItem: Label
142+
{
143+
text: model.displayText
144+
color: UM.Theme.getColor("text")
145+
font: UM.Theme.getFont("medium")
146+
renderType: Text.NativeRendering
147+
verticalAlignment: Text.AlignVCenter
148+
149+
width: contentWidth
150+
height: parent.height
151+
}
152+
153+
onClicked:
154+
{
155+
if(model.index == 0) //The 0th element is the "From Disk" option, which should activate the open local file dialog.
156+
{
157+
Cura.Actions.open.trigger();
158+
}
159+
else
160+
{
161+
openFileButton.fileProviderModel.trigger(model.name);
162+
}
163+
openFileButton.toggleContent();
164+
}
165+
166+
background: Rectangle
167+
{
168+
color: parent.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
169+
radius: UM.Theme.getSize("action_button_radius").width
170+
width: popup.width
171+
}
172+
}
173+
}
174+
}
175+
}
176+
}
62177
}

0 commit comments

Comments
 (0)