Geen omschrijving

drawingWindow.cpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "drawingWindow.h"
  2. #include "ui_drawingWindow.h"
  3. #include <vector>
  4. /// \fn DrawingWindow::DrawingWindow(QWidget *parent)
  5. /// \~English
  6. /// \brief Constructor.
  7. /// \~Spanish
  8. /// \brief Constructor.
  9. DrawingWindow::DrawingWindow(QWidget *parent) :
  10. QMainWindow(parent),
  11. ui(new Ui::DrawingWindow)
  12. {
  13. ui->setupUi(this);
  14. myTessellation = new vector<Tessellation *>;
  15. vT = new vector<Tessellation *>;
  16. vL = new vector<Line *>;
  17. // just hidding the toolbars to have a bigger drawing area.
  18. QList<QToolBar *> toolbars = this->findChildren<QToolBar *>();
  19. foreach(QToolBar *t, toolbars) t->hide();
  20. QList<QStatusBar *> statusbars = this->findChildren<QStatusBar *>();
  21. foreach(QStatusBar *t, statusbars) t->hide();
  22. }
  23. /// \fn void DrawingWindow::addLine(int x0, int y0, int x1, int y1, int width, QColor color)
  24. /// \~English
  25. /// \brief Add a line to the window, specifying coordinates
  26. /// of the starting and end points.
  27. /// \param x0 starting coordinate x
  28. /// \param y0 starting coordinate y
  29. /// \param x1 end coordinate x
  30. /// \param y1 end coordinate y
  31. /// \param width line width
  32. /// \param color line color
  33. /// \~Spanish
  34. /// \brief Anade una linea a la ventana, especificando las coordenadas
  35. /// de los puntos iniciales y finales
  36. /// \param x0 coordenada inicial x
  37. /// \param y0 coordenada inicial y
  38. /// \param x1 coordenada final x
  39. /// \param y1 coordenada final y
  40. /// \param width ancho de la linea
  41. /// \param color color de la linea
  42. void DrawingWindow::addLine(int x0, int y0, int x1, int y1, int width, QColor color) {
  43. Line *tmp = new Line(x0,y0,x1,y1, width, color, this);
  44. tmp->show();
  45. vL->push_back(tmp);
  46. }
  47. /// \fn void DrawingWindow::addLinePolar(int x0, int y0, int length, double angle, int width, QColor color)
  48. /// \~English
  49. /// \brief Add a line to the window, specifying coordinates
  50. /// of the starting point, the length and angle.
  51. /// \param x0 starting coordinate x
  52. /// \param y0 starting coordinate y
  53. /// \param length - length of the line
  54. /// \param angle - angle of the line
  55. /// \param width - line width
  56. /// \param color - line color
  57. /// \~Spanish
  58. /// \brief Anade una linea a la ventana, especifica las coordenadas
  59. /// de el punto inicial, el largo y el angulo
  60. /// \param x0 coordenada inicial x
  61. /// \param y0 coordenada inicial y
  62. /// \param length - largo de la linea
  63. /// \param angle - angulo de la linea
  64. /// \param width - ancho de la linea
  65. /// \param color - color de la linea
  66. void DrawingWindow::addLinePolar(int x0, int y0, int length, double angle, int width, QColor color) {
  67. Line *tmp = new Line(x0,y0,length, angle, width, color, this);
  68. tmp->show();
  69. vL->push_back(tmp);
  70. }
  71. /// \fn void DrawingWindow::addTessellation(Tessellation &t)
  72. /// \~English
  73. /// \brief Add a tessalation to the window
  74. /// \param t a tessellation object
  75. /// \~Spanish
  76. /// \brief Anade un mosaico a la ventana
  77. /// \param t un objeto de tipo tessellation (mosaico)
  78. void DrawingWindow::addTessellation(Tessellation &t) {
  79. Tessellation *tmp = new Tessellation(this);
  80. tmp->move(t.x(),t.y());
  81. tmp->setRotation(t.getRotation());
  82. tmp->show();
  83. vT->push_back(tmp);
  84. }
  85. /// \fn DrawingWindow::~DrawingWindow()
  86. /// \~English
  87. /// \brief Destructor
  88. /// \~Spanish
  89. /// \brief Destructor
  90. DrawingWindow::~DrawingWindow()
  91. {
  92. foreach(Tessellation *t, *vT) delete t;
  93. delete vT;
  94. foreach(Line *l, *vL) delete l;
  95. delete vL;
  96. delete ui;
  97. }
  98. /// \fn void DrawingWindow::paintEvent(QPaintEvent *)
  99. /// \~English
  100. /// \brief Paints event.
  101. /// \~Spanish
  102. /// \brief Evento de pintar
  103. void DrawingWindow::paintEvent(QPaintEvent *) {
  104. QPainter p(this);
  105. QPen myPen;
  106. myPen.setWidth(1);
  107. myPen.setColor(QColor(0x0000ff));
  108. p.setPen(myPen);
  109. p.setBrush(Qt::cyan);
  110. }