Warning, file /system/qtcurve/qt4/style/blurhelper.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*****************************************************************************
0002  *   Copyright 2010 Craig Drummond <craig.p.drummond@gmail.com>              *
0003  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0004  *                                                                           *
0005  *   This program is free software; you can redistribute it and/or modify    *
0006  *   it under the terms of the GNU Lesser General Public License as          *
0007  *   published by the Free Software Foundation; either version 2.1 of the    *
0008  *   License, or (at your option) version 3, or any later version accepted   *
0009  *   by the membership of KDE e.V. (or its successor approved by the         *
0010  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0011  *   Section 6 of version 3 of the license.                                  *
0012  *                                                                           *
0013  *   This program is distributed in the hope that it will be useful,         *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0016  *   Lesser General Public License for more details.                         *
0017  *                                                                           *
0018  *   You should have received a copy of the GNU Lesser General Public        *
0019  *   License along with this library. If not,                                *
0020  *   see <http://www.gnu.org/licenses/>.                                     *
0021  *****************************************************************************/
0022 
0023 #ifndef blurhelper_h
0024 #define blurhelper_h
0025 
0026 //////////////////////////////////////////////////////////////////////////////
0027 // blurhelper.h
0028 // handle regions passed to kwin for blurring
0029 // -------------------
0030 //
0031 // Copyright (c) 2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
0032 //
0033 // Loosely inspired (and largely rewritten) from BeSpin style
0034 // Copyright (C) 2007 Thomas Luebking <thomas.luebking@web.de>
0035 //
0036 // Permission is hereby granted, free of charge, to any person obtaining a copy
0037 // of this software and associated documentation files (the "Software"), to
0038 // deal in the Software without restriction, including without limitation the
0039 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
0040 // sell copies of the Software, and to permit persons to whom the Software is
0041 // furnished to do so, subject to the following conditions:
0042 //
0043 // The above copyright notice and this permission notice shall be included in
0044 // all copies or substantial portions of the Software.
0045 //
0046 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0047 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0048 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0049 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0050 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0051 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0052 // IN THE SOFTWARE.
0053 //////////////////////////////////////////////////////////////////////////////
0054 
0055 #include <qtcurve-utils/log.h>
0056 #include "utils.h"
0057 
0058 #include <QPointer>
0059 #include <QHash>
0060 #include <QBasicTimer>
0061 #include <QTimerEvent>
0062 #include <QDockWidget>
0063 #include <QMenu>
0064 #include <QMenuBar>
0065 #include <QRegion>
0066 #include <QToolBar>
0067 
0068 namespace QtCurve {
0069 class BlurHelper: public QObject {
0070     Q_OBJECT
0071 public:
0072     // ! constructor
0073     BlurHelper(QObject*);
0074 
0075     // ! enable state
0076     void
0077     setEnabled(bool value)
0078     {
0079         _enabled = value;
0080     }
0081     // ! enabled
0082     bool
0083     enabled() const
0084     {
0085         return _enabled;
0086     }
0087     // ! register widget
0088     void registerWidget(QWidget*);
0089     // ! register widget
0090     void unregisterWidget(QWidget*);
0091     // ! event filter
0092     bool eventFilter(QObject*, QEvent*) override;
0093 protected:
0094     // ! timer event
0095     /*! used to perform delayed blur region update of pending widgets */
0096     void
0097     timerEvent(QTimerEvent *event) override
0098     {
0099         if (event->timerId() == _timer.timerId()) {
0100             _timer.stop();
0101             update();
0102         } else {
0103             QObject::timerEvent(event);
0104         }
0105     }
0106     // ! get list of blur-behind regions matching a given widget
0107     QRegion blurRegion(QWidget*) const;
0108     // ! trim blur region to remove unnecessary areas (recursive)
0109     void trimBlurRegion(QWidget*, QWidget*, QRegion&) const;
0110     // ! update blur region for all pending widgets
0111     /*! a timer is used to allow some buffering of the update requests */
0112     void
0113     delayedUpdate()
0114     {
0115         if (!_timer.isActive()) {
0116             _timer.start(10, this);
0117         }
0118     }
0119     // ! update blur region for all pending widgets
0120     void
0121     update()
0122     {
0123         foreach (const WidgetPointer &widget, const_(_pendingWidgets)) {
0124             if (widget) {
0125                 update(widget.data());
0126             }
0127         }
0128         _pendingWidgets.clear();
0129     }
0130     // ! update blur regions for given widget
0131     void update(QWidget*) const;
0132     // ! clear blur regions for given widget
0133     void clear(WId) const;
0134     // ! returns true if a given widget is opaque
0135     bool
0136     isOpaque(const QWidget *widget) const
0137     {
0138         return (!widget->isWindow()) &&
0139             ((widget->autoFillBackground() &&
0140               widget->palette().color(widget->backgroundRole()).alpha() ==
0141               0xff) || widget->testAttribute(Qt::WA_OpaquePaintEvent));
0142     }
0143     // ! true if widget is a transparent window
0144     /*! some additional checks are performed to make sure stuff like plasma
0145       tooltips don't get their blur region overwritten */
0146     inline bool isTransparent(const QWidget *widget) const;
0147 private:
0148     // ! enability
0149     bool _enabled;
0150     // ! list of widgets for which blur region must be updated
0151     typedef QPointer<QWidget> WidgetPointer;
0152     typedef QHash<QWidget*, WidgetPointer> WidgetSet;
0153     WidgetSet _pendingWidgets;
0154     // ! delayed update timer
0155     QBasicTimer _timer;
0156 };
0157 bool
0158 BlurHelper::isTransparent(const QWidget *widget) const
0159 {
0160     return (widget->isWindow() &&
0161             // widgets using qgraphicsview
0162             !(widget->graphicsProxyWidget() ||
0163               widget->inherits("Plasma::Dialog")) &&
0164             // flags and special widgets
0165             (widget->testAttribute(Qt::WA_StyledBackground) ||
0166              qobject_cast<const QMenu*>(widget) ||
0167              // TODO temporary solution only
0168              widget->inherits("QComboBoxPrivateContainer") ||
0169              qobject_cast<const QDockWidget*>(widget) ||
0170              qobject_cast<const QToolBar*>(widget) ||
0171              // konsole (thought that should be handled
0172              // internally by the application
0173              widget->inherits("Konsole::MainWindow")) &&
0174             Utils::hasAlphaChannel(widget));
0175 }
0176 }
0177 
0178 #endif