File indexing completed on 2024-05-12 17:21:07

0001 /*
0002  * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 #include <QCommandLineOption>
0007 #include <QCommandLineParser>
0008 #include <QIcon>
0009 #include <QObject>
0010 #include <QQmlApplicationEngine>
0011 #include <QQmlContext>
0012 #include <QQuickStyle>
0013 
0014 #ifdef Q_OS_ANDROID
0015 #include <QGuiApplication>
0016 #else
0017 #include <QApplication>
0018 #endif
0019 
0020 #include <KAboutData>
0021 #include <KLocalizedContext>
0022 #include <KLocalizedString>
0023 
0024 #include "historymanager.h"
0025 #include "mathengine.h"
0026 #include "inputmanager.h"
0027 #include "unitmodel.h"
0028 #include "version.h"
0029 
0030 #ifdef Q_OS_ANDROID
0031 Q_DECL_EXPORT
0032 #endif
0033 int main(int argc, char *argv[])
0034 {
0035     QCommandLineParser parser;
0036 
0037     QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0038 #ifdef Q_OS_ANDROID
0039     QGuiApplication app(argc, argv);
0040     QQuickStyle::setStyle(QStringLiteral("org.kde.breeze"));
0041 #else
0042     QApplication app(argc, argv);
0043     // set default style and icon theme
0044     QIcon::setFallbackThemeName(QStringLiteral("breeze"));
0045     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0046         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0047     }
0048     // if using org.kde.desktop, ensure we use kde style if possible
0049     if (qEnvironmentVariableIsEmpty("QT_QPA_PLATFORMTHEME")) {
0050         qputenv("QT_QPA_PLATFORMTHEME", "kde");
0051     }
0052 #endif
0053     QQmlApplicationEngine engine;
0054     KLocalizedString::setApplicationDomain("kalk");
0055     parser.addVersionOption();
0056     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0057 
0058     engine.rootContext()->setContextProperty(QStringLiteral("historyManager"), HistoryManager::inst());
0059     engine.rootContext()->setContextProperty(QStringLiteral("inputManager"), InputManager::inst());
0060     engine.rootContext()->setContextProperty(QStringLiteral("unitModel"), UnitModel::inst());
0061     
0062     KAboutData aboutData(QStringLiteral("kalk"), 
0063                          i18n("Calculator"), 
0064                          QStringLiteral(KALK_VERSION_STRING), 
0065                          i18n("Calculator for Plasma"), 
0066                          KAboutLicense::GPL, 
0067                          i18n("© 2020-2022 KDE Community"));
0068     aboutData.setBugAddress("https://bugs.kde.org/describecomponents.cgi?product=kalk");
0069     KAboutData::setApplicationData(aboutData);
0070 
0071     parser.process(app);
0072 
0073     qmlRegisterSingletonType("org.kde.kalk", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
0074         return engine->toScriptValue(KAboutData::applicationData());
0075     });
0076 #ifdef QT_DEBUG
0077     engine.rootContext()->setContextProperty(QStringLiteral("debug"), true);
0078 #else
0079     engine.rootContext()->setContextProperty(QStringLiteral("debug"), false);
0080 #endif
0081     // load main ui
0082     engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
0083 
0084     // required for X11
0085     app.setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.kalk")));
0086     KNumber::setDefaultFloatPrecision(1000);
0087     return app.exec();
0088 }