-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransperant.cpp
More file actions
75 lines (56 loc) · 1.84 KB
/
Copy pathtransperant.cpp
File metadata and controls
75 lines (56 loc) · 1.84 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "transperant.h"
#include <QDebug>
#include <QPainter>
#include <QPainterPath>
static QPainterPath DrawPopWindow(QRect rect, int radius = 0, int inlineWeight = 0) {
rect.adjust(inlineWeight,inlineWeight,-inlineWeight,-inlineWeight);
int trigangleWidth = rect.width()/5;
QPainterPath topTriangle;
if(radius != 0) radius = radius/2;
topTriangle.addRoundedRect(QRect(0,0,trigangleWidth,trigangleWidth), radius, radius);
// qreal hip = sqrt((trigangleWidth * trigangleWidth) + (trigangleWidth * trigangleWidth));
qreal hip = sqrt(pow(trigangleWidth,2) + pow(trigangleWidth,2));
int location = rect.width()/2 - hip/2;
topTriangle = QTransform()
.translate(location,(trigangleWidth/2 + trigangleWidth/5))
.rotate(-45)
.map(topTriangle);
QPainterPath mainRect;
mainRect.addRoundedRect(rect.adjusted(0,trigangleWidth/2,0,0), radius, radius);
return mainRect + topTriangle;
}
Transperant::Transperant(QWidget *parent)
: QWidget(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint)
{
resize(300,600);
setAttribute(Qt::WA_TranslucentBackground);
setMouseTracking(true);
}
void Transperant::paintEvent(QPaintEvent*event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
int iw = 5;
QPainterPath path = DrawPopWindow(this->rect(),24, iw);
painter.fillPath(path, Qt::red);
QPainterPath inlinePath = path;
QColor border = isMouseOver ? Qt::white : Qt::red;
border.setAlpha(250);
painter.setPen(QPen(border, iw, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
painter.drawPath(inlinePath);
QWidget::paintEvent(event);
}
void Transperant::enterEvent(QEnterEvent*event)
{
qDebug() << "inside ";
isMouseOver = true;
update();
QWidget::enterEvent(event);
}
void Transperant::leaveEvent(QEvent*event)
{
isMouseOver = false;
update();
qDebug() << "outside ";
QWidget::leaveEvent(event);
}