| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2020 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qquickitemsmodule_p.h" |
| 41 | |
| 42 | #include "qquickitem.h" |
| 43 | #include "qquickitem_p.h" |
| 44 | #include "qquickevents_p_p.h" |
| 45 | #include "qquickrectangle_p.h" |
| 46 | #include "qquickfocusscope_p.h" |
| 47 | #include "qquicktext_p.h" |
| 48 | #include "qquicktextinput_p.h" |
| 49 | #include "qquicktextedit_p.h" |
| 50 | #include "qquicktextdocument.h" |
| 51 | #include "qquickimage_p.h" |
| 52 | #include "qquickborderimage_p.h" |
| 53 | #include "qquickscalegrid_p_p.h" |
| 54 | #include "qquickmousearea_p.h" |
| 55 | #include "qquickpincharea_p.h" |
| 56 | #include "qquickflickable_p.h" |
| 57 | #include "qquickflickable_p_p.h" |
| 58 | #if QT_CONFIG(quick_listview) |
| 59 | #include "qquicklistview_p.h" |
| 60 | #endif |
| 61 | #if QT_CONFIG(quick_gridview) |
| 62 | #include "qquickgridview_p.h" |
| 63 | #endif |
| 64 | #if QT_CONFIG(quick_pathview) |
| 65 | #include "qquickpathview_p.h" |
| 66 | #endif |
| 67 | #if QT_CONFIG(quick_tableview) |
| 68 | #include "qquicktableview_p.h" |
| 69 | #endif |
| 70 | #if QT_CONFIG(quick_viewtransitions) |
| 71 | #include "qquickitemviewtransition_p.h" |
| 72 | #endif |
| 73 | #if QT_CONFIG(quick_path) |
| 74 | #include <private/qquickpath_p.h> |
| 75 | #include <private/qquickpathinterpolator_p.h> |
| 76 | #endif |
| 77 | #if QT_CONFIG(quick_positioners) |
| 78 | #include "qquickpositioners_p.h" |
| 79 | #endif |
| 80 | #if QT_CONFIG(quick_repeater) |
| 81 | #include "qquickrepeater_p.h" |
| 82 | #endif |
| 83 | #include "qquickloader_p.h" |
| 84 | #if QT_CONFIG(quick_animatedimage) |
| 85 | #include "qquickanimatedimage_p.h" |
| 86 | #endif |
| 87 | #if QT_CONFIG(quick_flipable) |
| 88 | #include "qquickflipable_p.h" |
| 89 | #endif |
| 90 | #include "qquicktranslate_p.h" |
| 91 | #include "qquickstateoperations_p.h" |
| 92 | #include "qquickitemanimation_p.h" |
| 93 | //#include <private/qquickpincharea_p.h> |
| 94 | #if QT_CONFIG(quick_canvas) |
| 95 | #include <QtQuick/private/qquickcanvasitem_p.h> |
| 96 | #include <QtQuick/private/qquickcontext2d_p.h> |
| 97 | #endif |
| 98 | #include "qquickitemgrabresult.h" |
| 99 | #if QT_CONFIG(quick_sprite) |
| 100 | #include "qquicksprite_p.h" |
| 101 | #include "qquickspritesequence_p.h" |
| 102 | #include "qquickanimatedsprite_p.h" |
| 103 | #endif |
| 104 | #if QT_CONFIG(opengl) |
| 105 | # include "qquickopenglinfo_p.h" |
| 106 | #endif |
| 107 | #include "qquickgraphicsinfo_p.h" |
| 108 | #if QT_CONFIG(quick_shadereffect) |
| 109 | #include <QtQuick/private/qquickshadereffectsource_p.h> |
| 110 | #include "qquickshadereffect_p.h" |
| 111 | #include "qquickshadereffectmesh_p.h" |
| 112 | #endif |
| 113 | #if QT_CONFIG(quick_draganddrop) |
| 114 | #include "qquickdrag_p.h" |
| 115 | #include "qquickdroparea_p.h" |
| 116 | #endif |
| 117 | #include "qquickmultipointtoucharea_p.h" |
| 118 | #include <QtQuick/private/qquickaccessibleattached_p.h> |
| 119 | |
| 120 | #include "handlers/qquickdraghandler_p.h" |
| 121 | #include "handlers/qquickhoverhandler_p.h" |
| 122 | #include "handlers/qquickpinchhandler_p.h" |
| 123 | #include "handlers/qquickpointhandler_p.h" |
| 124 | #include "handlers/qquicktaphandler_p.h" |
| 125 | #include "handlers/qquickwheelhandler_p.h" |
| 126 | |
| 127 | QT_BEGIN_NAMESPACE |
| 128 | Q_DECLARE_LOGGING_CATEGORY(lcTransient) |
| 129 | QT_END_NAMESPACE |
| 130 | |
| 131 | static QQmlPrivate::AutoParentResult qquickitem_autoParent(QObject *obj, QObject *parent) |
| 132 | { |
| 133 | // When setting a parent (especially during dynamic object creation) in QML, |
| 134 | // also try to set up the analogous item/window relationship. |
| 135 | if (QQuickItem *parentItem = qmlobject_cast<QQuickItem *>(object: parent)) { |
| 136 | QQuickItem *item = qmlobject_cast<QQuickItem *>(object: obj); |
| 137 | if (item) { |
| 138 | // An Item has another Item |
| 139 | item->setParentItem(parentItem); |
| 140 | return QQmlPrivate::Parented; |
| 141 | } else if (parentItem->window()) { |
| 142 | QQuickWindow *win = qmlobject_cast<QQuickWindow *>(object: obj); |
| 143 | if (win) { |
| 144 | // A Window inside an Item should be transient for that item's window |
| 145 | qCDebug(lcTransient) << win << "is transient for"<< parentItem->window(); |
| 146 | win->setTransientParent(parentItem->window()); |
| 147 | return QQmlPrivate::Parented; |
| 148 | } |
| 149 | } else if (QQuickPointerHandler *handler = qmlobject_cast<QQuickPointerHandler *>(object: obj)) { |
| 150 | QQuickItemPrivate::get(item: parentItem)->addPointerHandler(h: handler); |
| 151 | handler->setParent(parent); |
| 152 | return QQmlPrivate::Parented; |
| 153 | } |
| 154 | return QQmlPrivate::IncompatibleObject; |
| 155 | } else if (QQuickWindow *parentWindow = qmlobject_cast<QQuickWindow *>(object: parent)) { |
| 156 | QQuickWindow *win = qmlobject_cast<QQuickWindow *>(object: obj); |
| 157 | if (win) { |
| 158 | // A Window inside a Window should be transient for it |
| 159 | qCDebug(lcTransient) << win << "is transient for"<< parentWindow; |
| 160 | win->setTransientParent(parentWindow); |
| 161 | return QQmlPrivate::Parented; |
| 162 | } else if (QQuickItem *item = qmlobject_cast<QQuickItem *>(object: obj)) { |
| 163 | // The parent of an Item inside a Window is actually the implicit content Item |
| 164 | item->setParentItem(parentWindow->contentItem()); |
| 165 | return QQmlPrivate::Parented; |
| 166 | } else if (QQuickPointerHandler *handler = qmlobject_cast<QQuickPointerHandler *>(object: obj)) { |
| 167 | QQuickItemPrivate::get(item: parentWindow->contentItem())->addPointerHandler(h: handler); |
| 168 | handler->setParent(parentWindow->contentItem()); |
| 169 | return QQmlPrivate::Parented; |
| 170 | } |
| 171 | return QQmlPrivate::IncompatibleObject; |
| 172 | } else if (qmlobject_cast<QQuickItem *>(object: obj)) { |
| 173 | return QQmlPrivate::IncompatibleParent; |
| 174 | } |
| 175 | return QQmlPrivate::IncompatibleObject; |
| 176 | } |
| 177 | |
| 178 | static void qt_quickitems_defineModule() |
| 179 | { |
| 180 | QQmlPrivate::RegisterAutoParent autoparent = { .version: 0, .function: &qquickitem_autoParent }; |
| 181 | QQmlPrivate::qmlregister(QQmlPrivate::AutoParentRegistration, &autoparent); |
| 182 | |
| 183 | qRegisterMetaType<QQuickAnchorLine>(typeName: "QQuickAnchorLine"); |
| 184 | qRegisterMetaType<QPointingDeviceUniqueId>(typeName: "QPointingDeviceUniqueId"); |
| 185 | qRegisterMetaType<QQuickHandlerPoint>(); |
| 186 | } |
| 187 | |
| 188 | static void initResources() |
| 189 | { |
| 190 | Q_INIT_RESOURCE(items); |
| 191 | } |
| 192 | |
| 193 | QT_BEGIN_NAMESPACE |
| 194 | |
| 195 | void QQuickItemsModule::defineModule() |
| 196 | { |
| 197 | initResources(); |
| 198 | qt_quickitems_defineModule(); |
| 199 | } |
| 200 | |
| 201 | QT_END_NAMESPACE |
| 202 |
