-
Notifications
You must be signed in to change notification settings - Fork 4
/
windowdragger.cpp
56 lines (46 loc) · 1.85 KB
/
windowdragger.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
/*
###############################################################################
# #
# The MIT License #
# #
# Copyright (C) 2017 by Juergen Skrotzky ([email protected]) #
# >> https://github.com/Jorgen-VikingGod #
# #
# Sources: https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle #
# #
###############################################################################
*/
#include "windowdragger.h"
#include <QPainter>
#include <QStyleOption>
WindowDragger::WindowDragger(QWidget *parent) : QWidget(parent) {
mousePressed = false;
}
void WindowDragger::mousePressEvent(QMouseEvent *event) {
mousePressed = true;
mousePos = event->globalPos();
QWidget *parent = parentWidget();
if (parent) parent = parent->parentWidget();
if (parent) wndPos = parent->pos();
}
void WindowDragger::mouseMoveEvent(QMouseEvent *event) {
QWidget *parent = parentWidget();
if (parent) parent = parent->parentWidget();
if (parent && mousePressed)
parent->move(wndPos + (event->globalPos() - mousePos));
}
void WindowDragger::mouseReleaseEvent(QMouseEvent *event) {
Q_UNUSED(event);
mousePressed = false;
}
void WindowDragger::paintEvent(QPaintEvent *event) {
Q_UNUSED(event);
QStyleOption styleOption;
styleOption.init(this);
QPainter painter(this);
style()->drawPrimitive(QStyle::PE_Widget, &styleOption, &painter, this);
}
void WindowDragger::mouseDoubleClickEvent(QMouseEvent *event) {
Q_UNUSED(event);
emit doubleClicked();
}