2013-05-03 18:04:51 +00:00
|
|
|
/* qt-gui.cpp */
|
|
|
|
/* Qt UI implementation */
|
2011-09-20 19:40:34 +00:00
|
|
|
#include "dive.h"
|
|
|
|
#include "display.h"
|
2013-05-23 06:24:33 +00:00
|
|
|
#include "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
|
|
|
|
2015-06-16 13:52:06 +00:00
|
|
|
#include "qt-gui.h"
|
2013-04-02 16:49:17 +00:00
|
|
|
|
2015-07-13 00:34:52 +00:00
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
#include <QQmlContext>
|
2015-07-22 16:09:49 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2015-07-13 00:34:52 +00:00
|
|
|
#include "qt-mobile/qmlmanager.h"
|
|
|
|
#include "qt-models/divelistmodel.h"
|
2015-07-17 16:10:32 +00:00
|
|
|
#include "qt-mobile/qmlprofile.h"
|
2015-11-11 18:54:36 +00:00
|
|
|
#include "qt-mobile/gpslocation.h"
|
2015-06-04 10:36:36 +00:00
|
|
|
|
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");
|
2015-05-27 12:36:39 +00:00
|
|
|
QQmlApplicationEngine engine;
|
2015-06-09 19:20:44 +00:00
|
|
|
DiveListModel diveListModel;
|
2015-07-22 16:09:49 +00:00
|
|
|
QSortFilterProxyModel *sortModel = new QSortFilterProxyModel(0);
|
|
|
|
sortModel->setSourceModel(&diveListModel);
|
|
|
|
sortModel->setDynamicSortFilter(true);
|
|
|
|
sortModel->setSortRole(DiveListModel::DiveDateRole);
|
|
|
|
sortModel->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);
|
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"));
|
2015-07-13 00:39:13 +00:00
|
|
|
qqWindowObject->setProperty("messageText", QVariant("Subsurface mobile startup"));
|
2015-07-12 17:42:23 +00:00
|
|
|
#if !defined(Q_OS_ANDROID)
|
|
|
|
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);
|
2014-12-18 18:47:00 +00:00
|
|
|
free((void *)default_dive_computer_vendor);
|
|
|
|
free((void *)default_dive_computer_product);
|
2014-05-12 17:58:15 +00:00
|
|
|
free((void *)default_dive_computer_device);
|
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;
|
|
|
|
}
|