-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenTimer.cpp
More file actions
74 lines (62 loc) · 2.85 KB
/
ScreenTimer.cpp
File metadata and controls
74 lines (62 loc) · 2.85 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
#include "ScreenTimer.h"
#include <QDesktopWidget>
#include <QMouseEvent>
#include <QLayout>
#include <QPushButton>
#include <QPainter>
#include "BlurPanel.h"
#include "centralWgt.h"
static const unsigned int CNTRL_SH_INT = 1500;//msec
static const float WGT_WDTH_PERC = 0.15f;//widget width percentage of screen
static const float WGT_HGHT_PERC = 0.07f;//widget height percentage of screen
static const int SCRN_X_OFFSET = 5;//screen offset in x axis
static const int SCRN_Y_OFFSET = 5;//scrren offset in y axis
ScreenTimer::ScreenTimer(QWidget *parent)
: QMainWindow(parent)
{
QDesktopWidget qdw;
QRect scrnRct = qdw.availableGeometry();
setupUi(QSize(scrnRct.size()));
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::ToolTip);
setAttribute(Qt::WA_AlwaysStackOnTop, true);
setAttribute(Qt::WA_TranslucentBackground, true);
//setAttribute(Qt::WA_NoSystemBackground, true);
this->move(scrnRct.x() + scrnRct.width() * (1 - WGT_WDTH_PERC) - SCRN_X_OFFSET, scrnRct.y() + SCRN_Y_OFFSET);
/*curved frame*/
const int radius = 10;
QPainterPath pPath;
pPath.addRoundedRect(this->rect(), radius, radius);
QRegion mask = QRegion(pPath.toFillPolygon().toPolygon());
this->setMask(mask);
/*enable mouse tracking*/
centralWidget->setMouseTracking(true);
}
ScreenTimer::~ScreenTimer()
{
//m_pBlur is dynamically deleted
/*if (m_pBlur != Q_NULLPTR)
m_pBlur->deleteLater();*/
}
void ScreenTimer::setupUi(QSize scrnSz)
{
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
printf("screen width %d height %d\n", scrnSz.width(), scrnSz.height());
printf("widget width %f height %f\n", scrnSz.width() * WGT_WDTH_PERC, scrnSz.height() * WGT_HGHT_PERC);
if (this->objectName().isEmpty())
this->setObjectName(QString::fromUtf8("ScreenTimer"));
this->resize(scrnSz.width() * WGT_WDTH_PERC, scrnSz.height() * WGT_HGHT_PERC);
this->setSizePolicy(sizePolicy);
this->setMinimumSize(QSize(scrnSz.width() * WGT_WDTH_PERC, scrnSz.height() * WGT_HGHT_PERC));
this->setMaximumSize(QSize(scrnSz.width() * WGT_WDTH_PERC, scrnSz.height() * WGT_HGHT_PERC));
centralWidget = new CentralWgt(scrnSz, this);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
sizePolicy.setHeightForWidth(centralWidget->sizePolicy().hasHeightForWidth());
centralWidget->setSizePolicy(sizePolicy);
centralWidget->setMinimumSize(QSize(scrnSz.width() * WGT_WDTH_PERC, scrnSz.height() * WGT_HGHT_PERC));
centralWidget->setMaximumSize(QSize(scrnSz.width() * WGT_WDTH_PERC, scrnSz.height() * WGT_HGHT_PERC));
this->setCentralWidget(centralWidget);
//QMetaObject::connectSlotsByName(this);
} // setupUi