Няма описание

drawingWindow.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "drawingWindow.h"
  2. #include "ui_drawingWindow.h"
  3. #include <vector>
  4. /// \fn DrawingWindow::DrawingWindow(QWidget *parent)
  5. /// \~English
  6. /// \brief Constructor.
  7. /// \param parent when creating a DrawingWindow in the main function, leave this parameter empty
  8. /// \~Spanish
  9. /// \brief Constructor
  10. /// \param parent ventana padre
  11. DrawingWindow::DrawingWindow(QWidget *parent) :
  12. QMainWindow(parent),
  13. ui(new Ui::DrawingWindow)
  14. {
  15. ui->setupUi(this);
  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 x
  28. /// \param y0 starting y
  29. /// \param x1 end x
  30. /// \param y1 end 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 inciales y finales.
  36. /// \param x0 x inicial
  37. /// \param y0 y inicial
  38. /// \param x1 x final
  39. /// \param y1 y final
  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 x
  52. /// \param y0 starting y
  53. /// \param length length of the line
  54. /// \param angle angle
  55. /// \param width line width
  56. /// \param color line color
  57. /// \~Spanish
  58. /// \brief Anade una linea a la ventana, especificando las coordenadas
  59. /// del punto inicial, el largo y el angulo.
  60. /// \param x0 x incial
  61. /// \param y0 y inicial
  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 DrawingWindow::~DrawingWindow - the destructor
  72. /// \~English
  73. /// \brief Destructor
  74. /// \~Spanish
  75. /// \brief Destructor
  76. DrawingWindow::~DrawingWindow()
  77. {
  78. foreach(Line *l, *vL) delete l;
  79. delete vL;
  80. delete ui;
  81. }
  82. /// \fn void DrawingWindow::paintEvent(QPaintEvent *)
  83. /// \~English
  84. /// \brief Function called in a paint event
  85. /// \~Spanish
  86. /// \brief Funcion invocada en un evento de pintar
  87. void DrawingWindow::paintEvent(QPaintEvent *) {
  88. QPainter p(this);
  89. QPen myPen;
  90. myPen.setWidth(1);
  91. myPen.setColor(QColor(0x0000ff));
  92. p.setPen(myPen);
  93. p.setBrush(Qt::cyan);
  94. }