-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpip_float_window.cpp
More file actions
68 lines (57 loc) · 1.59 KB
/
pip_float_window.cpp
File metadata and controls
68 lines (57 loc) · 1.59 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
// ======================= pip_float_window.cpp =======================
#include "pip_float_window.h"
#include <QVideoWidget>
#include <QVBoxLayout>
#include <QMouseEvent>
#include <QRegion>
PipFloatWindow::PipFloatWindow(QWidget *parent)
: QWidget(parent)
{
//setWindowFlags(Qt::FramelessWindowHint |
// Qt::WindowStaysOnTopHint |
// Qt::Tool);
setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_ShowWithoutActivating, true);
m_videoWidget = new QVideoWidget(this);
m_videoWidget->setAspectRatioMode(Qt::KeepAspectRatio);
auto *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_videoWidget);
resize(260, 180);
}
QVideoWidget *PipFloatWindow::videoWidget() const
{
return m_videoWidget;
}
void PipFloatWindow::setCircleShape(bool enabled)
{
m_circle = enabled;
if (m_circle) {
setMask(QRegion(rect(), QRegion::Ellipse));
} else {
clearMask();
}
}
void PipFloatWindow::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
m_dragOffset = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}
void PipFloatWindow::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton) {
move(event->globalPos() - m_dragOffset);
event->accept();
}
}
void PipFloatWindow::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
if (m_circle) {
setMask(QRegion(rect(), QRegion::Ellipse));
} else {
clearMask();
}
}