source: subsurface/subsurface-mobile-helper.cpp

Last change on this file was 59ed9ea3, checked in by Dirk Hohndel <dirk@…>, 3 weeks ago

Add SPDX header to top level files

Signed-off-by: Dirk Hohndel <dirk@…>

  • Property mode set to 100644
File size: 3.7 KB
Line 
1// SPDX-License-Identifier: GPL-2.0
2/* qt-gui.cpp */
3/* Qt UI implementation */
4#include "core/dive.h"
5#include "core/display.h"
6#include "core/helpers.h"
7
8#include <QApplication>
9#include <QDesktopWidget>
10#include <QNetworkProxy>
11#include <QLibraryInfo>
12
13#include "core/qt-gui.h"
14
15#include <QQuickWindow>
16#include <QScreen>
17#include <QQmlApplicationEngine>
18#include <QQmlContext>
19#include <QSortFilterProxyModel>
20#include "mobile-widgets/qmlmanager.h"
21#include "qt-models/divelistmodel.h"
22#include "qt-models/gpslistmodel.h"
23#include "mobile-widgets/qmlprofile.h"
24
25#include "mobile-widgets/qml/kirigami/src/kirigamiplugin.h"
26
27QObject *qqWindowObject = NULL;
28
29void init_ui()
30{
31        init_qt_late();
32}
33
34void run_ui()
35{
36        qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
37        qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
38
39        QQmlApplicationEngine engine;
40        KirigamiPlugin::getInstance().registerTypes();
41#if __APPLE__
42        // when running the QML UI on a Mac the deployment of the QML Components seems
43        // to fail and the search path for the components is rather odd - simply the
44        // same directory the executable was started from <bundle>/Contents/MacOS/
45        // To work around this we need to manually copy the components at install time
46        // to Contents/Frameworks/qml and make sure that we add the correct import path
47        QStringList importPathList = engine.importPathList();
48        Q_FOREACH(QString importPath, importPathList) {
49                if (importPath.contains("MacOS"))
50                        engine.addImportPath(importPath.replace("MacOS", "Frameworks"));
51        }
52        qDebug() << "QML import path" << engine.importPathList();
53#endif
54        engine.addImportPath("qrc://imports");
55        DiveListModel diveListModel;
56        DiveListSortModel *sortModel = new DiveListSortModel(0);
57        sortModel->setSourceModel(&diveListModel);
58        sortModel->setDynamicSortFilter(true);
59        sortModel->setSortRole(DiveListModel::DiveDateRole);
60        sortModel->sort(0, Qt::DescendingOrder);
61        GpsListModel gpsListModel;
62        QSortFilterProxyModel *gpsSortModel = new QSortFilterProxyModel(0);
63        gpsSortModel->setSourceModel(&gpsListModel);
64        gpsSortModel->setDynamicSortFilter(true);
65        gpsSortModel->setSortRole(GpsListModel::GpsWhenRole);
66        gpsSortModel->sort(0, Qt::DescendingOrder);
67        QQmlContext *ctxt = engine.rootContext();
68        ctxt->setContextProperty("diveModel", sortModel);
69        ctxt->setContextProperty("gpsModel", gpsSortModel);
70        engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
71        qqWindowObject = engine.rootObjects().value(0);
72        if (!qqWindowObject) {
73                fprintf(stderr, "can't create window object\n");
74                exit(1);
75        }
76        QQuickWindow *qml_window = qobject_cast<QQuickWindow *>(qqWindowObject);
77        qml_window->setIcon(QIcon(":/subsurface-mobile-icon"));
78        qqWindowObject->setProperty("messageText", QVariant("Subsurface-mobile startup"));
79        qDebug() << "qqwindow devicePixelRatio" << qml_window->devicePixelRatio() << qml_window->screen()->devicePixelRatio();
80        QScreen *screen = qml_window->screen();
81        QObject::connect(qml_window, &QQuickWindow::screenChanged, QMLManager::instance(), &QMLManager::screenChanged);
82        QMLManager *manager = QMLManager::instance();
83        manager->setDevicePixelRatio(qml_window->devicePixelRatio(), qml_window->screen());
84        manager->dlSortModel = sortModel;
85        manager->screenChanged(screen);
86        qDebug() << "qqwindow screen has ldpi/pdpi" << screen->logicalDotsPerInch() << screen->physicalDotsPerInch();
87#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
88        qml_window->setHeight(1200);
89        qml_window->setWidth(800);
90#endif
91        qml_window->show();
92        qApp->exec();
93}
94
95void exit_ui()
96{
97        delete qApp;
98        free((void *)existing_filename);
99}
100
101double get_screen_dpi()
102{
103        QDesktopWidget *mydesk = qApp->desktop();
104        return mydesk->physicalDpiX();
105}
106
107bool haveFilesOnCommandLine()
108{
109        return false;
110}
Note: See TracBrowser for help on using the repository browser.