| 93 | } |
| 94 | |
| 95 | void paintVector(QPainter * painter, |
| 96 | const stats::StatisticsType &statisticsType, |
| 97 | const double & zoomFactor, |
| 98 | const int & x1, |
| 99 | const int & y1, |
| 100 | const int & x2, |
| 101 | const int & y2, |
| 102 | const float & vx, |
| 103 | const float & vy, |
| 104 | bool isLine, |
| 105 | const int & xMin, |
| 106 | const int & xMax, |
| 107 | const int & yMin, |
| 108 | const int & yMax) |
| 109 | { |
| 110 | |
| 111 | // Is the arrow (possibly) visible? |
| 112 | if (!(x1 < xMin && x2 < xMin) && !(x1 > xMax && x2 > xMax) && !(y1 < yMin && y2 < yMin) && |
| 113 | !(y1 > yMax && y2 > yMax)) |
| 114 | { |
| 115 | // Set the pen for drawing |
| 116 | auto vectorStyle = statisticsType.vectorStyle; |
| 117 | auto arrowColor = functionsGui::toQColor(vectorStyle.color); |
| 118 | if (statisticsType.mapVectorToColor) |
| 119 | arrowColor.setHsvF( |
| 120 | functions::clip((std::atan2(vy, vx) + M_PI) / (2 * M_PI), 0.0, 1.0), 1.0, 1.0); |
| 121 | arrowColor.setAlpha(arrowColor.alpha() * ((float)statisticsType.alphaFactor / 100.0)); |
| 122 | |
| 123 | if (statisticsType.scaleVectorToZoom) |
| 124 | vectorStyle.width = vectorStyle.width * zoomFactor / 8; |
| 125 | |
| 126 | painter->setPen(QPen(arrowColor, vectorStyle.width, patternToQPenStyle(vectorStyle.pattern))); |
| 127 | painter->setBrush(arrowColor); |
| 128 | |
| 129 | // Draw the arrow tip, or a circle if the vector is (0,0) if the zoom factor is not 1 or |
| 130 | // smaller. |
| 131 | if (zoomFactor > 1) |
| 132 | { |
| 133 | // At which angle do we draw the triangle? |
| 134 | // A vector to the right (1, 0) -> 0° |
| 135 | // A vector to the top (0, -1) -> 90° |
| 136 | const auto angle = std::atan2(vy, vx); |
| 137 | |
| 138 | // Draw the vector head if the vector is not 0,0 |
| 139 | if ((vx != 0 || vy != 0)) |
| 140 | { |
| 141 | // The size of the arrow head |
| 142 | const int headSize = |
| 143 | (zoomFactor >= STATISTICS_DRAW_VALUES_ZOOM && !statisticsType.scaleVectorToZoom) |
| 144 | ? 8 |
| 145 | : zoomFactor / 2; |
| 146 | |
| 147 | if (statisticsType.arrowHead != stats::StatisticsType::ArrowHead::none) |
| 148 | { |
| 149 | // We draw an arrow head. This means that we will have to draw a shortened line |
| 150 | const int shorten = (statisticsType.arrowHead == stats::StatisticsType::ArrowHead::arrow) |
| 151 | ? headSize * 2 |
| 152 | : headSize * 0.5; |
no test coverage detected