141 self.setWindowTitle(i18n(
"Create new Template"))
142 self.setLayout(QVBoxLayout())
143 buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
146 mainWidget = QWidget()
147 explanation = QLabel(i18n(
"This allows you to make a template document with guides.\nThe width and height are the size of the live-area, the safe area is the live area minus the margins, and the full image is the live area plus the bleeds."))
148 explanation.setWordWrap(
True)
149 self.layout().addWidget(explanation)
150 self.layout().addWidget(mainWidget)
151 self.layout().addWidget(buttons)
152 mainWidget.setLayout(QHBoxLayout())
154 elements.setLayout(QVBoxLayout())
155 previewLayout = QWidget()
156 previewLayout.setLayout(QVBoxLayout())
157 mainWidget.layout().addWidget(elements)
158 mainWidget.layout().addWidget(previewLayout)
167 templateBGColor = QPushButton(i18n(
"Select background color"))
169 previewLayout.layout().addWidget(templateBGColor)
172 self.
DPI.setMaximum(1200)
173 self.
DPI.setValue(300)
181 widgetSize = QWidget()
182 sizeForm = QFormLayout()
183 sizeForm.addRow(i18n(
"DPI:"), self.
DPI)
184 widthLayout = QHBoxLayout()
187 sizeForm.addRow(i18n(
"Width:"), widthLayout)
188 heightLayout = QHBoxLayout()
191 sizeForm.addRow(i18n(
"Height:"), heightLayout)
192 widgetSize.setLayout(sizeForm)
193 elements.layout().addWidget(widgetSize)
195 marginAndBleed = QTabWidget()
196 elements.layout().addWidget(marginAndBleed)
199 marginForm = QGridLayout()
200 margins.setLayout(marginForm)
213 marginForm.addWidget(QLabel(i18n(
"Left:")), 0, 0, Qt.AlignmentFlag.AlignRight)
216 marginForm.addWidget(QLabel(i18n(
"Top:")), 1, 0, Qt.AlignmentFlag.AlignRight)
217 marginForm.addWidget(self.
marginTop, 1, 1)
219 marginForm.addWidget(QLabel(i18n(
"Right:")), 2, 0, Qt.AlignmentFlag.AlignRight)
222 marginForm.addWidget(QLabel(i18n(
"Bottom:")), 3, 0, Qt.AlignmentFlag.AlignRight)
225 marginAndBleed.addTab(margins, i18n(
"Margins"))
228 bleedsForm = QGridLayout()
229 bleeds.setLayout(bleedsForm)
242 bleedsForm.addWidget(QLabel(i18n(
"Left:")), 0, 0, Qt.AlignmentFlag.AlignRight)
243 bleedsForm.addWidget(self.
bleedLeft, 0, 1)
245 bleedsForm.addWidget(QLabel(i18n(
"Top:")), 1, 0, Qt.AlignmentFlag.AlignRight)
246 bleedsForm.addWidget(self.
bleedTop, 1, 1)
248 bleedsForm.addWidget(QLabel(i18n(
"Right:")), 2, 0, Qt.AlignmentFlag.AlignRight)
251 bleedsForm.addWidget(QLabel(i18n(
"Bottom:")), 3, 0, Qt.AlignmentFlag.AlignRight)
255 marginAndBleed.addTab(bleeds, i18n(
"Bleeds"))
257 if QLocale().system().measurementSystem()
is QLocale.MeasurementSystem.MetricSystem:
306 template = Application.createDocument(int(wBase + bL + bR), int(hBase + bT + bB), self.
templateName.text(),
"RGBA",
"U8",
"sRGB built-in", self.
DPI.
value())
308 backgroundName = i18n(
"Background")
309 if len(template.topLevelNodes()) > 0:
310 backgroundNode = template.topLevelNodes()[0]
311 backgroundNode.setName(backgroundName)
313 backgroundNode = template.createNode(backgroundName,
"paintlayer")
314 template.rootNode().addChildNode(backgroundNode,
None)
316 pixelByteArray = QByteArray()
318 pixelByteArray = backgroundNode.pixelData(0, 0, template.width(), template.height())
319 pixelByteArray.fill(int(255).to_bytes(1, byteorder=
'little'))
321 red = int(self.
currentColor.redF()*255).to_bytes(1, byteorder=
'little')
322 green = int(self.
currentColor.greenF()*255).to_bytes(1, byteorder=
'little')
323 blue = int(self.
currentColor.blueF()*255).to_bytes(1, byteorder=
'little')
324 alpha = int(self.
currentColor.alphaF()*255).to_bytes(1, byteorder=
'little')
326 progress = QProgressDialog(i18n(
"Creating template"), str(), 0, template.width()*template.height())
327 progress.setCancelButton(
None)
329 QApplication.instance().processEvents()
330 for byteNumber
in range(template.width()*template.height()):
331 pixelByteArray.append( blue)
332 pixelByteArray.append(green)
333 pixelByteArray.append( red)
334 pixelByteArray.append(alpha)
335 progress.setValue(byteNumber)
336 backgroundNode.setPixelData(pixelByteArray, 0, 0, template.width(), template.height())
337 backgroundNode.setOpacity(255)
338 backgroundNode.setLocked(
True)
340 sketchNode = template.createNode(i18n(
"Sketch"),
"paintlayer")
341 template.rootNode().addChildNode(sketchNode, backgroundNode)
344 verticalGuides.append(bL)
345 verticalGuides.append(bL + mL)
346 verticalGuides.append((bL + wBase) - mR)
347 verticalGuides.append(bL + wBase)
349 horizontalGuides = []
350 horizontalGuides.append(bT)
351 horizontalGuides.append(bT + mT)
352 horizontalGuides.append((bT + hBase) - mB)
353 horizontalGuides.append(bT + hBase)
355 template.setHorizontalGuides(horizontalGuides)
356 template.setVerticalGuides(verticalGuides)
357 template.setGuidesVisible(
True)
358 template.setGuidesLocked(
True)
359 template.refreshProjection()
363 print(
"CPMT: Template", self.
templateName.text(),
"made and saved.")
364 template.waitForDone()
384 scaleRatio = maxSize / (hBase + bT + bB)
386 scaleRatio = maxSize / (wBase + bR + bL)
388 width = (wBase + bL + bR) * scaleRatio
389 height = (hBase + bT + bB) * scaleRatio
390 topLeft = [max((maxSize - width) / 2, 0), max((maxSize - height) / 2, 0)]
392 image = QImage(maxSize, maxSize, QImage.Format.Format_ARGB32)
393 image.fill(Qt.GlobalColor.transparent)
399 CanvasSize = QRectF(topLeft[0], topLeft[1], width, height)
400 p.drawRect(CanvasSize.toRect())
403 PageSize = CanvasSize
404 PageSize.setWidth(width - (bR * scaleRatio))
405 PageSize.setHeight(height - (bB * scaleRatio))
406 PageSize.setX(PageSize.x() + (bL * scaleRatio))
407 PageSize.setY(PageSize.y() + (bT * scaleRatio))
409 p.setPen(Qt.GlobalColor.blue)
410 p.setBrush(Qt.GlobalColor.transparent)
411 p.drawRect(PageSize.toRect())
415 LiveArea.setWidth(LiveArea.width() - (mR * scaleRatio))
416 LiveArea.setHeight(LiveArea.height() - (mB * scaleRatio))
417 LiveArea.setX(LiveArea.x() + (mL * scaleRatio))
418 LiveArea.setY(LiveArea.y() + (mT * scaleRatio))
420 p.setPen(Qt.GlobalColor.blue)
421 p.drawRect(LiveArea.toRect())