File indexing completed on 2024-05-05 10:10:09
0001 /***************************************************************************** 0002 * Copyright 2007 - 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 #include "qtcurve_plugin.h" 0024 #include "qtcurve.h" 0025 #include "config.h" 0026 0027 #include <qtcurve-utils/qtprops.h> 0028 #include <qtcurve-utils/x11base.h> 0029 0030 #ifdef Q_WS_X11 0031 # include <QX11Info> 0032 #endif 0033 0034 #include <QTypeInfo> 0035 #include <QFileInfo> 0036 #include <QDir> 0037 0038 #include <mutex> 0039 0040 namespace QtCurve { 0041 0042 #ifdef QTC_QT4_STYLE_SUPPORT 0043 static void 0044 getStyles(const QString &dir, const char *sub, QSet<QString> &styles) 0045 { 0046 QDir d(dir + sub); 0047 0048 if (d.exists()) { 0049 QStringList filters; 0050 0051 filters << QString(THEME_PREFIX "*" THEME_SUFFIX); 0052 d.setNameFilters(filters); 0053 0054 foreach (const QString &str, d.entryList()) { 0055 QString style(str.left(str.lastIndexOf(THEME_SUFFIX))); 0056 if (!styles.contains(style)) { 0057 styles.insert(style); 0058 } 0059 } 0060 } 0061 } 0062 0063 static void 0064 getStyles(const QString &dir, QSet<QString> &styles) 0065 { 0066 getStyles(dir, THEME_DIR, styles); 0067 getStyles(dir, THEME_DIR4, styles); 0068 } 0069 #endif 0070 0071 QStringList 0072 StylePlugin::keys() const 0073 { 0074 QSet<QString> styles; 0075 styles.insert("QtCurve"); 0076 0077 #ifdef QTC_QT4_STYLE_SUPPORT 0078 getStyles(Utils::kdeHome(), styles); 0079 getStyles(KDE_PREFIX(4), styles); 0080 #endif 0081 return styles.toList(); 0082 } 0083 0084 QStyle* 0085 StylePlugin::create(const QString &key) 0086 { 0087 // init needs to be called before Style is created 0088 init(); 0089 if (key.toLower() == "qtcurve") { 0090 return new Style; 0091 } 0092 #ifdef QTC_QT4_STYLE_SUPPORT 0093 if (key.indexOf(THEME_PREFIX) == 0) { 0094 return new Style(key); 0095 } 0096 #endif 0097 return 0; 0098 } 0099 0100 __attribute__((hot)) static bool 0101 qtcEventCallback(void **cbdata) 0102 { 0103 QObject *receiver = (QObject*)cbdata[0]; 0104 QTC_RET_IF_FAIL(receiver, false); 0105 QEvent *event = (QEvent*)cbdata[1]; 0106 if (qtcUnlikely(event->type() == QEvent::DynamicPropertyChange)) { 0107 QDynamicPropertyChangeEvent *prop_event = 0108 static_cast<QDynamicPropertyChangeEvent*>(event); 0109 // eat the property change events from ourselves 0110 if (prop_event->propertyName() == QTC_PROP_NAME) { 0111 return true; 0112 } 0113 } 0114 QWidget *widget = qtcToWidget(receiver); 0115 if (!widget) 0116 return false; 0117 if (qtcUnlikely(!widget->testAttribute(Qt::WA_WState_Polished) && 0118 !qtcGetWid(widget))) { 0119 if (Style *style = getStyle(widget)) { 0120 style->prePolish(widget); 0121 } 0122 } else if (event->type() == QEvent::UpdateRequest) { 0123 QtcQWidgetProps(widget)->opacity = 100; 0124 } 0125 return false; 0126 } 0127 0128 void 0129 StylePlugin::init() 0130 { 0131 static std::once_flag ref_flag; 0132 std::call_once(ref_flag, [] { 0133 QInternal::registerCallback(QInternal::EventNotifyCallback, 0134 qtcEventCallback); 0135 #ifdef Q_WS_X11 0136 qtcX11InitXlib(QX11Info::display()); 0137 #endif 0138 }); 0139 } 0140 0141 Q_EXPORT_PLUGIN2(Style, StylePlugin) 0142 0143 }