/
xybordershadowwidget.cpp
77 lines (67 loc) · 1.94 KB
/
xybordershadowwidget.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
#include "xybordershadowwidget.h"
#include <QPainter>
#include <QMouseEvent>
#include <qmath.h>
XYBorderShadowWidget::XYBorderShadowWidget(QWidget *parent)
: QWidget(parent)
{
this->setAttribute(Qt::WA_TranslucentBackground);
mbLeftMousePressed = false;
}
XYBorderShadowWidget::~XYBorderShadowWidget()
{
}
bool XYBorderShadowWidget::close()
{
emit closed();
return QWidget::close();
}
void XYBorderShadowWidget::paintEvent(QPaintEvent *event)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRect(10, 10, this->width() - 20, this->height() - 20);
QPainter painter(this);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.fillRect(rect(), QColor(0x00, 0x00, 0x00, 0x00));
painter.fillPath(path, QColor(Qt::white));
QColor color(0,0,0,0);
for (int i=0; i<10; i++)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRoundedRect(10-i, 10-i, this->width()-(10-i)*2, this->height()-(10-i)*2, i, i);
int alpha = 150 - qSqrt(i)*50;
color.setAlpha(alpha > 0? alpha/3:0);
painter.setPen(color);
painter.drawPath(path);
}
}
void XYBorderShadowWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
mbLeftMousePressed = true;
moLastPos = event->globalPos();
}
}
void XYBorderShadowWidget::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
mbLeftMousePressed = false;
moLastPos = event->globalPos();
}
}
void XYBorderShadowWidget::mouseMoveEvent(QMouseEvent *event)
{
if (mbLeftMousePressed)
{
QPoint lastpos = pos();
lastpos.setX( lastpos.x() + event->globalX() - moLastPos.x());
lastpos.setY( lastpos.y() + event->globalY() - moLastPos.y());
move(lastpos);
moLastPos = event->globalPos();
}
}