summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2015-03-25 14:42:18 +0100
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-03-25 14:16:46 +0000
commit7fd1a0709bc0e7737a6f48433ab04129e43a1b57 (patch)
tree59167dfac7bd3d808171fd5b5b4da2ed208e2d7f /src
parent3ac0be60ce9ed9985e40066ba1c8612125582d35 (diff)
Add private attached property to access QQuickWindow from any item
Should really be in QQuickWindowAttached, but until the naming is settled we expose it privately in Controls. Change-Id: Id239197303bcb2e1ff1a108c78e5610bb193f0a3 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/controls/Private/private.pri3
-rw-r--r--src/controls/Private/qquickcontrolsprivate.cpp75
-rw-r--r--src/controls/Private/qquickcontrolsprivate_p.h38
-rw-r--r--src/controls/plugin.cpp4
4 files changed, 106 insertions, 14 deletions
diff --git a/src/controls/Private/private.pri b/src/controls/Private/private.pri
index 5de6881e9..420647ff4 100644
--- a/src/controls/Private/private.pri
+++ b/src/controls/Private/private.pri
@@ -21,7 +21,8 @@ SOURCES += \
$$PWD/qquickcontrolsettings.cpp \
$$PWD/qquickwheelarea.cpp \
$$PWD/qquickabstractstyle.cpp \
- $$PWD/qquicktreemodeladaptor.cpp
+ $$PWD/qquicktreemodeladaptor.cpp \
+ $$PWD/qquickcontrolsprivate.cpp
!no_desktop {
diff --git a/src/controls/Private/qquickcontrolsprivate.cpp b/src/controls/Private/qquickcontrolsprivate.cpp
new file mode 100644
index 000000000..612826687
--- /dev/null
+++ b/src/controls/Private/qquickcontrolsprivate.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickcontrolsprivate_p.h"
+#include <qquickitem.h>
+#include <qquickwindow.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickControlsPrivateAttached::QQuickControlsPrivateAttached(QObject *attachee)
+ : m_attachee(qobject_cast<QQuickItem*>(attachee))
+{
+ if (m_attachee)
+ connect(m_attachee, &QQuickItem::windowChanged, this, &QQuickControlsPrivateAttached::windowChanged);
+}
+
+QQuickWindow *QQuickControlsPrivateAttached::window() const
+{
+ return m_attachee ? m_attachee->window() : 0;
+}
+
+QObject *QQuickControlsPrivate::registerTooltipModule(QQmlEngine *engine, QJSEngine *jsEngine)
+{
+ Q_UNUSED(engine);
+ Q_UNUSED(jsEngine);
+ return new QQuickTooltip();
+}
+
+QObject *QQuickControlsPrivate::registerSettingsModule(QQmlEngine *engine, QJSEngine *jsEngine)
+{
+ Q_UNUSED(jsEngine);
+ return new QQuickControlSettings(engine);
+}
+
+QQuickControlsPrivateAttached *QQuickControlsPrivate::qmlAttachedProperties(QObject *object)
+{
+ return new QQuickControlsPrivateAttached(object);
+}
+
+QT_END_NAMESPACE
+
+
diff --git a/src/controls/Private/qquickcontrolsprivate_p.h b/src/controls/Private/qquickcontrolsprivate_p.h
index 3775f63df..335ca92be 100644
--- a/src/controls/Private/qquickcontrolsprivate_p.h
+++ b/src/controls/Private/qquickcontrolsprivate_p.h
@@ -43,26 +43,38 @@
QT_BEGIN_NAMESPACE
-class QQuickControlsPrivate {
+class QQuickWindow;
+
+class QQuickControlsPrivateAttached : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QQuickWindow* window READ window NOTIFY windowChanged)
public:
+ QQuickControlsPrivateAttached(QObject* attachee);
- inline static QObject *registerTooltipModule(QQmlEngine *engine, QJSEngine *jsEngine)
- {
- Q_UNUSED(engine);
- Q_UNUSED(jsEngine);
- return new QQuickTooltip();
- }
+ QQuickWindow *window() const;
- inline static QObject *registerSettingsModule(QQmlEngine *engine, QJSEngine *jsEngine)
- {
- Q_UNUSED(engine);
- Q_UNUSED(jsEngine);
- return new QQuickControlSettings(engine);
- }
+Q_SIGNALS:
+ void windowChanged();
+private:
+ QQuickItem* m_attachee;
+};
+
+class QQuickControlsPrivate : public QObject
+{
+ Q_OBJECT
+
+public:
+ static QObject *registerTooltipModule(QQmlEngine *engine, QJSEngine *jsEngine);
+ static QObject *registerSettingsModule(QQmlEngine *engine, QJSEngine *jsEngine);
+
+ static QQuickControlsPrivateAttached *qmlAttachedProperties(QObject *object);
};
QT_END_NAMESPACE
+QML_DECLARE_TYPEINFO(QQuickControlsPrivate, QML_HAS_ATTACHED_PROPERTIES)
+
#endif // QQUICKCONTROLSPRIVATE_P_H
diff --git a/src/controls/plugin.cpp b/src/controls/plugin.cpp
index 3fa827e7a..a402df68c 100644
--- a/src/controls/plugin.cpp
+++ b/src/controls/plugin.cpp
@@ -149,6 +149,10 @@ void QtQuickControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri
qmlRegisterType<QQuickSpinBoxValidator>(private_uri, 1, 0, "SpinBoxValidator");
qmlRegisterSingletonType<QQuickTooltip>(private_uri, 1, 0, "Tooltip", QQuickControlsPrivate::registerTooltipModule);
qmlRegisterSingletonType<QQuickControlSettings>(private_uri, 1, 0, "Settings", QQuickControlsPrivate::registerSettingsModule);
+
+ qmlRegisterUncreatableType<QQuickControlsPrivate>(private_uri, 1, 0, "Controls", QLatin1String("Controls is an abstract type."));
+ qmlRegisterType<QQuickControlsPrivateAttached>();
+
qmlRegisterType<QQuickTreeModelAdaptor>(private_uri, 1, 0, "TreeModelAdaptor");
qmlRegisterType<QQuickMenu>(private_uri, 1, 0, "MenuPrivate");