blob: 8e966c3df79cc1d3895b2316fef13fc05e0403dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
// Copyright (c) 2017 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1
import QtQuick.Controls.Styles 1.1
import UM 1.2 as UM
import Cura 1.0 as Cura
UM.Dialog
{
id: base
title: catalog.i18nc("@title:window", "Add Printer")
property bool firstRun: false
property string preferredCategory: "Ultimaker"
property string activeCategory: preferredCategory
minimumWidth: UM.Theme.getSize("modal_window_minimum").width
minimumHeight: UM.Theme.getSize("modal_window_minimum").height
width: minimumWidth
height: minimumHeight
flags:
{
var window_flags = Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint;
if (Cura.MachineManager.activeDefinitionId !== "") //Disallow closing the window if we have no active printer yet. You MUST add a printer.
{
window_flags |= Qt.WindowCloseButtonHint;
}
return window_flags;
}
onVisibilityChanged:
{
// Reset selection and machine name
if (visible) {
activeCategory = preferredCategory;
machineList.currentIndex = 0;
machineName.text = getMachineName();
}
}
signal machineAdded(string id)
function getMachineName()
{
if (machineList.model.getItem(machineList.currentIndex) != undefined)
{
return machineList.model.getItem(machineList.currentIndex).name;
}
return "";
}
function getMachineMetaDataEntry(key)
{
if (machineList.model.getItem(machineList.currentIndex) != undefined)
{
return machineList.model.getItem(machineList.currentIndex).metadata[key];
}
return "";
}
Label
{
id: titleLabel
anchors
{
top: parent.top
left: parent.left
topMargin: UM.Theme.getSize("default_margin").height
}
text: catalog.i18nc("@title:tab", "Add a printer to Cura")
font.pointSize: 18
}
Label
{
id: captionLabel
anchors
{
left: parent.left
top: titleLabel.bottom
topMargin: UM.Theme.getSize("default_margin").height
}
text: catalog.i18nc("@title:tab", "Select the printer you want to use from the list below.\n\nIf your printer is not in the list, use the \"Custom FFF Printer\" from the \"Custom\" category and adjust the settings to match your printer in the next dialog.")
width: parent.width
wrapMode: Text.WordWrap
}
ScrollView
{
id: machinesHolder
anchors
{
top: captionLabel.visible ? captionLabel.bottom : parent.top;
topMargin: captionLabel.visible ? UM.Theme.getSize("default_margin").height : 0;
bottom: addPrinterButton.top;
bottomMargin: UM.Theme.getSize("default_margin").height
}
width: Math.round(parent.width * 0.45)
frameVisible: true;
Rectangle
{
parent: viewport
anchors.fill: parent
color: palette.light
}
ListView
{
id: machineList
model: UM.DefinitionContainersModel
{
id: machineDefinitionsModel
filter: { "visible": true }
sectionProperty: "category"
preferredSectionValue: preferredCategory
}
section.property: "section"
section.delegate: Button
{
id: machineSectionButton
text: section
width: machineList.width
style: ButtonStyle
{
background: Item
{
height: UM.Theme.getSize("standard_list_lineheight").height
width: machineList.width
}
label: Label
{
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("standard_arrow").width + UM.Theme.getSize("default_margin").width
text: control.text
color: palette.windowText
font.bold: true
UM.RecolorImage
{
id: downArrow
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.left
anchors.rightMargin: UM.Theme.getSize("default_margin").width
width: UM.Theme.getSize("standard_arrow").width
height: UM.Theme.getSize("standard_arrow").height
sourceSize.width: width
sourceSize.height: width
color: palette.windowText
source: base.activeCategory == section ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_right")
}
}
}
onClicked:
{
base.activeCategory = section;
if (machineList.model.getItem(machineList.currentIndex).section != section)
{
// Find the first machine from this section
for(var i = 0; i < machineList.model.rowCount(); i++)
{
var item = machineList.model.getItem(i);
if (item.section == section)
{
machineList.currentIndex = i;
break;
}
}
}
machineName.text = getMachineName();
}
}
delegate: RadioButton
{
id: machineButton
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("standard_list_lineheight").width
opacity: 1;
height: UM.Theme.getSize("standard_list_lineheight").height;
checked: ListView.isCurrentItem;
exclusiveGroup: printerGroup;
text: model.name
onClicked:
{
ListView.view.currentIndex = index;
machineName.text = getMachineName()
}
states: State
{
name: "collapsed";
when: base.activeCategory != model.section;
PropertyChanges { target: machineButton; opacity: 0; height: 0; }
}
}
}
}
Column
{
anchors
{
top: machinesHolder.top
left: machinesHolder.right
right: parent.right
leftMargin: UM.Theme.getSize("default_margin").width
}
spacing: UM.Theme.getSize("default_margin").height
Label
{
width: parent.width
wrapMode: Text.WordWrap
text: getMachineName()
font.pointSize: 16
elide: Text.ElideRight
}
Grid
{
width: parent.width
columns: 2
rowSpacing: UM.Theme.getSize("default_lining").height
columnSpacing: UM.Theme.getSize("default_margin").width
verticalItemAlignment: Grid.AlignVCenter
Label
{
wrapMode: Text.WordWrap
text: catalog.i18nc("@label", "Manufacturer")
}
Label
{
width: Math.floor(parent.width * 0.65)
wrapMode: Text.WordWrap
text: getMachineMetaDataEntry("manufacturer")
}
Label
{
wrapMode: Text.WordWrap
text: catalog.i18nc("@label", "Author")
}
Label
{
width: Math.floor(parent.width * 0.75)
wrapMode: Text.WordWrap
text: getMachineMetaDataEntry("author")
}
Label
{
wrapMode: Text.WordWrap
text: catalog.i18nc("@label", "Printer Name")
}
TextField
{
id: machineName
text: getMachineName()
width: Math.floor(parent.width * 0.75)
maximumLength: 40
//validator: Cura.MachineNameValidator { } //TODO: Gives a segfault in PyQt5.6. For now, we must use a signal on text changed.
validator: RegExpValidator
{
regExp: {
machineName.machine_name_validator.machineNameRegex
}
}
property var machine_name_validator: Cura.MachineNameValidator { }
}
}
}
Button
{
id: addPrinterButton
text: catalog.i18nc("@action:button", "Add Printer")
anchors.bottom: parent.bottom
anchors.right: parent.right
onClicked: addMachine()
}
onAccepted: addMachine()
function addMachine()
{
base.visible = false
var item = machineList.model.getItem(machineList.currentIndex);
Cura.MachineManager.addMachine(machineName.text, item.id)
base.machineAdded(item.id) // Emit signal that the user added a machine.
}
Item
{
UM.I18nCatalog
{
id: catalog;
name: "cura";
}
SystemPalette { id: palette }
ExclusiveGroup { id: printerGroup; }
}
}
|