2017-04-27 20:27:59 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-05-03 11:04:51 -07:00
|
|
|
/* qt-gui.cpp */
|
|
|
|
/* Qt UI implementation */
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "core/dive.h"
|
|
|
|
#include "core/display.h"
|
|
|
|
#include "core/helpers.h"
|
2011-09-20 12:40:34 -07:00
|
|
|
|
2013-05-03 11:04:51 -07:00
|
|
|
#include <QApplication>
|
2013-05-10 09:24:06 -07:00
|
|
|
#include <QDesktopWidget>
|
2013-07-13 14:42:26 +02:00
|
|
|
#include <QNetworkProxy>
|
2013-10-08 22:25:02 -07:00
|
|
|
#include <QLibraryInfo>
|
2015-05-27 15:36:39 +03:00
|
|
|
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "core/qt-gui.h"
|
2013-04-02 19:49:17 +03:00
|
|
|
|
2015-07-12 17:34:52 -07:00
|
|
|
#include <QQuickWindow>
|
2016-03-08 19:35:22 -08:00
|
|
|
#include <QScreen>
|
2015-07-12 17:34:52 -07:00
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
#include <QQmlContext>
|
2015-07-22 19:09:49 +03:00
|
|
|
#include <QSortFilterProxyModel>
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "mobile-widgets/qmlmanager.h"
|
2015-07-12 17:34:52 -07:00
|
|
|
#include "qt-models/divelistmodel.h"
|
2016-01-07 21:36:27 -08:00
|
|
|
#include "qt-models/gpslistmodel.h"
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "mobile-widgets/qmlprofile.h"
|
2017-05-12 18:17:23 +02:00
|
|
|
#include "core/downloadfromdcthread.h"
|
2017-10-06 07:51:30 -07:00
|
|
|
#include "core/connectionlistmodel.h"
|
2017-05-26 17:53:25 +02:00
|
|
|
#include "qt-models/diveimportedmodel.h"
|
2017-06-05 18:16:12 +02:00
|
|
|
#include "qt-models/messagehandlermodel.h"
|
2015-06-04 13:36:36 +03:00
|
|
|
|
2016-06-22 18:17:25 +02:00
|
|
|
#include "mobile-widgets/qml/kirigami/src/kirigamiplugin.h"
|
|
|
|
|
2015-09-03 14:49:59 -03:00
|
|
|
QObject *qqWindowObject = NULL;
|
2013-04-25 15:28:31 -07:00
|
|
|
|
2017-10-11 19:38:24 +02:00
|
|
|
void set_non_bt_addresses() {
|
|
|
|
#if defined(Q_OS_ANDROID)
|
|
|
|
connectionListModel.addAddress("FTDI");
|
|
|
|
#elif defined(Q_OS_LINUX) // since this is in the else, it does NOT include Android
|
|
|
|
connectionListModel.addAddress("/dev/ttyS0");
|
|
|
|
connectionListModel.addAddress("/dev/ttyS1");
|
|
|
|
connectionListModel.addAddress("/dev/ttyS2");
|
|
|
|
connectionListModel.addAddress("/dev/ttyS3");
|
|
|
|
// this makes debugging so much easier - use the simulator
|
|
|
|
connectionListModel.addAddress("/tmp/ttyS1");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-06-16 06:52:06 -07:00
|
|
|
void init_ui()
|
2014-03-19 18:23:43 +02:00
|
|
|
{
|
2015-06-16 06:52:06 -07:00
|
|
|
init_qt_late();
|
2011-09-20 12:40:34 -07:00
|
|
|
}
|
|
|
|
|
2015-06-16 06:52:06 -07:00
|
|
|
void run_ui()
|
2011-09-20 12:40:34 -07:00
|
|
|
{
|
2015-06-04 13:36:36 +03:00
|
|
|
qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
|
2015-07-17 19:10:32 +03:00
|
|
|
qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
|
2016-06-22 18:17:25 +02:00
|
|
|
|
2017-05-26 16:40:50 +02:00
|
|
|
qmlRegisterType<DCDeviceData>("org.subsurfacedivelog.mobile", 1, 0, "DCDeviceData");
|
|
|
|
qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread");
|
2017-05-26 17:53:25 +02:00
|
|
|
qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel");
|
2017-05-26 16:40:50 +02:00
|
|
|
|
2015-05-27 15:36:39 +03:00
|
|
|
QQmlApplicationEngine engine;
|
2016-06-22 18:17:25 +02:00
|
|
|
KirigamiPlugin::getInstance().registerTypes();
|
2017-09-23 15:05:08 -07:00
|
|
|
#if defined(__APPLE__) && !defined(Q_OS_IOS)
|
2015-11-30 14:17:04 -08:00
|
|
|
// when running the QML UI on a Mac the deployment of the QML Components seems
|
|
|
|
// to fail and the search path for the components is rather odd - simply the
|
|
|
|
// same directory the executable was started from <bundle>/Contents/MacOS/
|
|
|
|
// To work around this we need to manually copy the components at install time
|
|
|
|
// to Contents/Frameworks/qml and make sure that we add the correct import path
|
|
|
|
QStringList importPathList = engine.importPathList();
|
|
|
|
Q_FOREACH(QString importPath, importPathList) {
|
|
|
|
if (importPath.contains("MacOS"))
|
|
|
|
engine.addImportPath(importPath.replace("MacOS", "Frameworks"));
|
|
|
|
}
|
|
|
|
qDebug() << "QML import path" << engine.importPathList();
|
|
|
|
#endif
|
2015-11-29 17:41:47 +01:00
|
|
|
engine.addImportPath("qrc://imports");
|
2015-06-09 22:20:44 +03:00
|
|
|
DiveListModel diveListModel;
|
2016-01-28 18:28:44 -08:00
|
|
|
DiveListSortModel *sortModel = new DiveListSortModel(0);
|
2015-07-22 19:09:49 +03:00
|
|
|
sortModel->setSourceModel(&diveListModel);
|
|
|
|
sortModel->setDynamicSortFilter(true);
|
|
|
|
sortModel->setSortRole(DiveListModel::DiveDateRole);
|
|
|
|
sortModel->sort(0, Qt::DescendingOrder);
|
2016-01-07 21:36:27 -08:00
|
|
|
GpsListModel gpsListModel;
|
|
|
|
QSortFilterProxyModel *gpsSortModel = new QSortFilterProxyModel(0);
|
|
|
|
gpsSortModel->setSourceModel(&gpsListModel);
|
|
|
|
gpsSortModel->setDynamicSortFilter(true);
|
2016-03-11 07:26:42 -08:00
|
|
|
gpsSortModel->setSortRole(GpsListModel::GpsWhenRole);
|
2016-01-07 21:36:27 -08:00
|
|
|
gpsSortModel->sort(0, Qt::DescendingOrder);
|
2015-06-09 22:20:44 +03:00
|
|
|
QQmlContext *ctxt = engine.rootContext();
|
2015-07-22 19:09:49 +03:00
|
|
|
ctxt->setContextProperty("diveModel", sortModel);
|
2016-01-07 21:36:27 -08:00
|
|
|
ctxt->setContextProperty("gpsModel", gpsSortModel);
|
2017-05-12 18:17:23 +02:00
|
|
|
ctxt->setContextProperty("vendorList", vendorList);
|
2017-10-11 19:38:24 +02:00
|
|
|
set_non_bt_addresses();
|
|
|
|
|
2017-07-16 21:50:28 -07:00
|
|
|
ctxt->setContextProperty("connectionListModel", &connectionListModel);
|
2017-06-05 18:16:12 +02:00
|
|
|
ctxt->setContextProperty("logModel", MessageHandlerModel::self());
|
2017-05-12 18:17:23 +02:00
|
|
|
|
2015-05-27 15:36:39 +03:00
|
|
|
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
|
2015-07-12 17:39:13 -07:00
|
|
|
qqWindowObject = engine.rootObjects().value(0);
|
|
|
|
if (!qqWindowObject) {
|
|
|
|
fprintf(stderr, "can't create window object\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
QQuickWindow *qml_window = qobject_cast<QQuickWindow *>(qqWindowObject);
|
2015-07-09 20:34:04 -07:00
|
|
|
qml_window->setIcon(QIcon(":/subsurface-mobile-icon"));
|
2016-01-01 09:34:32 -08:00
|
|
|
qqWindowObject->setProperty("messageText", QVariant("Subsurface-mobile startup"));
|
2016-03-08 19:35:22 -08:00
|
|
|
qDebug() << "qqwindow devicePixelRatio" << qml_window->devicePixelRatio() << qml_window->screen()->devicePixelRatio();
|
|
|
|
QScreen *screen = qml_window->screen();
|
|
|
|
QObject::connect(qml_window, &QQuickWindow::screenChanged, QMLManager::instance(), &QMLManager::screenChanged);
|
2016-04-14 05:48:51 -07:00
|
|
|
QMLManager *manager = QMLManager::instance();
|
2017-04-03 17:29:06 -07:00
|
|
|
manager->setDevicePixelRatio(qml_window->devicePixelRatio(), qml_window->screen());
|
2016-04-14 05:48:51 -07:00
|
|
|
manager->dlSortModel = sortModel;
|
|
|
|
manager->screenChanged(screen);
|
2016-03-08 19:35:22 -08:00
|
|
|
qDebug() << "qqwindow screen has ldpi/pdpi" << screen->logicalDotsPerInch() << screen->physicalDotsPerInch();
|
2016-04-05 16:48:47 -07:00
|
|
|
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
|
2015-07-12 10:42:23 -07:00
|
|
|
qml_window->setHeight(1200);
|
|
|
|
qml_window->setWidth(800);
|
|
|
|
#endif
|
2015-05-27 15:36:39 +03:00
|
|
|
qml_window->show();
|
2015-06-16 06:52:06 -07:00
|
|
|
qApp->exec();
|
2011-09-20 12:40:34 -07:00
|
|
|
}
|
|
|
|
|
2015-06-16 06:52:06 -07:00
|
|
|
void exit_ui()
|
2012-05-02 10:03:48 -07:00
|
|
|
{
|
2015-06-16 06:52:06 -07:00
|
|
|
delete qApp;
|
2014-05-12 14:58:15 -03:00
|
|
|
free((void *)existing_filename);
|
2012-05-02 10:03:48 -07:00
|
|
|
}
|
|
|
|
|
2013-05-10 09:24:06 -07:00
|
|
|
double get_screen_dpi()
|
|
|
|
{
|
2015-06-16 06:52:06 -07:00
|
|
|
QDesktopWidget *mydesk = qApp->desktop();
|
2013-05-10 09:24:06 -07:00
|
|
|
return mydesk->physicalDpiX();
|
|
|
|
}
|
2015-11-05 10:05:22 -08:00
|
|
|
|
|
|
|
bool haveFilesOnCommandLine()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|