Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
selectionpainter.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17#include "selectionpainter.h"
18
19#include "object.h"
20#include "qpainter.h"
21
22SelectionPainter::SelectionPainter()
23{
24}
25
26void SelectionPainter::paint(QPainter& painter,
27 const Object* object,
28 int layerIndex,
29 const TransformToolProperties& toolProperties,
30 TransformParameters& tParams)
31{
32 Layer* layer = object->getLayer(layerIndex);
33
34 if (layer == nullptr) { return; }
35
36 QTransform transform = tParams.selectionTransform * tParams.viewTransform;
37 QPolygonF projectedSelectionPolygon = transform.map(tParams.originalSelectionRectF);
38
39 if (layer->type() == Layer::BITMAP)
40 {
41 painter.setBrush(Qt::NoBrush);
42 painter.setPen(QPen(Qt::DashLine));
43
44 // Draw current selection
45 painter.drawPolygon(projectedSelectionPolygon.toPolygon());
46
47 }
48 if (layer->type() == Layer::VECTOR)
49 {
50 painter.setBrush(QColor(0, 0, 0, 20));
51 painter.setPen(Qt::gray);
52 painter.drawPolygon(projectedSelectionPolygon);
53 }
54
55 painter.setPen(Qt::SolidLine);
56 painter.setBrush(QBrush(Qt::gray));
57 int radius = HANDLE_WIDTH / 2;
58
59 const QRectF topLeftCorner = QRectF(projectedSelectionPolygon[0].x() - radius,
60 projectedSelectionPolygon[0].y() - radius,
61 HANDLE_WIDTH, HANDLE_WIDTH);
62 painter.drawRect(topLeftCorner);
63
64 const QRectF topRightCorner = QRectF(projectedSelectionPolygon[1].x() - radius,
65 projectedSelectionPolygon[1].y() - radius,
66 HANDLE_WIDTH, HANDLE_WIDTH);
67 painter.drawRect(topRightCorner);
68
69 const QRectF bottomRightCorner = QRectF(projectedSelectionPolygon[2].x() - radius,
70 projectedSelectionPolygon[2].y() - radius,
71 HANDLE_WIDTH, HANDLE_WIDTH);
72 painter.drawRect(bottomRightCorner);
73
74 const QRectF bottomLeftCorner = QRectF(projectedSelectionPolygon[3].x() - radius,
75 projectedSelectionPolygon[3].y() - radius,
76 HANDLE_WIDTH, HANDLE_WIDTH);
77 painter.drawRect(bottomLeftCorner);
78
79 if (toolProperties.showSelectionInfoEnabled()) {
80 paintSelectionInfo(painter, transform, tParams.viewTransform, tParams.originalSelectionRectF, projectedSelectionPolygon);
81 }
82}
83
84void SelectionPainter::paintSelectionInfo(QPainter& painter, const QTransform& mergedTransform, const QTransform& viewTransform, const QRectF& selectionRect, const QPolygonF& projectedPolygonF)
85{
86 QRect projectedSelectionRect = mergedTransform.mapRect(selectionRect).toAlignedRect();
87 QRect originalSelectionRect = viewTransform.mapRect(selectionRect).toAlignedRect();
88 QPolygon projectedPolygon = projectedPolygonF.toPolygon();
89
90 QPoint projectedCenter = projectedSelectionRect.center();
91 QPoint originalCenter = originalSelectionRect.center();
92 int diffX = static_cast<int>(projectedCenter.x() - originalCenter.x());
93 int diffY = static_cast<int>(originalCenter.y() - projectedCenter.y());
94 painter.drawText(projectedPolygon[0] - QPoint(HANDLE_WIDTH, HANDLE_WIDTH),
95 QString("Size: %1x%2. Diff: %3, %4.").arg(QString::number(selectionRect.width()),
96 QString::number(selectionRect.height()),
97 QString::number(diffX),
98 QString::number(diffY)));
99}
Layer
Definition: layer.h:33
Object
Definition: object.h:42
QBrush
QColor
QPainter
QPainter::drawPolygon
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
QPainter::drawRect
void drawRect(const QRectF &rectangle)
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QPainter::setBrush
void setBrush(const QBrush &brush)
QPainter::setPen
void setPen(const QColor &color)
QPen
QPoint
QPoint::x
int x() const const
QPoint::y
int y() const const
QPolygon
QPolygonF
QPolygonF::toPolygon
QPolygon toPolygon() const const
QRect
QRect::center
QPoint center() const const
QRectF
QRectF::height
qreal height() const const
QRectF::width
qreal width() const const
QString
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString::number
QString number(int n, int base)
Qt::NoBrush
NoBrush
Qt::gray
gray
Qt::DashLine
DashLine
QTransform
QTransform::map
QPoint map(const QPoint &point) const const
QTransform::mapRect
QRect mapRect(const QRect &rectangle) const const
TransformParameters
Definition: selectionpainter.h:30
TransformToolProperties
Definition: toolproperties.h:573
Generated on Wed Dec 24 2025 23:46:02 for Pencil2D by doxygen 1.9.6 based on revision 1be63043db1f7fc0545528fc3b6d5098a552755b