Warning, file /system/qtcurve/qt4/style/prepolish.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 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0003  *                                                                           *
0004  *   This program is free software; you can redistribute it and/or modify    *
0005  *   it under the terms of the GNU Lesser General Public License as          *
0006  *   published by the Free Software Foundation; either version 2.1 of the    *
0007  *   License, or (at your option) version 3, or any later version accepted   *
0008  *   by the membership of KDE e.V. (or its successor approved by the         *
0009  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0010  *   Section 6 of version 3 of the license.                                  *
0011  *                                                                           *
0012  *   This program is distributed in the hope that it will be useful,         *
0013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0015  *   Lesser General Public License for more details.                         *
0016  *                                                                           *
0017  *   You should have received a copy of the GNU Lesser General Public        *
0018  *   License along with this library. If not,                                *
0019  *   see <http://www.gnu.org/licenses/>.                                     *
0020  *****************************************************************************/
0021 
0022 #include "config.h"
0023 #include <qtcurve-utils/qtprops.h>
0024 
0025 #include "qtcurve_p.h"
0026 #include "argbhelper.h"
0027 
0028 #include <QMenu>
0029 
0030 namespace QtCurve {
0031 
0032 __attribute__((hot)) void
0033 Style::prePolish(QWidget *widget) const
0034 {
0035     if (!widget || QtcX11Info::creatingDummy)
0036         return;
0037 
0038     QtcQWidgetProps props(widget);
0039     // Don't use XCreateSimpleWindow
0040     fixVisual(widget);
0041     // HACK:
0042     // Modify X11Info of toplevel widgets before they create native windows.
0043     // This way we won't interfere with widgets that set this property
0044     // themselves, e.g. plasma, kscreenlock.
0045     // We do this on windows that are typically shown right after being
0046     // created before entering the main loop and therefore do not have a
0047     // chance to be polished before creating window id. In this way, we can
0048     // avoid recreating native window which breaks a lot of applications.
0049     // This way should work for all applications except when the application
0050     // relies on a native RGB window since the children of a RGBA window in
0051     // Qt are usually also RGBA. The only example of such application I have
0052     // found so far is kaffeine. See workaround bellow. (NOTE: gl widget works
0053     // because it is treated differently in Qt) (NOTE2: gl widget will not work
0054     // straightforwardly when reparenting to a 32bit window due to a bug in
0055     // Qt4, which causes a 24bit x11info and 32bit gl window to be created
0056     // The fixVisual() above should work around it, too lazy to
0057     // report upstream..... :-P).
0058 
0059     // TODO:
0060     //     use all information to check if a widget should be transparent.
0061     //     Maybe we can also do sth to their parents' and/or children as well
0062     if (!widget->testAttribute(Qt::WA_WState_Polished) &&
0063         !(widget->windowFlags() & Qt::MSWindowsOwnDC) &&
0064         !qtcGetWid(widget) && !props->prePolished) {
0065         // Skip MSWindowsOwnDC since it is set for QGLWidget and not likely to
0066         // be used in other cases.
0067 
0068         // Fix for kaffeine. Kaffeine needs a RGB window for the XV extension.
0069         // Setting parent to nullptr forces a native RGB window to be created
0070         // for MediaWidget so that its children will also have RGB visual.
0071         // Kaffeine later sets the parent again (when adding the to layout)
0072         // after the native RGB children has already been created and in this
0073         // case, Qt does not create recreate the children window. This seems to
0074         // be the only way in Qt4 to have a RGB non-OpenGL window in a RGBA
0075         // window.
0076         // TODO: maybe we can hack around parent x11info
0077         if (opts.bgndOpacity != 100 && widget->inherits("MediaWidget")) {
0078             widget->setAttribute(Qt::WA_DontCreateNativeAncestors);
0079             widget->setAttribute(Qt::WA_NativeWindow);
0080             if (!qtcGetWid(widget)) {
0081                 props->prePolished = true;
0082                 // Kaffeine set parent back after children window has been
0083                 // created.
0084                 widget->setParent(nullptr);
0085                 widget->createWinId();
0086             }
0087             return;
0088         }
0089         // the result of qobject_cast may change if we are called in
0090         // constructor (which is usually the case we want here) so we only
0091         // set the prePolished property if we have done something.
0092         if ((opts.bgndOpacity != 100 && (qtcIsWindow(widget) ||
0093                                          qtcIsToolTip(widget))) ||
0094             (opts.dlgOpacity != 100 && qtcIsDialog(widget)) ||
0095             (opts.menuBgndOpacity != 100 &&
0096              (qobject_cast<QMenu*>(widget) ||
0097               widget->inherits("QComboBoxPrivateContainer")))) {
0098             props->prePolished = true;
0099             addAlphaChannel(widget);
0100             // Set this for better efficiency for now
0101             widget->setAutoFillBackground(false);
0102         }
0103     }
0104 }
0105 
0106 }