Warning, file /frameworks/kwindowsystem/tests/blurbehindtest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2013 Nicolás Alvarez <nicolas.alvarez@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #include <QApplication> 0009 #include <QPushButton> 0010 #include <QVBoxLayout> 0011 #include <QWidget> 0012 0013 #include <kwindoweffects.h> 0014 0015 class BlurTestWindow : public QWidget 0016 { 0017 public: 0018 BlurTestWindow(); 0019 0020 void resizeEvent(QResizeEvent *) override; 0021 0022 private: 0023 QPushButton *m_btnNothing; 0024 QPushButton *m_btnFullWindow; 0025 QPushButton *m_btnRect; 0026 QPushButton *m_btnEllipse; 0027 QWidget *m_area; 0028 0029 enum { Nothing, FullWindow, Rect, Ellipse } m_state; 0030 0031 void setWindowAlpha(int alpha); 0032 0033 void disableBlur(); 0034 void enableBlur(); 0035 void enableBlurRect(); 0036 void enableBlurEllipse(); 0037 }; 0038 0039 BlurTestWindow::BlurTestWindow() 0040 { 0041 m_state = Nothing; 0042 setAttribute(Qt::WA_TranslucentBackground); 0043 setAttribute(Qt::WA_NoSystemBackground, false); 0044 setWindowAlpha(192); 0045 0046 m_btnNothing = new QPushButton("Nothing"); 0047 m_btnFullWindow = new QPushButton("Full window"); 0048 m_btnRect = new QPushButton("Rectangle"); 0049 m_btnEllipse = new QPushButton("Ellipse"); 0050 0051 m_area = new QWidget; 0052 m_area->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 0053 0054 connect(m_btnNothing, &QPushButton::clicked, this, &BlurTestWindow::disableBlur); 0055 connect(m_btnFullWindow, &QPushButton::clicked, this, &BlurTestWindow::enableBlur); 0056 connect(m_btnRect, &QPushButton::clicked, this, &BlurTestWindow::enableBlurRect); 0057 connect(m_btnEllipse, &QPushButton::clicked, this, &BlurTestWindow::enableBlurEllipse); 0058 0059 QVBoxLayout *layout = new QVBoxLayout(this); 0060 layout->addWidget(m_btnNothing); 0061 layout->addWidget(m_btnFullWindow); 0062 layout->addWidget(m_btnRect); 0063 layout->addWidget(m_btnEllipse); 0064 layout->addWidget(m_area); 0065 0066 winId(); // force creation of the associated window 0067 } 0068 0069 void BlurTestWindow::disableBlur() 0070 { 0071 m_state = Nothing; 0072 KWindowEffects::enableBlurBehind(windowHandle(), false); 0073 repaint(); 0074 } 0075 void BlurTestWindow::enableBlur() 0076 { 0077 m_state = FullWindow; 0078 KWindowEffects::enableBlurBehind(windowHandle(), true); 0079 repaint(); 0080 } 0081 void BlurTestWindow::enableBlurRect() 0082 { 0083 m_state = Rect; 0084 QRegion rgn(m_area->geometry()); 0085 KWindowEffects::enableBlurBehind(windowHandle(), true, rgn); 0086 repaint(); 0087 } 0088 void BlurTestWindow::enableBlurEllipse() 0089 { 0090 m_state = Ellipse; 0091 QRegion rgn(m_area->geometry(), QRegion::Ellipse); 0092 KWindowEffects::enableBlurBehind(windowHandle(), true, rgn); 0093 repaint(); 0094 } 0095 0096 void BlurTestWindow::resizeEvent(QResizeEvent *) 0097 { 0098 if (m_state == Rect) { 0099 enableBlurRect(); 0100 } else if (m_state == Ellipse) { 0101 enableBlurEllipse(); 0102 } 0103 } 0104 0105 void BlurTestWindow::setWindowAlpha(int alpha) 0106 { 0107 QPalette pal = this->palette(); 0108 QColor windowColor = pal.color(QPalette::Window); 0109 windowColor.setAlpha(alpha); 0110 pal.setColor(QPalette::Window, windowColor); 0111 this->setPalette(pal); 0112 } 0113 0114 int main(int argc, char **argv) 0115 { 0116 QApplication app(argc, argv); 0117 0118 BlurTestWindow wnd; 0119 wnd.show(); 0120 0121 return app.exec(); 0122 }