aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols2/qquickstyle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quickcontrols2/qquickstyle.cpp')
-rw-r--r--src/quickcontrols2/qquickstyle.cpp67
1 files changed, 51 insertions, 16 deletions
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp
index b4901db3..e1cf4bfe 100644
--- a/src/quickcontrols2/qquickstyle.cpp
+++ b/src/quickcontrols2/qquickstyle.cpp
@@ -43,6 +43,7 @@
#include <QtCore/qsettings.h>
#include <QtCore/qfileselector.h>
#include <QtCore/qlibraryinfo.h>
+#include <QtCore/qloggingcategory.h>
#include <QtCore/qmetaobject.h>
#include <QtGui/qcolor.h>
#include <QtGui/qfont.h>
@@ -57,6 +58,8 @@
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(lcQtQuickControlsStyle, "qt.quick.controls.style")
+
/*!
\class QQuickStyle
\brief The QQuickStyle class allows configuring the application style.
@@ -64,7 +67,7 @@ QT_BEGIN_NAMESPACE
\since 5.7
QQuickStyle provides API for querying and configuring the application
- \l {Styling Qt Quick Controls 2}{styles} of Qt Quick Controls 2.
+ \l {Styling Qt Quick Controls}{styles} of Qt Quick Controls.
\code
#include <QGuiApplication>
@@ -86,7 +89,7 @@ QT_BEGIN_NAMESPACE
\endcode
\note The style must be configured \b before loading QML that imports
- Qt Quick Controls 2. It is not possible to change the style after the QML
+ Qt Quick Controls. It is not possible to change the style after the QML
types have been registered.
The style can also be specified as a path to a custom style, such as
@@ -102,7 +105,7 @@ QT_BEGIN_NAMESPACE
QQuickStyle::setFallbackStyle("Material");
\endcode
- \sa {Styling Qt Quick Controls 2}
+ \sa {Styling Qt Quick Controls}
*/
static QStringList envPathList(const QByteArray &var)
@@ -110,7 +113,7 @@ static QStringList envPathList(const QByteArray &var)
QStringList paths;
if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty(var))) {
const QByteArray value = qgetenv(var);
- paths += QString::fromLocal8Bit(value).split(QDir::listSeparator(), QString::SkipEmptyParts);
+ paths += QString::fromLocal8Bit(value).split(QDir::listSeparator(), Qt::SkipEmptyParts);
}
return paths;
}
@@ -119,8 +122,14 @@ static QStringList defaultImportPathList()
{
QStringList importPaths;
importPaths.reserve(3);
-#ifndef QT_STATIC
+#ifdef Q_OS_ANDROID
+ // androiddeployqt puts the QML files inside a resource file and they are not
+ // showing up in the Qml2ImportsPath as a result
+ importPaths += QStringLiteral(":/android_rcc_bundle/qml");
+#else
+# ifndef QT_STATIC
importPaths += QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath);
+# endif
#endif
importPaths += envPathList("QML2_IMPORT_PATH");
importPaths += QStringLiteral(":/qt-project.org/imports");
@@ -182,6 +191,8 @@ struct QQuickStyleSpec
void resolve(const QUrl &baseUrl = QUrl())
{
+ qCDebug(lcQtQuickControlsStyle) << "resolving style with baseUrl" << baseUrl;
+
if (style.isEmpty())
style = QGuiApplicationPrivate::styleOverride;
if (style.isEmpty())
@@ -234,6 +245,15 @@ struct QQuickStyleSpec
}
resolved = true;
}
+
+ qCDebug(lcQtQuickControlsStyle).nospace() << "done resolving:"
+ << "\n custom=" << custom
+ << "\n resolved=" << resolved
+ << "\n style=" << style
+ << "\n fallbackStyle=" << fallbackStyle
+ << "\n fallbackMethod=" << fallbackMethod
+ << "\n configFilePath=" << configFilePath
+ << "\n customStylePaths=" << customStylePaths;
}
void reset()
@@ -260,12 +280,19 @@ struct QQuickStyleSpec
return configFilePath;
}
+ // Is this a custom style defined by the user and not "built-in" style?
bool custom;
+ // Did we manage to find a valid style path?
bool resolved;
+ // The full path to the style.
QString style;
+ // The built-in style to use if the requested style cannot be found.
QString fallbackStyle;
+ // A description of the way in which fallbackStyle was set, used in e.g. warning messages shown to the user.
QByteArray fallbackMethod;
+ // The path to the qtquickcontrols2.conf file.
QString configFilePath;
+ // An extra list of directories where we search for available styles before any other directories.
QStringList customStylePaths;
};
@@ -341,7 +368,7 @@ QStringList QQuickStylePrivate::stylePaths(bool resolve)
} else {
// Fast/simpler path for systems where something other than : is used as
// the list separator (such as ';').
- const QStringList customPaths = value.split(listSeparator, QString::SkipEmptyParts);
+ const QStringList customPaths = value.split(listSeparator, Qt::SkipEmptyParts);
paths += customPaths;
}
}
@@ -379,7 +406,13 @@ void QQuickStylePrivate::init(const QUrl &baseUrl)
spec->resolve(baseUrl);
if (!spec->fallbackStyle.isEmpty()) {
- QString fallbackStyle = spec->findStyle(QQmlFile::urlToLocalFileOrQrc(baseUrl), spec->fallbackStyle);
+ QString fallbackStyle;
+ const QStringList stylePaths = QQuickStylePrivate::stylePaths();
+ for (const QString &path : stylePaths) {
+ fallbackStyle = spec->findStyle(path, spec->fallbackStyle);
+ if (!fallbackStyle.isEmpty())
+ break;
+ }
if (fallbackStyle.isEmpty()) {
if (spec->fallbackStyle.compare(QStringLiteral("Default")) != 0) {
qWarning() << "ERROR: unable to locate fallback style" << spec->fallbackStyle;
@@ -495,7 +528,7 @@ static bool qt_is_dark_system_theme()
{
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
if (const QPalette *systemPalette = theme->palette(QPlatformTheme::SystemPalette)) {
- const QColor textColor = systemPalette->color(QPalette::WindowText);
+ const QColor &textColor = systemPalette->color(QPalette::WindowText);
return textColor.red() > 128 && textColor.blue() > 128 && textColor.green() > 128;
}
}
@@ -536,14 +569,16 @@ QString QQuickStyle::path()
/*!
Sets the application style to \a style.
- \note The style must be configured \b before loading QML that imports Qt Quick Controls 2.
+ \note The style must be configured \b before loading QML that imports Qt Quick Controls.
It is not possible to change the style after the QML types have been registered.
- \sa setFallbackStyle(), {Using Styles in Qt Quick Controls 2}
+ \sa setFallbackStyle(), {Using Styles in Qt Quick Controls}
*/
void QQuickStyle::setStyle(const QString &style)
{
- if (QQmlMetaType::isModule(QStringLiteral("QtQuick.Controls"), 2, 0)) {
+ qCDebug(lcQtQuickControlsStyle) << "setStyle called with" << style;
+
+ if (QQmlMetaType::isModule(QStringLiteral("QtQuick.Controls"), QTypeRevision::fromVersion(2, 0))) {
qWarning() << "ERROR: QQuickStyle::setStyle() must be called before loading QML that imports Qt Quick Controls 2.";
return;
}
@@ -555,19 +590,19 @@ void QQuickStyle::setStyle(const QString &style)
\since 5.8
Sets the application fallback style to \a style.
- \note The fallback style must be the name of one of the built-in Qt Quick Controls 2 styles, e.g. "Material".
+ \note The fallback style must be the name of one of the built-in Qt Quick Controls styles, e.g. "Material".
- \note The style must be configured \b before loading QML that imports Qt Quick Controls 2.
+ \note The style must be configured \b before loading QML that imports Qt Quick Controls.
It is not possible to change the style after the QML types have been registered.
The fallback style can be also specified by setting the \c QT_QUICK_CONTROLS_FALLBACK_STYLE
- \l {Supported Environment Variables in Qt Quick Controls 2}{environment variable}.
+ \l {Supported Environment Variables in Qt Quick Controls}{environment variable}.
- \sa setStyle(), {Using Styles in Qt Quick Controls 2}
+ \sa setStyle(), {Using Styles in Qt Quick Controls}
*/
void QQuickStyle::setFallbackStyle(const QString &style)
{
- if (QQmlMetaType::isModule(QStringLiteral("QtQuick.Controls"), 2, 0)) {
+ if (QQmlMetaType::isModule(QStringLiteral("QtQuick.Controls"), QTypeRevision::fromVersion(2, 0))) {
qWarning() << "ERROR: QQuickStyle::setFallbackStyle() must be called before loading QML that imports Qt Quick Controls 2.";
return;
}