diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-01-02 15:41:02 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-01-17 20:40:17 +0100 |
commit | 99b19fab5a106cbc34f2733da6689eb0afbc36e5 (patch) | |
tree | 00672b0126900b501e461faa907c745dba5df43e | |
parent | 8d2227165723c76dbebb348f569a477f8e699870 (diff) |
Expose QStyleHints as Qt.styleHints
Change-Id: I0fc94e680b011963e645bdbf51110820751e53aa
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 28 | ||||
-rw-r--r-- | src/qml/qml/qqmlglobal.cpp | 8 | ||||
-rw-r--r-- | src/qml/qml/qqmlglobal_p.h | 1 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 7 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions_p.h | 1 | ||||
-rw-r--r-- | src/quick/util/qquickglobal.cpp | 8 | ||||
-rw-r--r-- | tests/auto/quick/qquickapplication/tst_qquickapplication.cpp | 14 |
7 files changed, 67 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index aececf915f..762e9880d2 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -523,6 +523,34 @@ The following functions are also on the Qt object. further details. */ +/*! + \qmlproperty object Qt::styleHints + \since 5.5 + + The \c styleHints object provides platform-specific style hints and settings. + See the QStyleHints documentation for further details. + + \note The \c styleHints object is only available when using the Qt Quick module. + + The following example uses the \c styleHints object to determine whether an + item should gain focus on mouse press or touch release: + \code + import QtQuick 2.4 + + MouseArea { + id: button + + onPressed: { + if (!Qt.styleHints.setFocusOnTouchRelease) + button.forceActiveFocus() + } + onReleased: { + if (Qt.styleHints.setFocusOnTouchRelease) + button.forceActiveFocus() + } + } + \endcode +*/ /*! \qmlmethod object Qt::include(string url, jsobject callback) diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index e100b53386..6f7582346f 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -364,6 +364,14 @@ QObject *QQmlGuiProvider::inputMethod() } #endif +QObject *QQmlGuiProvider::styleHints() +{ + QObject *o = new QObject(); + o->setObjectName(QString::fromLatin1("No styleHints available")); + QQmlEngine::setObjectOwnership(o, QQmlEngine::JavaScriptOwnership); + return o; +} + static QQmlGuiProvider *guiProvider = 0; Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *newProvider) diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index da09956530..28cea20adb 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -296,6 +296,7 @@ public: #ifndef QT_NO_IM virtual QObject *inputMethod(); #endif + virtual QObject *styleHints(); virtual QStringList fontFamilies(); virtual bool openUrlExternally(QUrl &); }; diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 19cb1edb60..6eaa020218 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -142,6 +142,7 @@ Heap::QtObject::QtObject(ExecutionEngine *v4, QQmlEngine *qmlEngine) #ifndef QT_NO_IM o->defineAccessorProperty(QStringLiteral("inputMethod"), QV4::QtObject::method_get_inputMethod, 0); #endif + o->defineAccessorProperty(QStringLiteral("styleHints"), QV4::QtObject::method_get_styleHints, 0); } @@ -1272,6 +1273,12 @@ ReturnedValue QtObject::method_get_inputMethod(CallContext *ctx) } #endif +ReturnedValue QtObject::method_get_styleHints(CallContext *ctx) +{ + QObject *o = QQml_guiProvider()->styleHints(); + return QV4::QObjectWrapper::wrap(ctx->d()->engine, o); +} + QV4::Heap::ConsoleObject::ConsoleObject(ExecutionEngine *v4) : Heap::Object(v4) diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h index a6d1821cda..ca10a86ffc 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h +++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h @@ -116,6 +116,7 @@ struct QtObject : Object #ifndef QT_NO_IM static ReturnedValue method_get_inputMethod(CallContext *ctx); #endif + static ReturnedValue method_get_styleHints(CallContext *ctx); }; struct ConsoleObject : Object diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index 146b6d73e2..b06edb844d 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -39,6 +39,7 @@ #include <QtGui/QGuiApplication> #include <QtGui/qdesktopservices.h> #include <QtGui/qfontdatabase.h> +#include <QtGui/qstylehints.h> #include <private/qv4engine_p.h> #include <private/qv4object_p.h> @@ -932,6 +933,13 @@ public: } #endif + QStyleHints *styleHints() + { + QStyleHints *sh = qGuiApp->styleHints(); + QQmlEngine::setObjectOwnership(sh, QQmlEngine::CppOwnership); + return sh; + } + QStringList fontFamilies() { QFontDatabase database; diff --git a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp index f803a63fd7..a5c7b125eb 100644 --- a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp +++ b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp @@ -37,6 +37,7 @@ #include <QtQuick/qquickitem.h> #include <QtQuick/qquickview.h> #include <QtGui/qinputmethod.h> +#include <QtGui/qstylehints.h> #include <qpa/qwindowsysteminterface.h> #include <qpa/qplatformintegration.h> #include <private/qguiapplication_p.h> @@ -52,6 +53,7 @@ private slots: void state(); void layoutDirection(); void inputMethod(); + void styleHints(); void cleanup(); private: @@ -214,6 +216,18 @@ void tst_qquickapplication::inputMethod() QCOMPARE(qvariant_cast<QObject*>(item->property("inputMethod")), qApp->inputMethod()); } +void tst_qquickapplication::styleHints() +{ + // technically not in QQuickApplication, but testing anyway here + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0; Item { property variant styleHints: Qt.styleHints }", QUrl::fromLocalFile("")); + QQuickItem *item = qobject_cast<QQuickItem *>(component.create()); + QVERIFY(item); + QQuickView view; + item->setParentItem(view.rootObject()); + + QCOMPARE(qvariant_cast<QObject*>(item->property("styleHints")), qApp->styleHints()); +} QTEST_MAIN(tst_qquickapplication) |