Нема описа

tessellation.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "tessellation.h"
  2. /// \fn Tessellation::Tessellation(QWidget *parent)
  3. /// \~English
  4. /// \brief Constructor. Creates a tesselation like this:
  5. /// ![http://i.imgur.com/WuMRMsi.png](http://i.imgur.com/WuMRMsi.png)
  6. /// \param parent parent of this tesselation, you should pass a reference to the window
  7. /// where this tesselation 'lives'.
  8. /// \~Spanish
  9. /// \brief Constructor. Crea un mosaico como este: ![http://i.imgur.com/WuMRMsi.png](http://i.imgur.com/WuMRMsi.png)
  10. /// \param parent padre este mosaico, debes pasar una referencia a la ventana donde este mosaico 'reside'.
  11. Tessellation::Tessellation(QWidget *parent) :
  12. QWidget(parent)
  13. {
  14. resize(101,101);
  15. width = 50;
  16. height = 50;
  17. move(0,0);
  18. rotation = 0;
  19. }
  20. /// \fn int Tessellation::getRotation()
  21. /// \~English
  22. /// \brief Getter for the rotation.
  23. /// \return The rotation
  24. /// \~Spanish
  25. /// \brief Devuelve la rotacion.
  26. /// \return La rotacion
  27. int Tessellation::getRotation() { return rotation; }
  28. /// \fn int Tessellation::getWidth()
  29. /// \~English
  30. /// \brief Getter for the tesseltation width
  31. /// \return tesselation width
  32. /// \~Spanish
  33. /// \brief Devuelve el ancho del mosaico
  34. /// \return ancho del mosaico
  35. int Tessellation::getWidth() { return width; }
  36. /// \fn int Tessellation::getHeight()
  37. /// \~English
  38. /// \brief Getter for the tesseltation height
  39. /// \return tesselation height
  40. /// \~Spanish
  41. /// \brief Devuelve la altura del mosaico
  42. /// \return altura del mosaico
  43. int Tessellation::getHeight() { return height; }
  44. /// \fn void Tessellation::setRotation(int r)
  45. /// \~English
  46. /// \brief Setter for the tesselation rotation
  47. /// \param r tessellation rotation
  48. /// \~Spanish
  49. /// \brief Ajusta la rotacion del mosaico
  50. /// \param r rotacion para el mosaico
  51. void Tessellation::setRotation(int r) { rotation = r; }
  52. /// \fn void Tessellation::setWidth(int w)
  53. /// \~English
  54. /// \brief Setter for the tesselation width
  55. /// \param w tessellation width
  56. /// \~Spanish
  57. /// \brief Ajusta el ancho del mosaico
  58. /// \param w Ancho del mosaico
  59. void Tessellation::setWidth(int w) { width = w; }
  60. /// \fn void Tessellation::setHeight(int h)
  61. /// \~English
  62. /// \brief Setter for the tesselation height
  63. /// \param h tessellation height
  64. /// \~Spanish
  65. /// \brief Ajusta la altura del mosaico
  66. /// \param h Altura del mosaico
  67. void Tessellation::setHeight(int h) { height = h; }
  68. /// \fn void Tessellation::paintEvent(QPaintEvent *)
  69. /// \~English
  70. /// \brief Paints a tessellation in the window every time that a paint event
  71. /// occurs.
  72. /// \~Spanish
  73. /// \brief Pinta un mosaico en la pantalla cada ves que ocurre un evento de
  74. /// pintar.
  75. void Tessellation::paintEvent(QPaintEvent *) {
  76. QPainter p(this);
  77. QPen myPen;
  78. myPen.setWidth(1);
  79. myPen.setColor(QColor(0x0000ff));
  80. p.setPen(myPen);
  81. // draw the cyan half
  82. p.setBrush(Qt::cyan);
  83. p.translate(width/2,height/2);
  84. p.rotate(rotation);
  85. p.translate(-width/2,-height/2);
  86. QPoint points[3];
  87. points[0].setX(width); points[0].setY(height);
  88. points[1].setX(0); points[1].setY(height);
  89. points[2].setX(width); points[2].setY(0);
  90. p.drawPolygon(points, 3, Qt::OddEvenFill);
  91. // draw the blue half
  92. p.setBrush(Qt::blue);
  93. QPoint pp[3];
  94. pp[0].setX(0); pp[0].setY(0);
  95. pp[1].setX(0); pp[1].setY(height);
  96. pp[2].setX(width); pp[2].setY(0);
  97. p.drawPolygon(pp, 3, Qt::OddEvenFill);
  98. }