VPTissue Reference Manual
ArrowItem.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "../../cpp_simptshell/mesh_drawer/ArrowItem.h"
21 
22 #include <cmath>
23 
24 namespace SimPT_Shell {
25 
26 using std::sqrt;
27 
28 ArrowItem::ArrowItem(QGraphicsItem* parent) : QGraphicsLineItem(parent) {}
29 
30 void ArrowItem::paint(QPainter* p, const QStyleOptionGraphicsItem* , QWidget* )
31 {
32  // construct arrow head
33  QPointF const start = line().p1();
34  QPointF const end = line().p2();
35  QPointF const mid = start + 0.75e0 * (end - start);
36  double const vx = end.x() - start.x();
37  double const vy = end.y() - start.y();
38 
39  double length = sqrt(vx * vx + vy * vy);
40  if (length != 0) {
41  // perpendicular vector
42  double const px = -vy / length;
43  double const py = vx / length;
44 
45  // Arrow head lines go from end point to points about 3/4 of the total arrow,
46  // extending sideways about 1/4 of the arrow length.
47  QPointF const arwp1 = mid + QPointF((int) ((length / 4.) * px), (int) ((length / 4.) * py));
48  QPointF const arwp2 = mid - QPointF((int) ((length / 4.) * px), (int) ((length / 4.) * py));
49 
50  p->setPen(pen());
51  // Draw arrow head
52  p->drawLine(end, arwp1);
53  p->drawLine(end, arwp2);
54  // Draw arrow line
55  p->drawLine(start, end);
56  }
57 }
58 
59 } // namespace
Namespace for SimPT shell package.
Definition: Client.cpp:50
see the online Qt documentation
see the online Qt documentation
see the online Qt documentation