You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.5 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. *
  3. * This file is part of QMapControl,
  4. * an open-source cross-platform map widget
  5. *
  6. * Copyright (C) 2010 Jeffery MacEachern
  7. * Based on CirclePoint code by Kai Winter
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will `be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * Contact e-mail: kaiwinter@gmx.de
  23. * Program URL : http://qmapcontrol.sourceforge.net/
  24. *
  25. */
  26. #include "arrowpoint.h"
  27. ArrowPoint::ArrowPoint(qreal x, qreal y, int sideLength, qreal heading, QString name, mapPoint::Alignment alignment, QPen* pen)
  28. : mapPoint(x, y, name, alignment){
  29. size = QSize(sideLength, sideLength);
  30. h = heading;
  31. mypen = pen;
  32. mypixmap = QPixmap(sideLength, sideLength);
  33. drawArrow();
  34. }
  35. ArrowPoint::~ArrowPoint()
  36. {
  37. }
  38. void ArrowPoint::setHeading(qreal heading)
  39. {
  40. h = heading;
  41. drawArrow();
  42. }
  43. qreal ArrowPoint::getHeading() const
  44. {
  45. return h;
  46. }
  47. void ArrowPoint::setPen(QPen* pen)
  48. {
  49. mypen = pen;
  50. drawArrow();
  51. }
  52. void ArrowPoint::drawArrow()
  53. {
  54. mypixmap = QPixmap(size);
  55. mypixmap.fill(Qt::transparent);
  56. QPainter painter(&mypixmap);
  57. //#if !defined Q_WS_MAEMO_5 //FIXME Maemo has a bug - it will antialias our point out of existence
  58. painter.setRenderHints(QPainter::Antialiasing|QPainter::HighQualityAntialiasing);
  59. //#endif
  60. if(mypen)
  61. {
  62. painter.setPen(*mypen);
  63. painter.setBrush(QBrush(mypen->color()));
  64. }
  65. else
  66. {
  67. painter.setBrush(QBrush(painter.pen().color()));
  68. }
  69. painter.setWindow(-(size.width() / 2), -(size.height() / 2), size.width(), size.height());
  70. QTransform transform;
  71. transform.rotate(-h);
  72. transform.scale(0.4, 0.75);
  73. painter.setWorldTransform(transform);
  74. QPolygon arrow;
  75. arrow << QPoint(0, -(size.height() / 2));
  76. arrow << QPoint(-(size.width() / 2), +(size.height() / 2));
  77. arrow << QPoint(0, 0);
  78. arrow << QPoint(+(size.width() / 2), +(size.height() / 2));
  79. painter.drawPolygon(arrow);
  80. }