2013-05-03 11:04:51 -07:00
|
|
|
/* qt-gui.cpp */
|
|
|
|
/* Qt UI implementation */
|
2011-09-20 12:40:34 -07:00
|
|
|
#include "dive.h"
|
|
|
|
#include "display.h"
|
2013-04-07 15:20:43 -07:00
|
|
|
#include "qt-ui/mainwindow.h"
|
2013-05-22 23:24:33 -07:00
|
|
|
#include "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
|
|
|
|
2013-04-07 15:20:43 -07:00
|
|
|
|
2015-06-16 06:52:06 -07:00
|
|
|
#include "qt-gui.h"
|
2013-04-02 19:49:17 +03:00
|
|
|
|
2015-06-04 13:36:36 +03:00
|
|
|
#ifdef SUBSURFACE_MOBILE
|
2015-07-12 17:34:52 -07:00
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
#include <QQmlContext>
|
|
|
|
#include "qt-mobile/qmlmanager.h"
|
|
|
|
#include "qt-models/divelistmodel.h"
|
2015-07-17 19:10:32 +03:00
|
|
|
#include "qt-mobile/qmlprofile.h"
|
2015-07-12 17:34:52 -07:00
|
|
|
QObject *qqWindowObject = NULL;
|
2015-06-04 13:36:36 +03:00
|
|
|
#endif
|
|
|
|
|
2015-06-16 06:52:06 -07:00
|
|
|
static MainWindow *window = NULL;
|
2013-04-25 15:28:31 -07:00
|
|
|
|
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();
|
2013-10-10 12:26:03 -07:00
|
|
|
|
2013-09-18 10:27:24 -05:00
|
|
|
window = new MainWindow();
|
2013-09-09 05:59:03 -03:00
|
|
|
if (existing_filename && existing_filename[0] != '\0')
|
|
|
|
window->setTitle(MWTF_FILENAME);
|
|
|
|
else
|
|
|
|
window->setTitle(MWTF_DEFAULT);
|
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-05-27 15:36:39 +03:00
|
|
|
#ifdef SUBSURFACE_MOBILE
|
2015-06-03 17:19:01 +03:00
|
|
|
window->hide();
|
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");
|
2015-05-27 15:36:39 +03:00
|
|
|
QQmlApplicationEngine engine;
|
2015-06-09 22:20:44 +03:00
|
|
|
DiveListModel diveListModel;
|
|
|
|
QQmlContext *ctxt = engine.rootContext();
|
|
|
|
ctxt->setContextProperty("diveModel", &diveListModel);
|
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"));
|
2015-07-12 17:39:13 -07:00
|
|
|
qqWindowObject->setProperty("messageText", QVariant("Subsurface mobile startup"));
|
2015-07-12 10:42:23 -07:00
|
|
|
#if !defined(Q_OS_ANDROID)
|
|
|
|
qml_window->setHeight(1200);
|
|
|
|
qml_window->setWidth(800);
|
|
|
|
#endif
|
2015-05-27 15:36:39 +03:00
|
|
|
qml_window->show();
|
|
|
|
#else
|
2014-03-11 18:11:34 -03:00
|
|
|
window->show();
|
2015-05-27 15:36:39 +03:00
|
|
|
#endif
|
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
|
|
|
{
|
2013-09-18 10:27:24 -05:00
|
|
|
delete window;
|
2015-06-16 06:52:06 -07:00
|
|
|
delete qApp;
|
2014-05-12 14:58:15 -03:00
|
|
|
free((void *)existing_filename);
|
2014-12-18 10:47:00 -08:00
|
|
|
free((void *)default_dive_computer_vendor);
|
|
|
|
free((void *)default_dive_computer_product);
|
2014-05-12 14:58:15 -03:00
|
|
|
free((void *)default_dive_computer_device);
|
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();
|
|
|
|
}
|
2013-05-22 23:24:33 -07:00
|
|
|
|
2013-05-31 06:26:08 +09:00
|
|
|
|