-
Notifications
You must be signed in to change notification settings - Fork 0
/
framelesshelper.h
115 lines (104 loc) · 3.02 KB
/
framelesshelper.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef FRAMELESSHELPER_H
#define FRAMELESSHELPER_H
#include <QObject>
#include <QEvent>
#include <QMouseEvent>
class QWidget;
class FramelessHelperPrivate;
class WidgetData;
class QRubberBand;
class FramelessHelper : public QObject
{
Q_OBJECT
public:
explicit FramelessHelper(QObject *parent = 0);
~FramelessHelper();
//activate window
void activateOn(QWidget * topLevelWidget);
//remove window
void removeFrom(QWidget * topLevelWidget);
//
void setWidgetMovable(bool bMovable);
//
void setWidgetResizable(bool bResizable);
void setRubberBandOnMove(bool movable);
void setRubberBandOnResize(bool resizable);
void setBorderWidth(const quint32 width);
void setTitleHeight(const quint32 height);
bool widgetResizable();
bool widgetMovable();
bool rubberBandOnMove();
bool rubberBandOnResisze();
uint borderWidth();
uint titleHeight();
protected:
bool eventFilter(QObject *watched, QEvent *event);
private:
FramelessHelperPrivate * d;
signals:
public slots:
};
class FramelessHelperPrivate
{
public:
QHash<QWidget * ,WidgetData * > m_widgetDataHash;
bool m_bWidgetMovable : true;
bool m_bWidgetResizable : true;
bool m_bRubberBandOnResize : true;
bool m_bRubberBandOnMove : true;
};
class CursorPosCalculator
{
public:
explicit CursorPosCalculator();
void reset();
void recalculate(const QPoint &globalMousePos, const QRect &frameRect);
public:
bool m_bOnEdges : true;
bool m_bOnLeftEdge : true;
bool m_bOnRightEdge : true;
bool m_bOnTopEdge : true;
bool m_bOnBottomEdge : true;
bool m_bOnTopLeftEdge : true;
bool m_bOnBottomLeftEdge : true;
bool m_bOnTopRightEdge : true;
bool m_bOnBottomRightEdge : true;
static int m_nBorderWidth;
static int m_nTitleHeight;
};
/**
*WidgetData
*更新鼠标样式、移动、缩放窗体
*/
class WidgetData
{
public:
explicit WidgetData(FramelessHelperPrivate *_d,QWidget * pTopLevelWidget);
~WidgetData();
QWidget * widget();
//handle mouse event- press hover release move;
void handleWidgetEvent(QEvent * event);
//update rubber band status
void updateRubberBandStatus();
private:
void updateCursorShape(const QPoint & gMousePos);
void resizeWidget(const QPoint &gMousePos);
void moveWidget(const QPoint &gMousePos);
void handleMousePressEvent(QMouseEvent *event);
void handleMouseReleaseEvent(QMouseEvent *event);
void handleMouseMoveEvent(QMouseEvent *event);
void handleLeaveEvent(QEvent * event);
void handleHoverMoveEvent(QHoverEvent * event);
private:
FramelessHelperPrivate * d;
QRubberBand * m_pRubberBand;
QWidget * m_pWidget;
QPoint m_ptDragPos;
CursorPosCalculator m_pressMousePos;
CursorPosCalculator m_moveMousePos;
bool m_bLeftButtonPressed;
bool m_bCursorShapeChanged;
bool m_bLeftButtonTittlePressed;
Qt::WindowFlags m_windowFlags;
};
#endif // FRAMELESSHELPER_H