-
Notifications
You must be signed in to change notification settings - Fork 12
/
flwidget_linux.cpp
80 lines (66 loc) · 1.97 KB
/
flwidget_linux.cpp
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
#include "flwidget_linux.h"
#include <QLayout>
#include <QMouseEvent>
namespace
{
#define ResizeHandleWidth 10
}
FLWidget_Linux::FLWidget_Linux(QWidget *parent) : QWidget(parent)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
setStyleSheet("background-color:red;");
QHBoxLayout* layoutMain = new QHBoxLayout(this);
layoutMain->setContentsMargins(ResizeHandleWidth, ResizeHandleWidth, ResizeHandleWidth, ResizeHandleWidth);
this->setLayout(layoutMain);
resizingCornerEdge = XUtils::CornerEdge::kInvalid;
setMouseTracking(true);
XUtils::SetMouseTransparent(this, true);
setAttribute(Qt::WA_ShowModal);
resize(400, 400);
}
void FLWidget_Linux::mouseMoveEvent(QMouseEvent *event)
{
#ifdef Q_OS_LINUX
const int x = event->x();
const int y = event->y();
if (resizingCornerEdge == XUtils::CornerEdge::kInvalid)
{
XUtils::UpdateCursorShape(this, x, y, this->layout()->contentsMargins(), ResizeHandleWidth);
}
#endif
return QWidget::mouseMoveEvent(event);
}
void FLWidget_Linux::mousePressEvent(QMouseEvent *event)
{
#ifdef Q_OS_LINUX
const int x = event->x();
const int y = event->y();
if (event->button() == Qt::LeftButton)
{
const XUtils::CornerEdge ce = XUtils::GetCornerEdge(this, x, y, this->layout()->contentsMargins(), ResizeHandleWidth);
if (ce != XUtils::CornerEdge::kInvalid)
{
resizingCornerEdge = ce;
//send x11 move event dont send mouserrelease event
XUtils::SendButtonRelease(this, event->pos(), event->globalPos());
XUtils::StartResizing(this, QCursor::pos(), ce);
}
}
#endif
return QWidget::mousePressEvent(event);
}
void FLWidget_Linux::resizeEvent(QResizeEvent *e)
{
#ifdef Q_OS_LINUX
int resizeHandleWidth = ResizeHandleWidth;
XUtils::SetWindowExtents(this, this->layout()->contentsMargins(), resizeHandleWidth);
#endif
return QWidget::resizeEvent(e);
}
void FLWidget_Linux::mouseReleaseEvent(QMouseEvent *event)
{
#ifdef Q_OS_LINUX
resizingCornerEdge = XUtils::CornerEdge::kInvalid;
#endif
return QWidget::mouseReleaseEvent(event);
}