basemainwidget.cpp
1.53 KB
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
#include "basemainwidget.h"
#include <QPainter>
#include <qmath.h>
#include <QMouseEvent>
#include <QApplication>
#include <QDesktopWidget>
BaseMainWidget::BaseMainWidget(QWidget *parent) :
QFrame(parent)
{
setWindowFlags(Qt::FramelessWindowHint);
this->setAutoFillBackground(true);
}
void BaseMainWidget::paintEvent(QPaintEvent *)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
int cut = 1;
path.addRect(cut, cut, this->width()-cut*2, this->height()-cut*2);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.fillPath(path, QBrush(Qt::white));
QColor color("#ffffff");
for(int i=0; i<cut; i++)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRect(cut-i, cut-i, this->width()-(cut-i)*2, this->height()-(cut-i)*2);
color.setAlpha(150 - qSqrt(i)*50);
painter.setPen(color);
painter.drawPath(path);
}
}
void BaseMainWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}
void BaseMainWidget::mouseReleaseEvent(QMouseEvent *)
{
if (geometry().y() < QApplication::desktop()->geometry().top()) {
move(geometry().x(), QApplication::desktop()->geometry().top());
}
}
void BaseMainWidget::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() &Qt::LeftButton) {
move(event->globalPos() - dragPosition);
event->accept();
}
}