Introduce old redir program
[lcapit-junk-code.git] / qt-course / drawing / exer681-polygon / MyWidget.cpp
blobb1be9c2c449bc640237f3ccb52dacadd8253bb69
1 #include <QPainter>
2 #include <QPolygon>
4 #include "MyWidget.h"
6 MyWidget::MyWidget(QWidget *parent)
7 : QWidget(parent)
11 MyWidget::~MyWidget()
15 void MyWidget::paintEvent(QPaintEvent *event)
17 QPainter p(this);
19 if (m_points.size() == 1) {
20 // draw only one Point
21 p.drawPoint(m_points[0]);
22 return;
25 // draw the Polygon
26 QPolygon poly(m_points);
27 p.setBrush(Qt::green);
28 p.setRenderHints(QPainter::Antialiasing, true);
29 p.drawPolygon(poly);
32 void MyWidget::mousePressEvent(QMouseEvent *event)
34 if (event->button() == Qt::LeftButton)
35 m_points.append(event->pos());
36 else if (event->button() == Qt::RightButton)
37 m_points.clear();
38 else
39 return;
41 update();