-
Notifications
You must be signed in to change notification settings - Fork 0
/
applet.cpp
114 lines (96 loc) · 4.07 KB
/
applet.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "applet.h"
void Applet::setBlurredBackground() {
QScreen* screen = mInternalWidget->screen();
QRect screenGeometry = screen->geometry();
QRect widgetGeometry = mInternalWidget->geometry();
QPixmap pixmap = screen->grabWindow(0,
widgetGeometry.x(),
widgetGeometry.y(),
widgetGeometry.width(),
widgetGeometry.height());
QGraphicsBlurEffect* blurEffect = new QGraphicsBlurEffect();
blurEffect->setBlurRadius(15);
blurEffect->setBlurHints(QGraphicsBlurEffect::QualityHint);
QGraphicsScene* scene = new QGraphicsScene();
QGraphicsPixmapItem item;
item.setPixmap(pixmap);
item.setGraphicsEffect(blurEffect);
scene->addItem(&item);
QImage res(QSize(widgetGeometry.width(), widgetGeometry.height()), QImage::Format_ARGB32);
res.fill(Qt::transparent);
QPainter ptr(&res);
scene->render(&ptr, QRectF(), QRectF(0, 0, widgetGeometry.width(), widgetGeometry.height()));
QPalette palette;
palette.setBrush(mInternalWidget->backgroundRole(),
QBrush(QPixmap::fromImage(res)));
mInternalWidget->setPalette(palette);
}
QPair<int,int> Applet::getButtonCoordinates() {
int buttonCoord1, buttonCoord2;
if (mParentPanel->mPanelLayout == Horizontal) {
buttonCoord1 = mExternalWidget->x() + mParentPanel->mAxisShift;
buttonCoord2 = mExternalWidget->geometry().topRight().x() +
mParentPanel->mAxisShift;
}
else { // Vertical
buttonCoord1 = mExternalWidget->y() + mParentPanel->mAxisShift;
buttonCoord2 = mExternalWidget->geometry().bottomRight().y() +
mParentPanel->mAxisShift;
}
return qMakePair(buttonCoord1, buttonCoord2);
}
void Applet::preliminaryInternalWidgetSetup(int width,
int height,
bool canBeTransparent) {
// Window flags
mInternalWidget->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
// Geometry
QScreen* screen = mParentPanel->mPanelScreen;
QRect screenGeometry = screen->geometry();
int ax = 0, ay = 0;
QPair<int,int> buttonCoords = getButtonCoordinates();
int buttonCoord1 = buttonCoords.first, buttonCoord2 = buttonCoords.second;
switch (mParentPanel->mPanelLocation) {
case Top:
ax = (screenGeometry.width() - buttonCoord1 >= width) ? buttonCoord1 : buttonCoord2 - width;
ay = mParentPanel->mPanelThickness + 5;
break;
case Bottom:
ax = (screenGeometry.width() - buttonCoord1 >= width) ? buttonCoord1 : buttonCoord2 - width;
ay = screenGeometry.height() - mParentPanel->mPanelThickness - height - 5;
break;
case Left:
ax = mParentPanel->mPanelThickness + 5;
ay = (screenGeometry.height() - buttonCoord1 >= height) ? buttonCoord1 : buttonCoord2 - height;
break;
case Right:
ax = screenGeometry.width() - mParentPanel->mPanelThickness - width - 5;
ay = (screenGeometry.height() - buttonCoord1 >= height) ? buttonCoord1 : buttonCoord2 - height;
break;
}
ax += screenGeometry.x();
ay += screenGeometry.y();
mInternalWidget->setFixedSize(width, height);
mInternalWidget->move(ax, ay);
// Font
mInternalWidget->setFont(mCfgMan->mFont);
// Theme
QFile stylesheetReader("/usr/share/plainDE/styles/" + mCfgMan->mStylesheet);
stylesheetReader.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream styleSheet(&stylesheetReader);
mInternalWidget->setStyleSheet(styleSheet.readAll());
if (mCfgMan->mTransparent && canBeTransparent) {
setBlurredBackground();
}
// Opacity
mInternalWidget->setWindowOpacity(mParentPanel->mOpacity);
}
void Applet::externalWidgetSetup() {
}
void Applet::internalWidgetSetup() {
}
Applet::Applet(QString appletID, ConfigManager* cfgMan, Panel* parentPanel) {
mAppletID = appletID;
mCfgMan = cfgMan;
mParentPanel = parentPanel;
}