17#include "selectionpainter.h"
23SelectionPainter::SelectionPainter()
27void SelectionPainter::paint(
QPainter& painter,
33 Layer* layer =
object->getLayer(layerIndex);
35 if (layer ==
nullptr) {
return; }
37 QTransform transform = tParams.selectionTransform * tParams.viewTransform;
38 QPolygonF projectedSelectionPolygon = transform.
map(tParams.originalSelectionRectF);
40 if (layer->type() == Layer::BITMAP)
49 if (layer->type() == Layer::VECTOR)
56 if (tool->type() == SELECT || tool->type() == MOVE)
60 int radius = HANDLE_WIDTH / 2;
62 const QRectF topLeftCorner =
QRectF(projectedSelectionPolygon[0].x() - radius,
63 projectedSelectionPolygon[0].y() - radius,
64 HANDLE_WIDTH, HANDLE_WIDTH);
67 const QRectF topRightCorner =
QRectF(projectedSelectionPolygon[1].x() - radius,
68 projectedSelectionPolygon[1].y() - radius,
69 HANDLE_WIDTH, HANDLE_WIDTH);
72 const QRectF bottomRightCorner =
QRectF(projectedSelectionPolygon[2].x() - radius,
73 projectedSelectionPolygon[2].y() - radius,
74 HANDLE_WIDTH, HANDLE_WIDTH);
77 const QRectF bottomLeftCorner =
QRectF(projectedSelectionPolygon[3].x() - radius,
78 projectedSelectionPolygon[3].y() - radius,
79 HANDLE_WIDTH, HANDLE_WIDTH);
83 if (tool->properties.showSelectionInfo) {
84 paintSelectionInfo(painter, transform, tParams.viewTransform, tParams.originalSelectionRectF, projectedSelectionPolygon);
90 QRect projectedSelectionRect = mergedTransform.
mapRect(selectionRect).toAlignedRect();
91 QRect originalSelectionRect = viewTransform.
mapRect(selectionRect).toAlignedRect();
94 QPoint projectedCenter = projectedSelectionRect.
center();
96 int diffX =
static_cast<int>(projectedCenter.
x() - originalCenter.
x());
97 int diffY =
static_cast<int>(originalCenter.
y() - projectedCenter.
y());
98 painter.
drawText(projectedPolygon[0] -
QPoint(HANDLE_WIDTH, HANDLE_WIDTH),
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
void drawRect(const QRectF &rectangle)
void drawText(const QPointF &position, const QString &text)
void setBrush(const QBrush &brush)
void setPen(const QColor &color)
QPolygon toPolygon() const const
QPoint center() const const
qreal height() const const
qreal width() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString number(int n, int base)