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>
This commit is contained in:
Christoph Schleifenbaum 2013-11-14 13:56:19 +01:00 committed by The Qt Project
parent 7df8b1ada4
commit 958a4c9087
2 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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;