Warning, file /system/qtcurve/qt4/style/shadowhelper.cpp 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 ////////////////////////////////////////////////////////////////////////////// 0024 // shadowhelper.h 0025 // handle shadow _pixmaps passed to window manager via X property 0026 // ------------------- 0027 // 0028 // Copyright (c) 2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org> 0029 // 0030 // Permission is hereby granted, free of charge, to any person obtaining a copy 0031 // of this software and associated documentation files (the "Software"), to 0032 // deal in the Software without restriction, including without limitation the 0033 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 0034 // sell copies of the Software, and to permit persons to whom the Software is 0035 // furnished to do so, subject to the following conditions: 0036 // 0037 // The above copyright notice and this permission notice shall be included in 0038 // all copies or substantial portions of the Software. 0039 // 0040 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0041 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0042 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0043 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0044 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 0045 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 0046 // IN THE SOFTWARE. 0047 ////////////////////////////////////////////////////////////////////////////// 0048 0049 #include "shadowhelper.h" 0050 #include "utils.h" 0051 0052 #include <QDockWidget> 0053 #include <QMenu> 0054 #include <QPainter> 0055 #include <QToolBar> 0056 #include <QEvent> 0057 0058 #include <qtcurve-utils/x11shadow.h> 0059 #include <qtcurve-utils/qtprops.h> 0060 0061 namespace QtCurve { 0062 const char *const ShadowHelper::netWMForceShadowPropertyName = 0063 "_KDE_NET_WM_FORCE_SHADOW"; 0064 const char *const ShadowHelper::netWMSkipShadowPropertyName = 0065 "_KDE_NET_WM_SKIP_SHADOW"; 0066 0067 bool 0068 ShadowHelper::registerWidget(QWidget *widget, bool force) 0069 { 0070 QtcQWidgetProps props(widget); 0071 // make sure widget is not already registered 0072 if (props->shadowRegistered) 0073 return false; 0074 // check if widget qualifies 0075 if (!(force || acceptWidget(widget))) 0076 return false; 0077 props->shadowRegistered = true; 0078 0079 // WinIdChange Event 0080 widget->installEventFilter(this); 0081 installX11Shadows(widget); 0082 return true; 0083 } 0084 0085 void 0086 ShadowHelper::unregisterWidget(QWidget *widget) 0087 { 0088 QtcQWidgetProps props(widget); 0089 if (props->shadowRegistered) { 0090 uninstallX11Shadows(widget); 0091 props->shadowRegistered = false; 0092 } 0093 } 0094 0095 bool 0096 ShadowHelper::eventFilter(QObject *object, QEvent *event) 0097 { 0098 if (event->type() == QEvent::WinIdChange) 0099 installX11Shadows(static_cast<QWidget*>(object)); 0100 return false; 0101 } 0102 0103 bool 0104 ShadowHelper::acceptWidget(QWidget *widget) const 0105 { 0106 if (widget->property(netWMSkipShadowPropertyName).toBool()) 0107 return false; 0108 if (widget->property(netWMForceShadowPropertyName).toBool()) 0109 return true; 0110 0111 // menus 0112 if (qobject_cast<QMenu*>(widget)) 0113 return true; 0114 0115 // combobox dropdown lists 0116 if (widget->inherits("QComboBoxPrivateContainer")) 0117 return true; 0118 0119 // tooltips 0120 if ((widget->windowType() == Qt::ToolTip || 0121 widget->inherits("QTipLabel")) && !widget->inherits("Plasma::ToolTip")) 0122 return true; 0123 0124 // detached widgets 0125 if (qobject_cast<QToolBar*>(widget) || qobject_cast<QDockWidget*>(widget)) 0126 return true; 0127 0128 // Fix Lancelot main menu shadow. Somehow they sets the override the 0129 // shadow of the main menu to nothing instead of the plasma one. 0130 // Maybe I should submit a patch for lancelot later instead. 0131 if (widget->inherits("LancelotWindow")) 0132 return true; 0133 0134 // reject 0135 return false; 0136 } 0137 0138 bool 0139 ShadowHelper::installX11Shadows(QWidget *widget) 0140 { 0141 // DO NOT condition compile on QTC_ENABLE_X11. 0142 // There's no direct linkage on X11 and the following code will just do 0143 // nothing if X11 is not enabled (either at compile time or at run time). 0144 QTC_RET_IF_FAIL(qtcX11Enabled(), false); 0145 if (WId wid = qtcGetWid(widget)) { 0146 if (widget->windowType() == Qt::ToolTip && 0147 widget->inherits("QBalloonTip")) { 0148 bool atTop = true; 0149 int margin = qtcGetBalloonMargin(widget, &atTop); 0150 int margins[4] = {0, 0, 0, 0}; 0151 // KWin's shadows margin order is top, right, bottom, left.. 0152 margins[atTop ? 0 : 2] = margin; 0153 qtcX11ShadowInstall(wid, margins); 0154 } else { 0155 qtcX11ShadowInstall(wid); 0156 } 0157 return true; 0158 } 0159 return false; 0160 } 0161 0162 void 0163 ShadowHelper::uninstallX11Shadows(QWidget *widget) const 0164 { 0165 // DO NOT condition compile on QTC_ENABLE_X11. 0166 // There's no direct linkage on X11 and the following code will just do 0167 // nothing if X11 is not enabled (either at compile time or at run time). 0168 QTC_RET_IF_FAIL(qtcX11Enabled()); 0169 if (WId wid = qtcGetWid(widget)) { 0170 qtcX11ShadowUninstall(wid); 0171 } 0172 } 0173 }