mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-08 06:23:59 -06:00
Expose brush shape to QML
CURA-12543
This commit is contained in:
parent
3c04680c71
commit
7dcc5cd470
3 changed files with 15 additions and 9 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
from enum import IntEnum
|
||||
import numpy
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtCore import Qt, QObject, pyqtEnum
|
||||
from PyQt6.QtGui import QImage, QPainter, QColor, QPen
|
||||
from PyQt6 import QtWidgets
|
||||
from typing import cast, Dict, List, Optional, Tuple
|
||||
|
@ -24,9 +24,11 @@ from .PaintView import PaintView
|
|||
class PaintTool(Tool):
|
||||
"""Provides the tool to paint meshes."""
|
||||
|
||||
class BrushShape(IntEnum):
|
||||
SQUARE = 0
|
||||
CIRCLE = 1
|
||||
class Brush(QObject):
|
||||
@pyqtEnum
|
||||
class Shape(IntEnum):
|
||||
SQUARE = 0
|
||||
CIRCLE = 1
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
@ -41,7 +43,7 @@ class PaintTool(Tool):
|
|||
|
||||
self._brush_size: int = 10
|
||||
self._brush_color: str = "A"
|
||||
self._brush_shape: PaintTool.BrushShape = PaintTool.BrushShape.SQUARE
|
||||
self._brush_shape: PaintTool.Brush.Shape = PaintTool.Brush.Shape.SQUARE
|
||||
self._brush_pen: QPen = self._createBrushPen()
|
||||
|
||||
self._mouse_held: bool = False
|
||||
|
@ -56,9 +58,9 @@ class PaintTool(Tool):
|
|||
pen.setColor(Qt.GlobalColor.white)
|
||||
|
||||
match self._brush_shape:
|
||||
case PaintTool.BrushShape.SQUARE:
|
||||
case PaintTool.Brush.Shape.SQUARE:
|
||||
pen.setCapStyle(Qt.PenCapStyle.SquareCap)
|
||||
case PaintTool.BrushShape.CIRCLE:
|
||||
case PaintTool.Brush.Shape.CIRCLE:
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
return pen
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import QtQuick.Controls
|
|||
import QtQuick.Layouts
|
||||
|
||||
import UM 1.7 as UM
|
||||
import Cura 1.0 as Cura
|
||||
|
||||
Item
|
||||
{
|
||||
|
@ -154,7 +155,7 @@ Item
|
|||
|
||||
z: 2
|
||||
|
||||
onClicked: UM.Controller.triggerActionWithData("setBrushShape", 0)
|
||||
onClicked: UM.Controller.triggerActionWithData("setBrushShape", Cura.PaintToolBrush.SQUARE)
|
||||
}
|
||||
|
||||
UM.ToolbarButton
|
||||
|
@ -171,7 +172,7 @@ Item
|
|||
|
||||
z: 2
|
||||
|
||||
onClicked: UM.Controller.triggerActionWithData("setBrushShape", 1)
|
||||
onClicked: UM.Controller.triggerActionWithData("setBrushShape", Cura.PaintToolBrush.CIRCLE)
|
||||
}
|
||||
|
||||
UM.Slider
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
from . import PaintTool
|
||||
from . import PaintView
|
||||
|
||||
from PyQt6.QtQml import qmlRegisterUncreatableType
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
i18n_catalog = i18nCatalog("cura")
|
||||
|
||||
|
@ -24,6 +26,7 @@ def getMetaData():
|
|||
}
|
||||
|
||||
def register(app):
|
||||
qmlRegisterUncreatableType(PaintTool.PaintTool.Brush, "Cura", 1, 0, "This is an enumeration class", "PaintToolBrush")
|
||||
return {
|
||||
"tool": PaintTool.PaintTool(),
|
||||
"view": PaintView.PaintView()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue