File indexing completed on 2024-04-21 05:25:18

0001 /*
0002  * Copyright 2021 Aditya Mehra <aix.m@outlook.com>
0003  *
0004  * Licensed under the Apache License, Version 2.0 (the "License");
0005  * you may not use this file except in compliance with the License.
0006  * You may obtain a copy of the License at
0007  *
0008  *    http://www.apache.org/licenses/LICENSE-2.0
0009  *
0010  * Unless required by applicable law or agreed to in writing, software
0011  * distributed under the License is distributed on an "AS IS" BASIS,
0012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013  * See the License for the specific language governing permissions and
0014  * limitations under the License.
0015  *
0016  */
0017 
0018 #include "fakeqeventplugin.h"
0019 #include "emulatedmouse.h"
0020 #include "fakeEvent.h"
0021 #include <QQmlContext>
0022 #include <QQmlEngine>
0023 
0024 // Create a static instance of fakeEvent that can register itself with QML as a singleton
0025 static QObject *fakeEventSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
0026 {
0027     Q_UNUSED(scriptEngine);
0028 
0029     //singleton managed internally, qml should never delete it
0030     engine->setObjectOwnership(FakeEvent::instance(), QQmlEngine::CppOwnership);
0031     return FakeEvent::instance();
0032 }
0033 
0034 void FakeQEventPlugin::registerTypes(const char *uri)
0035 {
0036     qmlRegisterType<EmulatedMouse>(uri, 1, 0, "EmulatedMouse");
0037     qmlRegisterSingletonType<FakeEvent>(uri, 1, 0, "FakeEvent", fakeEventSingletonProvider);
0038 }
0039 
0040 #include "moc_fakeqeventplugin.cpp"