|
| 1 | +#include "applet.h" |
| 2 | + |
| 3 | +void Applet::setBlurredBackground(QWidget* internalWidget) { |
| 4 | + QScreen* screen = internalWidget->screen(); |
| 5 | + QRect widgetGeometry = internalWidget->geometry(); |
| 6 | + QPixmap pixmap = screen->grabWindow(0, |
| 7 | + widgetGeometry.x(), |
| 8 | + widgetGeometry.y(), |
| 9 | + widgetGeometry.width(), |
| 10 | + widgetGeometry.height()); |
| 11 | + qDebug() << widgetGeometry; |
| 12 | + QGraphicsBlurEffect* blurEffect = new QGraphicsBlurEffect(); |
| 13 | + blurEffect->setBlurRadius(15); |
| 14 | + blurEffect->setBlurHints(QGraphicsBlurEffect::QualityHint); |
| 15 | + |
| 16 | + QGraphicsScene* scene = new QGraphicsScene(); |
| 17 | + QGraphicsPixmapItem item; |
| 18 | + item.setPixmap(pixmap); |
| 19 | + item.setGraphicsEffect(blurEffect); |
| 20 | + scene->addItem(&item); |
| 21 | + QImage res(QSize(widgetGeometry.width(), widgetGeometry.height()), QImage::Format_ARGB32); |
| 22 | + res.fill(Qt::transparent); |
| 23 | + QPainter ptr(&res); |
| 24 | + scene->render(&ptr, QRectF(), QRectF(0, 0, widgetGeometry.width(), widgetGeometry.height())); |
| 25 | + |
| 26 | + QPalette palette; |
| 27 | + palette.setBrush(internalWidget->backgroundRole(), |
| 28 | + QBrush(QPixmap::fromImage(res))); |
| 29 | + internalWidget->setPalette(palette); |
| 30 | +} |
| 31 | + |
| 32 | +QPair<int,int> Applet::getButtonCoordinates(QWidget* externalWidget, Panel* parentPanel) { |
| 33 | + int buttonCoord1, buttonCoord2; |
| 34 | + if (parentPanel->mPanelLayout == Horizontal) { |
| 35 | + buttonCoord1 = externalWidget->x() + parentPanel->mAxisShift; |
| 36 | + buttonCoord2 = externalWidget->geometry().topRight().x() + parentPanel->mAxisShift; |
| 37 | + } |
| 38 | + else { // Vertical |
| 39 | + buttonCoord1 = externalWidget->y() + parentPanel->mAxisShift; |
| 40 | + buttonCoord2 = externalWidget->geometry().bottomRight().y() + parentPanel->mAxisShift; |
| 41 | + } |
| 42 | + return qMakePair(buttonCoord1, buttonCoord2); |
| 43 | +} |
| 44 | + |
| 45 | +void Applet::externalWidgetSetup(ConfigManager*, Panel*) { |
| 46 | + |
| 47 | +} |
| 48 | + |
| 49 | +void Applet::preliminaryInternalWidgetSetup(QWidget* internalWidget, |
| 50 | + QWidget* externalWidget, |
| 51 | + ConfigManager* cfgMan, |
| 52 | + Panel* parentPanel, |
| 53 | + int width, |
| 54 | + int height, |
| 55 | + bool canBeTransparent) { |
| 56 | + // Window flags |
| 57 | + internalWidget->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); |
| 58 | + |
| 59 | + // Geometry |
| 60 | + QScreen* screen = parentPanel->mPanelScreen; |
| 61 | + QRect screenGeometry = screen->geometry(); |
| 62 | + int ax = 0, ay = 0; |
| 63 | + QPair<int,int> buttonCoords = getButtonCoordinates(externalWidget, parentPanel); |
| 64 | + int buttonCoord1 = buttonCoords.first, buttonCoord2 = buttonCoords.second; |
| 65 | + switch (parentPanel->mPanelLocation) { |
| 66 | + case Top: |
| 67 | + ax = (screenGeometry.width() - buttonCoord1 >= width) ? buttonCoord1 : buttonCoord2 - width; |
| 68 | + ay = parentPanel->mPanelThickness + 5; |
| 69 | + break; |
| 70 | + |
| 71 | + case Bottom: |
| 72 | + ax = (screenGeometry.width() - buttonCoord1 >= width) ? buttonCoord1 : buttonCoord2 - width; |
| 73 | + ay = screenGeometry.height() - parentPanel->mPanelThickness - height - 5; |
| 74 | + break; |
| 75 | + |
| 76 | + case Left: |
| 77 | + ax = parentPanel->mPanelThickness + 5; |
| 78 | + ay = (screenGeometry.height() - buttonCoord1 >= height) ? buttonCoord1 : buttonCoord2 - height; |
| 79 | + break; |
| 80 | + |
| 81 | + case Right: |
| 82 | + ax = screenGeometry.width() - parentPanel->mPanelThickness - width - 5; |
| 83 | + ay = (screenGeometry.height() - buttonCoord1 >= height) ? buttonCoord1 : buttonCoord2 - height; |
| 84 | + break; |
| 85 | + } |
| 86 | + |
| 87 | + ax += screenGeometry.x(); |
| 88 | + ay += screenGeometry.y(); |
| 89 | + internalWidget->setFixedSize(width, height); |
| 90 | + internalWidget->move(ax, ay); |
| 91 | + |
| 92 | + // Font |
| 93 | + internalWidget->setFont(cfgMan->mFont); |
| 94 | + |
| 95 | + // Theme |
| 96 | + QFile stylesheetReader("/usr/share/plainDE/styles/" + cfgMan->mStylesheet); |
| 97 | + stylesheetReader.open(QIODevice::ReadOnly | QIODevice::Text); |
| 98 | + QTextStream styleSheet(&stylesheetReader); |
| 99 | + internalWidget->setStyleSheet(styleSheet.readAll()); |
| 100 | + if (cfgMan->mTransparent && canBeTransparent) { |
| 101 | + setBlurredBackground(internalWidget); |
| 102 | + } |
| 103 | + |
| 104 | + // Opacity |
| 105 | + internalWidget->setWindowOpacity(parentPanel->mOpacity); |
| 106 | +} |
| 107 | + |
| 108 | +Applet::Applet(ConfigManager*, Panel*, QString) { |
| 109 | + |
| 110 | +} |
0 commit comments