2013-05-03 18:04:51 +00:00
|
|
|
/* qt-gui.cpp */
|
|
|
|
/* Qt UI implementation */
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/dive.h"
|
|
|
|
#include "core/display.h"
|
|
|
|
#include "core/helpers.h"
|
2011-09-20 19:40:34 +00:00
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
#include <QApplication>
|
2013-05-10 16:24:06 +00:00
|
|
|
#include <QDesktopWidget>
|
2013-07-13 12:42:26 +00:00
|
|
|
#include <QNetworkProxy>
|
2013-10-09 05:25:02 +00:00
|
|
|
#include <QLibraryInfo>
|
2015-05-27 12:36:39 +00:00
|
|
|
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/qt-gui.h"
|
2013-04-02 16:49:17 +00:00
|
|
|
|
2015-07-13 00:34:52 +00:00
|
|
|
#include <QQuickWindow>
|
2016-03-09 03:35:22 +00:00
|
|
|
#include <QScreen>
|
2015-07-13 00:34:52 +00:00
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
#include <QQmlContext>
|
2015-07-22 16:09:49 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "mobile-widgets/qmlmanager.h"
|
2015-07-13 00:34:52 +00:00
|
|
|
#include "qt-models/divelistmodel.h"
|
2016-01-08 05:36:27 +00:00
|
|
|
#include "qt-models/gpslistmodel.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "mobile-widgets/qmlprofile.h"
|
2015-06-04 10:36:36 +00:00
|
|
|
|
2016-06-22 16:17:25 +00:00
|
|
|
#include "mobile-widgets/qml/kirigami/src/kirigamiplugin.h"
|
|
|
|
|
2015-09-03 17:49:59 +00:00
|
|
|
QObject *qqWindowObject = NULL;
|
2013-04-25 22:28:31 +00:00
|
|
|
|
2015-06-16 13:52:06 +00:00
|
|
|
void init_ui()
|
2014-03-19 16:23:43 +00:00
|
|
|
{
|
2015-06-16 13:52:06 +00:00
|
|
|
init_qt_late();
|
2011-09-20 19:40:34 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 13:52:06 +00:00
|
|
|
void run_ui()
|
2011-09-20 19:40:34 +00:00
|
|
|
{
|
2015-06-04 10:36:36 +00:00
|
|
|
qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
|
2015-07-17 16:10:32 +00:00
|
|
|
qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
|
2016-06-22 16:17:25 +00:00
|
|
|
|
2015-05-27 12:36:39 +00:00
|
|
|
QQmlApplicationEngine engine;
|
2016-06-22 16:17:25 +00:00
|
|
|
KirigamiPlugin::getInstance().registerTypes();
|
2015-11-30 22:17:04 +00:00
|
|
|
#if __APPLE__
|
|
|
|
// 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 16:41:47 +00:00
|
|
|
engine.addImportPath("qrc://imports");
|
2015-06-09 19:20:44 +00:00
|
|
|
DiveListModel diveListModel;
|
2016-01-29 02:28:44 +00:00
|
|
|
DiveListSortModel *sortModel = new DiveListSortModel(0);
|
2015-07-22 16:09:49 +00:00
|
|
|
sortModel->setSourceModel(&diveListModel);
|
|
|
|
sortModel->setDynamicSortFilter(true);
|
|
|
|
sortModel->setSortRole(DiveListModel::DiveDateRole);
|
|
|
|
sortModel->sort(0, Qt::DescendingOrder);
|
2016-01-08 05:36:27 +00:00
|
|
|
GpsListModel gpsListModel;
|
|
|
|
QSortFilterProxyModel *gpsSortModel = new QSortFilterProxyModel(0);
|
|
|
|
gpsSortModel->setSourceModel(&gpsListModel);
|
|
|
|
gpsSortModel->setDynamicSortFilter(true);
|
2016-03-11 15:26:42 +00:00
|
|
|
gpsSortModel->setSortRole(GpsListModel::GpsWhenRole);
|
2016-01-08 05:36:27 +00:00
|
|
|
gpsSortModel->sort(0, Qt::DescendingOrder);
|
2015-06-09 19:20:44 +00:00
|
|
|
QQmlContext *ctxt = engine.rootContext();
|
2015-07-22 16:09:49 +00:00
|
|
|
ctxt->setContextProperty("diveModel", sortModel);
|
2016-01-08 05:36:27 +00:00
|
|
|
ctxt->setContextProperty("gpsModel", gpsSortModel);
|
2015-05-27 12:36:39 +00:00
|
|
|
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
|
2015-07-13 00:39:13 +00: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-10 03:34:04 +00:00
|
|
|
qml_window->setIcon(QIcon(":/subsurface-mobile-icon"));
|
2016-01-01 17:34:32 +00:00
|
|
|
qqWindowObject->setProperty("messageText", QVariant("Subsurface-mobile startup"));
|
2016-03-09 03:35:22 +00: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 12:48:51 +00:00
|
|
|
QMLManager *manager = QMLManager::instance();
|
2017-04-04 00:29:06 +00:00
|
|
|
manager->setDevicePixelRatio(qml_window->devicePixelRatio(), qml_window->screen());
|
2016-04-14 12:48:51 +00:00
|
|
|
manager->dlSortModel = sortModel;
|
|
|
|
manager->screenChanged(screen);
|
2016-03-09 03:35:22 +00:00
|
|
|
qDebug() << "qqwindow screen has ldpi/pdpi" << screen->logicalDotsPerInch() << screen->physicalDotsPerInch();
|
2016-04-05 23:48:47 +00:00
|
|
|
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
|
2015-07-12 17:42:23 +00:00
|
|
|
qml_window->setHeight(1200);
|
|
|
|
qml_window->setWidth(800);
|
|
|
|
#endif
|
2015-05-27 12:36:39 +00:00
|
|
|
qml_window->show();
|
2015-06-16 13:52:06 +00:00
|
|
|
qApp->exec();
|
2011-09-20 19:40:34 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 13:52:06 +00:00
|
|
|
void exit_ui()
|
2012-05-02 17:03:48 +00:00
|
|
|
{
|
2015-06-16 13:52:06 +00:00
|
|
|
delete qApp;
|
2014-05-12 17:58:15 +00:00
|
|
|
free((void *)existing_filename);
|
2012-05-02 17:03:48 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 16:24:06 +00:00
|
|
|
double get_screen_dpi()
|
|
|
|
{
|
2015-06-16 13:52:06 +00:00
|
|
|
QDesktopWidget *mydesk = qApp->desktop();
|
2013-05-10 16:24:06 +00:00
|
|
|
return mydesk->physicalDpiX();
|
|
|
|
}
|
2015-11-05 18:05:22 +00:00
|
|
|
|
|
|
|
bool haveFilesOnCommandLine()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|