File indexing completed on 2024-05-19 16:50:19
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 #ifndef __QTC_UTILS_QT_PROPS_H__ 0023 #define __QTC_UTILS_QT_PROPS_H__ 0024 0025 #include "qtutils.h" 0026 #include <QSharedPointer> 0027 #include <QVariant> 0028 #include <QMdiSubWindow> 0029 0030 namespace QtCurve { 0031 0032 struct _QtcQWidgetProps { 0033 _QtcQWidgetProps(): 0034 opacity(100), 0035 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 0036 prePolishing(false), 0037 #else 0038 prePolished(false), 0039 prePolishStarted(false), 0040 #endif 0041 shadowRegistered(false), 0042 noEtch(false) 0043 { 0044 } 0045 int opacity; 0046 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 0047 bool prePolishing: 1; 0048 #else 0049 bool prePolished: 1; 0050 bool prePolishStarted: 1; 0051 #endif 0052 bool shadowRegistered: 1; 0053 // OK, Etching looks cr*p on plasma widgets, and khtml... 0054 // CPD:TODO WebKit? 0055 bool noEtch: 1; 0056 }; 0057 0058 #define QTC_PROP_NAME "_q__QTCURVE_WIDGET_PROPERTIES__" 0059 0060 class QtcQWidgetProps { 0061 typedef QSharedPointer<_QtcQWidgetProps> prop_type; 0062 inline prop_type 0063 getProps() const 0064 { 0065 // use _q_ to mimic qt internal properties and suppress QtDesigner 0066 // warning about unsupported properties. 0067 QVariant val(m_w->property(QTC_PROP_NAME)); 0068 if (!val.isValid()) { 0069 val = QVariant::fromValue(QSharedPointer<_QtcQWidgetProps>( 0070 new _QtcQWidgetProps)); 0071 const_cast<QWidget*>(m_w)->setProperty(QTC_PROP_NAME, val); 0072 } 0073 return val.value<prop_type>(); 0074 } 0075 public: 0076 QtcQWidgetProps(const QWidget *widget): m_w(widget), m_p(0) {} 0077 inline _QtcQWidgetProps* 0078 operator->() const 0079 { 0080 if (!m_p && m_w) { 0081 m_p = getProps(); 0082 } 0083 return m_p.data(); 0084 } 0085 private: 0086 const QWidget *m_w; 0087 mutable prop_type m_p; 0088 }; 0089 0090 static inline int 0091 qtcGetOpacity(const QWidget *widget) 0092 { 0093 for (const QWidget *w = widget;w;w = w->parentWidget()) { 0094 QtcQWidgetProps props(w); 0095 if (qobject_cast<const QMdiSubWindow*>(w)) { 0096 // don't use opacity on QMdiSubWindow menu for now, as it will 0097 // draw through the background as well. 0098 return 100; 0099 } 0100 if (props->opacity < 100) { 0101 return props->opacity; 0102 } 0103 if (w->isWindow()) { 0104 break; 0105 } 0106 } 0107 return 100; 0108 } 0109 0110 } 0111 0112 Q_DECLARE_METATYPE(QSharedPointer<QtCurve::_QtcQWidgetProps>) 0113 0114 #endif