Swiftray  1.0
polygon.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QMouseEvent>
5 #include <QPoint>
6 
7 
8 namespace Controls {
9 
10  class Polygon : public CanvasControl {
11  static constexpr unsigned int kDefaultNumSide = 5;
12  static constexpr unsigned int kMinimumNumSide = 3;
13  public:
14  Polygon(Canvas *canvas) noexcept;
15 
16  bool mouseMoveEvent(QMouseEvent *e) override;
17 
18  bool mouseReleaseEvent(QMouseEvent *e) override;
19 
20  bool keyPressEvent(QKeyEvent *e) override;
21 
22  void paint(QPainter *painter) override;
23 
24  void exit() override;
25 
26  bool isActive() override;
27 
28  unsigned int getNumSide() const { return num_side_; }
29  bool setNumSide(unsigned int numSide);
30 
31  private:
32  unsigned int num_side_;
33  QPointF initial_vertex_;
34  QPointF center_;
35  QPolygonF polygon_;
36 
37  void updateVertices(const QPointF &center, const QPointF &start_vertex);
38  };
39 
40 }
Definition: canvas.h:27
Definition: canvas-control.h:16
Canvas & canvas()
Definition: canvas-control.cpp:34
Definition: polygon.h:10
unsigned int getNumSide() const
Definition: polygon.h:28
void paint(QPainter *painter) override
Definition: polygon.cpp:47
bool setNumSide(unsigned int numSide)
Definition: polygon.cpp:105
Polygon(Canvas *canvas) noexcept
Definition: polygon.cpp:11
bool mouseMoveEvent(QMouseEvent *e) override
Definition: polygon.cpp:19
bool mouseReleaseEvent(QMouseEvent *e) override
Definition: polygon.cpp:28
bool keyPressEvent(QKeyEvent *e) override
Definition: polygon.cpp:55
void exit() override
Definition: polygon.cpp:78
bool isActive() override
Definition: polygon.cpp:15
In-canvas controls with its own painting and event handling functions.
Definition: canvas-control.h:8