-
Notifications
You must be signed in to change notification settings - Fork 0
/
rectselection.h
57 lines (52 loc) · 1.5 KB
/
rectselection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef RECTSELECTION_H
#define RECTSELECTION_H
#include <QRect>
#include <QSize>
#include <QPoint>
#include <QPainter>
#include <QPen>
#include <QBrush>
#define RECT_SELECTION_DEFAULT_HANDLE_SIZE 5;
class RectSelection
{
public:
RectSelection();
void reinit();
void draw(QPainter &painter);
//TODO: I may turn these to events if I decide to make selection tool a seperate widget
void pressed(const QPoint &pos);
void moved(const QPoint &pos);
void released(const QPoint &pos);
//properties
int getHandleSize() const;
void setHandleSize(const int size);
QSize getMinSize() const;
void setMinSize(const QSize &size);
void setCanvasSize(const QSize &value);
QPen getPenFrame() const;
void setPenFrame(const QPen &value);
QPen getPenHandle() const;
void setPenHandle(const QPen &value);
QBrush getBrushHandle() const;
void setBrushHandle(const QBrush &value);
QRect getFrame() const;
private:
QSize minSize;
bool minSizeSetManually; //if false use handleSize*2 as min
void setDefaultMinSize();
int handleSize;
QSize canvasSize;
QRect frame;
QRect tl, tr, bl, br;
enum class Pressed { frame, tl, tr, bl, br, none };
Pressed curPressed = Pressed::none;
QPoint lastPressedPos;
void adjustHandlePos();
void adjustHandleSize();
QPen penFrame;
QPen penHandle;
QBrush brushHandle;
void checkCanvasBounds(QRect &newRect);
void checkSrcImgBounds(QRect &newRect);
};
#endif // RECTSELECTION_H