37#include <ksharedconfig.h>
46constexpr qreal MinAxisLength = 1.0;
48QPointF
rotate90(
const QPointF &point)
50 return QPointF(-point.y(), point.x());
57 setObjectName(
"tool_ellipse");
74 QWidget *widget =
new QWidget();
75 widget->setObjectName(
"PlacementModeWidget");
78 KoGroupButton *boundingBoxButton = placementStrip->
addButton(i18nc(
"Ellipse tool placement mode",
"Bounding Box"));
79 KoGroupButton *threePointButton = placementStrip->
addButton(i18nc(
"Ellipse tool placement mode",
"3-Point"));
80 boundingBoxButton->setToolTip(i18n(
"Place the ellipse inside a bounding box"));
81 threePointButton->setToolTip(i18n(
"Place the ellipse by setting the major axis and width"));
83 KConfigGroup cfg = KSharedConfig::openConfig()->group(
toolId());
97 if (qobject_cast<KisRectangleConstraintWidget*>(other)) {
98 connect(placementStrip,
101 [other](
int mode,
bool checked) {
111 QHBoxLayout *hLayout =
new QHBoxLayout(widget);
112 hLayout->addWidget(
new QLabel(i18nc(
"Ellipse tool placement mode option label",
"Placement:")), 0, Qt::AlignLeft);
113 hLayout->addWidget(placementStrip, 1, Qt::AlignRight);
114 widgets.prepend(widget);
129 KConfigGroup cfg = KSharedConfig::openConfig()->group(
toolId());
162 i18n(
"This tool cannot paint on clone layers. Please select a paint or vector layer or mask."),
169 i18n(
"The MyPaint Brush Engine is not available for this colorspace"),
206 static const QCursor
cursor = [] {
207 QPixmap pixmap(42, 32);
208 pixmap.fill(Qt::transparent);
210 QPainter painter(&pixmap);
211 painter.drawPixmap(0, 0, QIcon(QStringLiteral(
":/tool_ellipse_cursor.svg")).pixmap(32, 32));
212 painter.setRenderHint(QPainter::Antialiasing,
true);
214 QPainterPath checkPath;
215 checkPath.moveTo(31.0, 23.0);
216 checkPath.lineTo(34.0, 26.0);
217 checkPath.lineTo(41.0, 17.0);
219 QPen outlinePen(Qt::white, 4.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
220 painter.setPen(outlinePen);
221 painter.drawPath(checkPath);
223 QPen checkPen(Qt::black, 2.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
224 painter.setPen(checkPen);
225 painter.drawPath(checkPath);
228 return QCursor(pixmap, 6, 6);
345 setStatusText(i18n(
"Click to place the other end of the ellipse axis."));
349 setStatusText(i18n(
"Drag handles to adjust the ellipse. Press Enter to apply or Esc to cancel."));
485 path.addPath(
drawX(firstPoint));
486 path.moveTo(firstPoint);
489 QPainterPath ellipsePath;
493 path.moveTo(firstPoint);
505 gc.setRenderHint(QPainter::Antialiasing,
true);
507 gc.setPen(QPen(palette.
black, 1.0));
508 gc.setBrush(QBrush(palette.
white));
510 const qreal radius = qMax<qreal>(3.0,
handleRadius() * 0.75);
513 gc.drawEllipse(QRectF(viewPoint - QPointF(radius, radius), QSizeF(radius * 2.0, radius * 2.0)));
527 const QPointF center = (
p1 +
p2) * 0.5;
528 const QPointF majorVector =
p2 -
p1;
529 const qreal majorLength = std::hypot(majorVector.x(), majorVector.y());
531 if (majorLength < MinAxisLength) {
535 const qreal semiMajor = majorLength * 0.5;
536 const QPointF majorUnit = majorVector / majorLength;
537 const QPointF minorUnit =
rotate90(majorUnit);
538 const QPointF localPoint = thirdPoint - center;
539 const qreal localX = QPointF::dotProduct(localPoint, majorUnit);
540 const qreal localY = QPointF::dotProduct(localPoint, minorUnit);
541 const qreal divisor = 1.0 - (localX * localX) / (semiMajor * semiMajor);
547 const qreal semiMinor = qAbs(localY) / std::sqrt(divisor);
548 if (semiMinor <= 0.0) {
552 QPainterPath canonicalPath;
553 canonicalPath.addEllipse(QPointF(0, 0), semiMajor, semiMinor);
555 QTransform ellipseTransform(majorUnit.x(), majorUnit.y(),
556 minorUnit.x(), minorUnit.y(),
557 center.x(), center.y());
559 *path = ellipseTransform.map(canonicalPath);
568 rect |= QRectF(point, QSizeF(1.0, 1.0));
575 rect |= path.boundingRect();
578 return rect.adjusted(-20.0, -20.0, 20.0, 20.0);
590 canvas()->resourceManager(),
596 QPainterPath documentPath = path;
598 QTransform pixelToDocument;
599 pixelToDocument.scale(1.0 /
image()->xRes(), 1.0 /
image()->yRes());
600 documentPath = pixelToDocument.map(path);
616 Q_UNUSED(roundCornersX);
617 Q_UNUSED(roundCornersY);
629 canvas()->resourceManager(),
634 path.addEllipse(rect);
640 canvas()->resourceManager());
QPointF rotate90(const QPointF &p)
KoColorDisplayRendererInterface * displayRendererInterface() const override
displayRendererInterface The display renderer interface has a number of color conversion functions wh...
KisViewManager * viewManager() const
static QCursor loadWithSize(const QString &cursorName, int width, int height, int hotspotX=-1, int hotspotY=-1)
static QCursor pointingHandCursor()
The KisResourcesSnapshot class takes a snapshot of the various resources like colors and settings use...
KoColor currentFgColor() const
KisCanvasResourceProvider * canvasResourceProvider()
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout=4500, KisFloatingMessage::Priority priority=KisFloatingMessage::Medium, int alignment=Qt::AlignCenter|Qt::TextWordWrap)
shows a floating message in the top right corner of the canvas
virtual KisHandlePalette handlePaletteForDisplayColorSpace() const =0
handlePaletteForDisplayColorSpace
void toQColor(QColor *c) const
a convenience method for the above.
The position of a path point within a path shape.
virtual QPointF normalize()
Normalizes the path data.
static KoPathShape * createShapeFromPainterPath(const QPainterPath &path)
Creates path shape from given QPainterPath.
bool spontaneous() const
return if this event was spontaneous (see QMouseEvent::spontaneous())
QPointF point
The point in document coordinates.
void rotate(qreal angle)
Rotate the shape (relative)
virtual void setStroke(KoShapeStrokeModelSP stroke)
static bool qFuzzyIsNull(half h)
#define koIcon(name)
Use these macros for icons without any issues.
KUndo2MagicString kundo2_i18n(const char *text)