File indexing completed on 2024-05-05 13:13:23
0001 /* 0002 * Copyright 2018 Camilo Higuita <milo.h@aol.com> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Library General Public License as 0006 * published by the Free Software Foundation; either version 2, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details 0013 * 0014 * You should have received a copy of the GNU Library General Public 0015 * License along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "mauikit.h" 0021 #include <QEvent> 0022 #include <QCoreApplication> 0023 0024 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0025 #include "appview.h" 0026 #include "handy.h" 0027 #include "mauiapp.h" 0028 #include "mauilist.h" 0029 #include "mauimodel.h" 0030 #include "notify.h" 0031 #include "style.h" 0032 #include "tabview.h" 0033 #include "controls.h" 0034 0035 #ifdef Q_OS_ANDROID 0036 #include "platforms/android/mauiandroid.h" 0037 #elif (defined Q_OS_LINUX || defined Q_OS_FREEBSD) 0038 #include "platforms/linux/mauilinux.h" 0039 #endif 0040 0041 #include "shadowhelper/windowshadow.h" 0042 #include "blurhelper/windowblur.h" 0043 0044 #include "platform.h" 0045 0046 #include "utils/basictheme_p.h" 0047 #include "utils/platformtheme.h" 0048 #include "utils/colorutils.h" 0049 #include "utils/imagecolors.h" 0050 #include "utils/wheelhandler.h" 0051 #include "utils/icon.h" 0052 #include "utils/fontpickermodel.h" 0053 #endif 0054 0055 #include <QDebug> 0056 #include <QQmlContext> 0057 0058 // we can't do this in the plugin object directly, as that can live in a different thread 0059 // and event filters are only allowed in the same thread as the filtered object 0060 class LanguageChangeEventFilter : public QObject 0061 { 0062 Q_OBJECT 0063 public: 0064 bool eventFilter(QObject *receiver, QEvent *event) override 0065 { 0066 if (event->type() == QEvent::LanguageChange && receiver == QCoreApplication::instance()) { 0067 Q_EMIT languageChangeEvent(); 0068 } 0069 return QObject::eventFilter(receiver, event); 0070 } 0071 0072 Q_SIGNALS: 0073 void languageChangeEvent(); 0074 }; 0075 0076 MauiKit::MauiKit(QObject *parent) : QQmlExtensionPlugin(parent) 0077 { 0078 auto filter = new LanguageChangeEventFilter; 0079 filter->moveToThread(QCoreApplication::instance()->thread()); 0080 QCoreApplication::instance()->installEventFilter(filter); 0081 connect(filter, &LanguageChangeEventFilter::languageChangeEvent, this, &MauiKit::languageChangeEvent); 0082 } 0083 0084 QUrl MauiKit::componentUrl(const QString &fileName) const 0085 { 0086 return QUrl(resolveFileUrl(fileName)); 0087 } 0088 0089 void MauiKit::initializeEngine(QQmlEngine* engine, const char* uri) 0090 { 0091 Q_UNUSED(uri); 0092 connect(this, &MauiKit::languageChangeEvent, engine, &QQmlEngine::retranslate); 0093 } 0094 0095 void MauiKit::registerTypes(const char *uri) 0096 { 0097 qDebug() << "REGISTER MAUIKIT TYPES <<<<<<<<<<<<<<<<<<<<<<"; 0098 #if defined(Q_OS_ANDROID) 0099 QResource::registerResource(QStringLiteral("assets:/android_rcc_bundle.rcc")); 0100 #endif 0101 0102 Q_ASSERT(QLatin1String(uri) == QLatin1String("org.mauikit.controls")); 0103 0104 // @uri org.mauikit.controls 0105 qmlRegisterType(componentUrl(QStringLiteral("ToolBar.qml")), uri, 1, 0, "ToolBar"); 0106 qmlRegisterType(componentUrl(QStringLiteral("ApplicationWindow.qml")), uri, 1, 0, "ApplicationWindow"); 0107 qmlRegisterType(componentUrl(QStringLiteral("Page.qml")), uri, 1, 0, "Page"); 0108 qmlRegisterType(componentUrl(QStringLiteral("PageLayout.qml")), uri, 1, 0, "PageLayout"); 0109 // qmlRegisterType(componentUrl(QStringLiteral("ShareDialog.qml")), uri, 1, 0, "ShareDialog"); 0110 qmlRegisterType(componentUrl(QStringLiteral("PieButton.qml")), uri, 1, 0, "PieButton"); 0111 qmlRegisterType(componentUrl(QStringLiteral("SideBarView.qml")), uri, 1, 0, "SideBarView"); 0112 qmlRegisterType(componentUrl(QStringLiteral("Holder.qml")), uri, 1, 0, "Holder"); 0113 0114 qmlRegisterType(componentUrl(QStringLiteral("ListDelegate.qml")), uri, 1, 0, "ListDelegate"); 0115 qmlRegisterType(componentUrl(QStringLiteral("ListBrowserDelegate.qml")), uri, 1, 0, "ListBrowserDelegate"); 0116 qmlRegisterType(componentUrl(QStringLiteral("SwipeItemDelegate.qml")), uri, 1, 0, "SwipeItemDelegate"); 0117 qmlRegisterType(componentUrl(QStringLiteral("SwipeBrowserDelegate.qml")), uri, 1, 0, "SwipeBrowserDelegate"); 0118 qmlRegisterType(componentUrl(QStringLiteral("ItemDelegate.qml")), uri, 1, 0, "ItemDelegate"); 0119 qmlRegisterType(componentUrl(QStringLiteral("GridBrowserDelegate.qml")), uri, 1, 0, "GridBrowserDelegate"); 0120 qmlRegisterType(componentUrl(QStringLiteral("SelectionBar.qml")), uri, 1, 0, "SelectionBar"); 0121 qmlRegisterType(componentUrl(QStringLiteral("LabelDelegate.qml")), uri, 1, 0, "LabelDelegate"); 0122 qmlRegisterType(componentUrl(QStringLiteral("InputDialog.qml")), uri, 1, 0, "InputDialog"); 0123 qmlRegisterType(componentUrl(QStringLiteral("PopupPage.qml")), uri, 1, 0, "PopupPage"); 0124 qmlRegisterType(componentUrl(QStringLiteral("Badge.qml")), uri, 1, 0, "Badge"); 0125 qmlRegisterType(componentUrl(QStringLiteral("ListBrowser.qml")), uri, 1, 0, "ListBrowser"); 0126 qmlRegisterType(componentUrl(QStringLiteral("GridBrowser.qml")), uri, 1, 0, "GridBrowser"); 0127 qmlRegisterType(componentUrl(QStringLiteral("TabBar.qml")), uri, 1, 0, "TabBar"); 0128 qmlRegisterType(componentUrl(QStringLiteral("TabButton.qml")), uri, 1, 0, "TabButton"); 0129 qmlRegisterType(componentUrl(QStringLiteral("ToolActions.qml")), uri, 1, 0, "ToolActions"); 0130 qmlRegisterType(componentUrl(QStringLiteral("ToolButtonMenu.qml")), uri, 1, 0, "ToolButtonMenu"); 0131 qmlRegisterType(componentUrl(QStringLiteral("ListItemTemplate.qml")), uri, 1, 0, "ListItemTemplate"); 0132 qmlRegisterType(componentUrl(QStringLiteral("GridItemTemplate.qml")), uri, 1, 0, "GridItemTemplate"); 0133 0134 qmlRegisterType(componentUrl(QStringLiteral("FloatingButton.qml")), uri, 1, 0, "FloatingButton"); 0135 0136 // //Kirigami aliases to be replaced later on 0137 qmlRegisterType(componentUrl(QStringLiteral("Icon.qml")), uri, 1, 0, "Icon"); 0138 qmlRegisterType(componentUrl(QStringLiteral("ShadowedRectangle.qml")), uri, 1, 0, "ShadowedRectangle"); //to be removed later 0139 0140 // /** Shapes **/ 0141 qmlRegisterType(componentUrl(QStringLiteral("private/Rectangle.qml")), uri, 1, 0, "Rectangle"); 0142 qmlRegisterType(componentUrl(QStringLiteral("private/CheckBoxItem.qml")), uri, 1, 0, "CheckBoxItem"); 0143 0144 // /** 1.1 **/ 0145 qmlRegisterType(componentUrl(QStringLiteral("AppViews.qml")), uri, 1, 1, "AppViews"); 0146 qmlRegisterType(componentUrl(QStringLiteral("AppViewLoader.qml")), uri, 1, 1, "AppViewLoader"); 0147 qmlRegisterType(componentUrl(QStringLiteral("AltBrowser.qml")), uri, 1, 1, "AltBrowser"); 0148 qmlRegisterType(componentUrl(QStringLiteral("SettingsDialog.qml")), uri, 1, 1, "SettingsDialog"); 0149 qmlRegisterType(componentUrl(QStringLiteral("SectionGroup.qml")), uri, 1, 1, "SectionGroup"); 0150 qmlRegisterType(componentUrl(QStringLiteral("ImageViewer.qml")), uri, 1, 1, "ImageViewer"); 0151 qmlRegisterType(componentUrl(QStringLiteral("AnimatedImageViewer.qml")), uri, 1, 1, "AnimatedImageViewer"); 0152 0153 // /** 1.2 **/ 0154 qmlRegisterType(componentUrl(QStringLiteral("SectionItem.qml")), uri, 1, 2, "SectionItem"); 0155 qmlRegisterType(componentUrl(QStringLiteral("FlexSectionItem.qml")), uri, 1, 2, "FlexSectionItem"); 0156 qmlRegisterType(componentUrl(QStringLiteral("Separator.qml")), uri, 1, 2, "Separator"); 0157 0158 // /** 1.3 **/ 0159 qmlRegisterType(componentUrl(QStringLiteral("GalleryRollItem.qml")), uri, 1, 3, "GalleryRollItem"); 0160 qmlRegisterType(componentUrl(QStringLiteral("CollageItem.qml")), uri, 1, 3, "CollageItem"); 0161 qmlRegisterType(componentUrl(QStringLiteral("FileListingDialog.qml")), uri, 1, 3, "FileListingDialog"); 0162 qmlRegisterType(componentUrl(QStringLiteral("SectionHeader.qml")), uri, 1, 3, "SectionHeader"); 0163 qmlRegisterType(componentUrl(QStringLiteral("IconItem.qml")), uri, 1, 3, "IconItem"); 0164 qmlRegisterType(componentUrl(QStringLiteral("DoodleCanvas.qml")), uri, 1, 3, "DoodleCanvas"); 0165 qmlRegisterType(componentUrl(QStringLiteral("Doodle.qml")), uri, 1, 3, "Doodle"); 0166 qmlRegisterType(componentUrl(QStringLiteral("FlexListItem.qml")), uri, 1, 3, "FlexListItem"); 0167 qmlRegisterType(componentUrl(QStringLiteral("Chip.qml")), uri, 1, 3, "Chip"); 0168 qmlRegisterType(componentUrl(QStringLiteral("ContextualMenu.qml")), uri, 1, 3, "ContextualMenu"); 0169 qmlRegisterType(componentUrl(QStringLiteral("FontsComboBox.qml")), uri, 1, 3, "FontsComboBox"); 0170 qmlRegisterType(componentUrl(QStringLiteral("TabView.qml")), uri, 1, 3, "TabView"); 0171 qmlRegisterType(componentUrl(QStringLiteral("TabViewButton.qml")), uri, 1, 3, "TabViewButton"); 0172 qmlRegisterType(componentUrl(QStringLiteral("CloseButton.qml")), uri, 1, 3, "CloseButton"); 0173 qmlRegisterType(componentUrl(QStringLiteral("ColorsRow.qml")), uri, 1, 3, "ColorsRow"); 0174 qmlRegisterType(componentUrl(QStringLiteral("SplitView.qml")), uri, 1, 3, "SplitView"); 0175 qmlRegisterType(componentUrl(QStringLiteral("SplitViewItem.qml")), uri, 1, 3, "SplitViewItem"); 0176 qmlRegisterType(componentUrl(QStringLiteral("ProgressIndicator.qml")), uri, 1, 3, "ProgressIndicator"); 0177 0178 qmlRegisterType(componentUrl(QStringLiteral("MenuItemActionRow.qml")), uri, 1, 3, "MenuItemActionRow"); 0179 qmlRegisterType(componentUrl(QStringLiteral("GalleryRollTemplate.qml")), uri, 1, 3, "GalleryRollTemplate"); 0180 qmlRegisterType(componentUrl(QStringLiteral("ScrollColumn.qml")), uri, 1, 3, "ScrollColumn"); 0181 qmlRegisterType(componentUrl(QStringLiteral("TabViewItem.qml")), uri, 1, 3, "TabViewItem"); 0182 qmlRegisterType(componentUrl(QStringLiteral("SettingsPage.qml")), uri, 1, 3, "SettingsPage"); 0183 qmlRegisterType(componentUrl(QStringLiteral("IconLabel.qml")), uri, 1, 3, "IconLabel"); 0184 qmlRegisterType(componentUrl(QStringLiteral("InfoDialog.qml")), uri, 1, 3, "InfoDialog"); 0185 qmlRegisterType(componentUrl(QStringLiteral("FontPicker.qml")), uri, 1, 3, "FontPicker"); 0186 qmlRegisterType(componentUrl(QStringLiteral("FontPickerDialog.qml")), uri, 1, 3, "FontPickerDialog"); 0187 qmlRegisterType(componentUrl(QStringLiteral("TextFieldPopup.qml")), uri, 1, 3, "TextFieldPopup"); 0188 qmlRegisterType(componentUrl(QStringLiteral("DialogWindow.qml")), uri, 1, 3, "DialogWindow"); 0189 0190 // //backwars compatible 0191 qmlRegisterType(componentUrl(QStringLiteral("SearchField.qml")), uri, 1, 0, "SearchField"); 0192 qmlRegisterType(componentUrl(QStringLiteral("PasswordField.qml")), uri, 1, 0, "PasswordField"); 0193 qmlRegisterType(componentUrl(QStringLiteral("private/ColorTransition.qml")), uri, 1, 0, "ColorTransition"); 0194 qmlRegisterType(componentUrl(QStringLiteral("private/EdgeShadow.qml")), uri, 1, 0, "EdgeShadow"); 0195 0196 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) //For MauiKit4 these types are registered inline using macros 0197 /// NON UI CONTROLS 0198 qmlRegisterUncreatableType<AppView>(uri, 1, 1, "AppView", "Cannot be created AppView"); 0199 qmlRegisterUncreatableType<TabViewInfo>(uri, 1, 3, "TabViewInfo", "Cannot be created TabView"); 0200 qmlRegisterUncreatableType<Controls>(uri, 1, 3, "Controls", "Attached properties for different purposes."); 0201 0202 qmlRegisterSingletonType<Platform>(uri, 1, 2, "Platform", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0203 Q_UNUSED(scriptEngine) 0204 auto platform = Platform::instance(); 0205 engine->setObjectOwnership(platform, QQmlEngine::CppOwnership); 0206 return platform; 0207 }); 0208 0209 qmlRegisterUncreatableType<Maui::PlatformTheme>(uri, 1, 0, "Theme", QStringLiteral("Cannot create objects of type Theme, use it as an attached property")); 0210 qmlRegisterSingletonType<ColorUtils>(uri, 1, 3, "ColorUtils", [](QQmlEngine *, QJSEngine *) -> QObject* 0211 { 0212 return new ColorUtils; 0213 }); 0214 0215 qmlRegisterType<ImageColors>(uri, 1, 3, "ImageColors"); 0216 qmlRegisterType<WheelHandler>(uri, 1, 3, "WheelHandler"); 0217 qmlRegisterType<Icon>(uri, 1, 0, "PrivateIcon"); 0218 0219 qmlRegisterType<FontPickerModel>(uri, 1, 3, "FontPickerModel"); 0220 0221 qmlRegisterType<WindowShadow>(uri, 1, 0, "WindowShadow"); 0222 qmlRegisterType<WindowBlur>(uri, 1, 0, "WindowBlur"); 0223 0224 /** DATA MODELING TEMPLATED INTERFACES **/ 0225 qmlRegisterAnonymousType<MauiList>(uri, 1); 0226 qmlRegisterType<MauiModel>(uri, 1, 0, "BaseModel"); 0227 0228 /** MAUI APPLICATION SPECIFIC PROPS **/ 0229 /** HELPERS **/ 0230 qmlRegisterAnonymousType<CSDControls>(uri, 1); 0231 qmlRegisterType<CSDButton>(uri, 1, 3, "CSDButton"); 0232 qmlRegisterType<Notify>(uri, 1, 3, "Notify"); 0233 qmlRegisterType<NotifyAction>(uri, 1, 3, "NotifyAction"); 0234 0235 qmlRegisterUncreatableType<Style>(uri, 1, 0, "Style", "Cannot be created Style"); 0236 qmlRegisterUncreatableType<MauiApp>(uri, 1, 0, "App", "Cannot be created App"); 0237 qmlRegisterSingletonType<Handy>(uri, 1, 2, "Handy", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0238 Q_UNUSED(scriptEngine) 0239 auto handy = Handy::instance(); 0240 engine->setObjectOwnership(handy, QQmlEngine::CppOwnership); 0241 return handy; 0242 }); 0243 0244 #ifdef Q_OS_ANDROID 0245 qmlRegisterSingletonType<MAUIAndroid>(uri, 1, 0, "Android", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { 0246 Q_UNUSED(engine) 0247 Q_UNUSED(scriptEngine) 0248 return new MAUIAndroid; 0249 }); 0250 #elif (defined Q_OS_LINUX || defined Q_OS_FREEBSD) 0251 qmlRegisterUncreatableType<MAUIKDE>(uri, 1, 0, "KDE", "Cannot be created KDE"); 0252 #elif defined Q_OS_WIN32 0253 // here window platform integration interfaces 0254 #elif defined Q_OS_MACOS 0255 #endif 0256 0257 // /** MAUI PLUGIN SUPPORT **/ 0258 //#ifdef SUPPORT_PLUGINS 0259 // qmlRegisterType(componentUrl(QStringLiteral("AppViewsPlugin.qml")), uri, 1, 2, "AppViewsPlugin"); 0260 // qmlRegisterType(componentUrl(QStringLiteral("PagePlugin.qml")), uri, 1, 2, "PagePlugin"); 0261 // qmlRegisterType(componentUrl(QStringLiteral("PluginManager.qml")), uri, 1, 2, "PluginManager"); 0262 // qmlRegisterType(componentUrl(QStringLiteral("PluginsInfo.qml")), uri, 1, 2, "PluginsInfo"); 0263 //#endif 0264 #endif 0265 0266 // /** Experimental **/ 0267 #ifdef Q_OS_WIN32 0268 qmlRegisterType(componentUrl(QStringLiteral("private/WindowControlsWindows.qml")), uri, 1, 1, "WindowControls"); 0269 #elif defined Q_OS_MAC 0270 qmlRegisterType(componentUrl(QStringLiteral("private/WindowControlsMac.qml")), uri, 1, 1, "WindowControls"); 0271 #elif defined Q_OS_ANDROID 0272 qmlRegisterType(componentUrl(QStringLiteral("private/WindowControlsWindows.qml")), uri, 1, 1, "WindowControls"); 0273 #elif (defined Q_OS_LINUX || defined Q_OS_FREEBSD) && !defined Q_OS_ANDROID 0274 qmlRegisterType(componentUrl(QStringLiteral("CSDControls.qml")), uri, 1, 1, "CSDControls"); 0275 qmlRegisterType(componentUrl(QStringLiteral("private/WindowControlsLinux.qml")), uri, 1, 1, "WindowControls"); 0276 #endif 0277 0278 // qmlProtectModule(uri, 3); 0279 } 0280 0281 #include "mauikit.moc" 0282 #include "moc_mauikit.cpp"