All Classes Namespaces Functions Variables Enumerations Properties Pages
selectionpainter.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 #include "selectionpainter.h"
18 
19 #include "object.h"
20 #include "qpainter.h"
21 #include "layermanager.h"
22 #include "basetool.h"
23 
24 
25 SelectionPainter::SelectionPainter()
26 {
27 }
28 
29 void SelectionPainter::paint(QPainter& painter,
30  const Object* object,
31  int layerIndex,
32  BaseTool* tool,
33  TransformParameters& tParams)
34 {
35  Layer* layer = object->getLayer(layerIndex);
36 
37  if (layer == nullptr) { return; }
38 
39  if (layer->type() == Layer::BITMAP)
40  {
41  painter.setBrush(Qt::NoBrush);
42  painter.setPen(QPen(Qt::DashLine));
43 
44  // Draw previous selection
45  painter.drawPolygon(tParams.lastSelectionPolygonF.toPolygon());
46 
47  // Draw current selection
48  painter.drawPolygon(tParams.currentSelectionPolygonF.toPolygon());
49 
50  }
51  if (layer->type() == Layer::VECTOR)
52  {
53  painter.setBrush(QColor(0, 0, 0, 20));
54  painter.setPen(Qt::gray);
55  painter.drawPolygon(tParams.currentSelectionPolygonF);
56  }
57 
58  if (layer->type() != Layer::VECTOR || tool->type() != SELECT)
59  {
60  painter.setPen(Qt::SolidLine);
61  painter.setBrush(QBrush(Qt::gray));
62  int width = 6;
63  int radius = width / 2;
64 
65  const QRectF topLeftCorner = QRectF(tParams.currentSelectionPolygonF[0].x() - radius,
66  tParams.currentSelectionPolygonF[0].y() - radius,
67  width, width);
68  painter.drawRect(topLeftCorner);
69 
70  const QRectF topRightCorner = QRectF(tParams.currentSelectionPolygonF[1].x() - radius,
71  tParams.currentSelectionPolygonF[1].y() - radius,
72  width, width);
73  painter.drawRect(topRightCorner);
74 
75  const QRectF bottomRightCorner = QRectF(tParams.currentSelectionPolygonF[2].x() - radius,
76  tParams.currentSelectionPolygonF[2].y() - radius,
77  width, width);
78  painter.drawRect(bottomRightCorner);
79 
80  const QRectF bottomLeftCorner = QRectF(tParams.currentSelectionPolygonF[3].x() - radius,
81  tParams.currentSelectionPolygonF[3].y() - radius,
82  width, width);
83  painter.drawRect(bottomLeftCorner);
84 
85  painter.setBrush(QColor(0, 255, 0, 50));
86  painter.setPen(Qt::green);
87  }
88 }
QPolygon toPolygon() const const
DashLine
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
void drawRect(const QRectF &rectangle)
void setPen(const QColor &color)
Definition: layer.h:39
void setBrush(const QBrush &brush)
Definition: object.h:54