1 /*****************************************************************************
2 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU Lesser General Public License as *
6 * published by the Free Software Foundation; either version 2.1 of the *
7 * License, or (at your option) version 3, or any later version accepted *
8 * by the membership of KDE e.V. (or its successor approved by the *
9 * membership of KDE e.V.), which shall act as a proxy defined in *
10 * Section 6 of version 3 of the license. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15 * Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with this library. If not, *
19 * see <http://www.gnu.org/licenses/>. *
20 *****************************************************************************/
21
22 #include "config.h"
23 #include <qtcurve-utils/qtprops.h>
24
25 #include "qtcurve_p.h"
26 #include "argbhelper.h"
27 #include <QMenu>
28
29 namespace QtCurve {
30
31 __attribute__((hot)) void
prePolish(QWidget * widget) const32 Style::prePolish(QWidget *widget) const
33 {
34 if (!widget)
35 return;
36 QtcQWidgetProps props(widget);
37 // HACK:
38 // Request for RGBA format on toplevel widgets before they
39 // create native windows. These windows are typically shown after being
40 // created before entering the main loop and therefore do not have a
41 // chance to be polished before creating window id. (NOTE: somehow the popup
42 // menu on mdi sub window in QtDesigner has the same problem).
43 // TODO:
44 // Use all information to check if a widget should be transparent.
45 // Need to figure out how Qt5's xcb backend deal with RGB native window
46 // as a child of a RGBA window. However, since Qt5 will not recreate
47 // native window, this is probably easier to deal with than Qt4.
48 // (After we create a RGB window, Qt5 will not override it).
49 if (!(widget->windowFlags() & Qt::MSWindowsOwnDC) &&
50 !qtcGetWid(widget) && !props->prePolishing) {
51 // Skip MSWindowsOwnDC since it is set for QGLWidget and not likely to
52 // be used in other cases.
53 if ((opts.bgndOpacity != 100 && (qtcIsWindow(widget) ||
54 qtcIsToolTip(widget))) ||
55 (opts.dlgOpacity != 100 && qtcIsDialog(widget)) ||
56 (opts.menuBgndOpacity != 100 &&
57 (qobject_cast<QMenu*>(widget) ||
58 widget->inherits("QComboBoxPrivateContainer")))) {
59 props->prePolishing = true;
60 addAlphaChannel(widget);
61 // QWidgetPrivate::updateIsTranslucent sets the format back
62 // is Qt::WA_TranslucentBackground is not set. So we need to do
63 // this repeatedly
64 props->prePolishing = false;
65 }
66 }
67 }
68 }
69