Skui 0.0.1
Build fast and easy to use control software with Skui.
 
Loading...
Searching...
No Matches
resizeboundingbox.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <QCursor>
4#include <QMargins>
5#include <QMouseEvent>
6#include <QPainter>
7#include <QWidget>
8
9static const int OUTER_HITBOX_SIZE = 10;
10static const QMargins WIDGET_MARGIN(20, 20, 20, 20);
11static const QMargins CENTER_HITBOX_MARGIN(15, 15, 15, 15);
12
25
26class ResizeBoundingBox : public QWidget
27{
28 Q_OBJECT
29public:
30 explicit ResizeBoundingBox(QWidget *parent = nullptr);
31
32 /* @brief Sets the size of bounding box.
33
34 This method sets the size of the visable bounding box.
35 The actual Widget has an offset, so that the mouse direction ankers are drawn correctly.
36
37 @param box_geometry Geometry of the bounding box.
38 */
39 void setBoxGeometry(QRect box_geometry);
40
41 /* @brief Sets the minimum size of the bounding box.
42
43 This method sets the minimum size of the visable bounding box.
44 The actual Widget has an offset, so that the mouse direction ankers are drawn correctly.
45
46 @param size Minimum size of the bounding box.
47 */
48 void setBoxMinimumSize(QSize size);
49
50protected:
51 void mousePressEvent(QMouseEvent *) override;
52 void mouseMoveEvent(QMouseEvent *) override;
53 void mouseReleaseEvent(QMouseEvent *) override;
54
55 void paintEvent(QPaintEvent *) override;
56
57signals:
59
60private:
61 QRect box_geometry;
62
63 QRect mapRectFromParent(QRect);
64 static QRect squareByCenter(QPoint, int);
65 QMap<DragDirection, QPoint> outerHitboxPositions();
66 QMap<DragDirection, QRect> hitboxes();
67 DragDirection containesHitbox(QPoint);
68 void setHoverCursor(DragDirection);
69
70 DragDirection active_direction = DragDirection::None;
71 bool mouse_pressed = false;
72
73 QPointF last_global_position;
74 QRect last_geometry;
75};
void changedDelta(DragDirection, QPointF)
void mouseMoveEvent(QMouseEvent *) override
Definition resizeboundingbox.cpp:127
ResizeBoundingBox(QWidget *parent=nullptr)
Definition resizeboundingbox.cpp:3
void setBoxGeometry(QRect box_geometry)
Definition resizeboundingbox.cpp:9
void setBoxMinimumSize(QSize size)
Definition resizeboundingbox.cpp:15
void mousePressEvent(QMouseEvent *) override
Definition resizeboundingbox.cpp:141
void mouseReleaseEvent(QMouseEvent *) override
Definition resizeboundingbox.cpp:154
void paintEvent(QPaintEvent *) override
Definition resizeboundingbox.cpp:23
DragDirection
Definition resizeboundingbox.hpp:13
@ NorthWest
Definition resizeboundingbox.hpp:14
@ South
Definition resizeboundingbox.hpp:19
@ Center
Definition resizeboundingbox.hpp:22
@ North
Definition resizeboundingbox.hpp:15
@ None
Definition resizeboundingbox.hpp:23
@ NorthEast
Definition resizeboundingbox.hpp:16
@ SouthEast
Definition resizeboundingbox.hpp:18
@ East
Definition resizeboundingbox.hpp:17
@ West
Definition resizeboundingbox.hpp:21
@ SouthWest
Definition resizeboundingbox.hpp:20