-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMoveFramelessWindow.h
81 lines (69 loc) · 1.97 KB
/
MoveFramelessWindow.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
#ifndef _MOVE_FRAMELESS_WINDOW_H_
#define _MOVE_FRAMELESS_WINDOW_H_
#include <QtWidgets/QWidget>
#include <QtGui/QtEvents>
template<typename T>
class MoveFramelessWindow: public T
{
public:
MoveFramelessWindow(QWidget * parent = 0, Qt::WindowFlags f = 0)
:T(parent, f)
{}
//protected:
// void mouseMoveEvent(QMouseEvent *event)
// {
// if (event->buttons() & Qt::LeftButton) {
// move(event->globalPos() - dragon_posision_);
// event->accept();
// }
// }
//
// void mousePressEvent(QMouseEvent *event)
// {
// if (event->button() == Qt::LeftButton) {
// dragon_posision_ = event->globalPos() - frameGeometry().topLeft();
// event->accept();
// }
// }
//
//protected:
// QPoint dragon_posision_;
protected:
void mousePressEvent(QMouseEvent* event)
{
offset = event->pos();
QWidget::mousePressEvent(event);
}
void mouseMoveEvent(QMouseEvent* event)
{
if(event->buttons() & Qt::LeftButton)
if(resizeMode) {
QPoint p = mapToGlobal(event->pos()) - geometry().topLeft();
resize(p.x(), p.y());
} else
move(mapToParent(event->pos() - offset));
else {
QPoint diff = geometry().bottomRight() - mapToGlobal(event->pos());
if(diff.x() <= 6 && diff.y() <= 6) {
if(!resizeMode) {
setCursor(Qt::SizeFDiagCursor);
resizeMode = true;
}
} else {
if(resizeMode) {
setCursor(Qt::SizeAllCursor);
resizeMode = false;
}
}
}
}
void mouseReleaseEvent(QMouseEvent* event)
{
offset = QPoint();
QWidget::mouseReleaseEvent(event);
}
private:
QPoint offset;
bool resizeMode;
};
#endif