summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
diff options
context:
space:
mode:
authorChristoph Schleifenbaum <christoph.schleifenbaum@kdab.com>2013-11-14 13:56:19 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-05 09:18:28 +0200
commit958a4c9087e03502d0173735df4611a7f96a0463 (patch)
tree6c63734f9199d85b68314c1354f9138bb85a455c /src/widgets/kernel
parent7df8b1ada4b23acedda5724b492c26a8e322648b (diff)
QApp: Method to check for native style usage.
Adds QApplicationPrivate::usesNativeStyle to check whether the QApplication is using the native platform style. This can be needed internally to decided whether to let the platform plugins do stuff or do it interally, style dependent. E.g. letting the platform plugin popup a QMenu vs. letting the style draw one. Change-Id: Ibb5e11a4d9d1d2824685ff146786a9354ceef43c Reviewed-by: BogDan Vatra <bogdan@kde.org>
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r--src/widgets/kernel/qapplication.cpp21
-rw-r--r--src/widgets/kernel/qapplication_p.h7
2 files changed, 28 insertions, 0 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index b4c4ffe7c7..0b983e7a9d 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -146,6 +146,20 @@ static void clearSystemPalette()
QApplicationPrivate::sys_pal = 0;
}
+static QByteArray get_style_class_name()
+{
+ QScopedPointer<QStyle> s(QStyleFactory::create(QApplicationPrivate::desktopStyleKey()));
+ if (!s.isNull())
+ return s->metaObject()->className();
+ return QByteArray();
+}
+
+static QByteArray nativeStyleClassName()
+{
+ static QByteArray name = get_style_class_name();
+ return name;
+}
+
#ifdef Q_OS_WINCE
int QApplicationPrivate::autoMaximizeThreshold = -1;
bool QApplicationPrivate::autoSipEnabled = false;
@@ -372,6 +386,8 @@ void qt_init_tooltip_palette();
void qt_cleanup();
QStyle *QApplicationPrivate::app_style = 0; // default application style
+bool QApplicationPrivate::overrides_native_style = false; // whether native QApplication style is
+ // overridden, i.e. not native
QString QApplicationPrivate::styleOverride; // style override
#ifndef QT_NO_STYLE_STYLESHEET
@@ -997,6 +1013,8 @@ QStyle *QApplication::style()
Q_ASSERT(!"No styles available!");
return 0;
}
+ QApplicationPrivate::overrides_native_style =
+ app_style->objectName() != QApplicationPrivate::desktopStyleKey();
}
// take ownership of the style
QApplicationPrivate::app_style->setParent(qApp);
@@ -1061,6 +1079,9 @@ void QApplication::setStyle(QStyle *style)
QStyle *old = QApplicationPrivate::app_style; // save
+ QApplicationPrivate::overrides_native_style =
+ nativeStyleClassName() == QByteArray(style->metaObject()->className());
+
#ifndef QT_NO_STYLE_STYLESHEET
if (!QApplicationPrivate::styleSheet.isEmpty() && !qobject_cast<QStyleSheetStyle *>(style)) {
// we have a stylesheet already and a new style is being set
diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h
index 0284a613d4..d5efb62dda 100644
--- a/src/widgets/kernel/qapplication_p.h
+++ b/src/widgets/kernel/qapplication_p.h
@@ -150,6 +150,12 @@ public:
bool canQuit();
#endif
+ //style
+ static bool usesNativeStyle()
+ {
+ return !overrides_native_style;
+ }
+
bool notify_helper(QObject *receiver, QEvent * e);
void construct(
@@ -184,6 +190,7 @@ public:
static QSize app_strut;
static QWidgetList *popupWidgets;
static QStyle *app_style;
+ static bool overrides_native_style;
static int app_cspec;
static QPalette *sys_pal;
static QPalette *set_pal;