Implemented QML skeleton for the application
This commit is contained in:
144
main.cpp
144
main.cpp
@@ -18,129 +18,55 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "mainwindownew.h"
|
||||
#include "connectandenterpage.h"
|
||||
#include "bmsinterface.h"
|
||||
#include "utility.h"
|
||||
#include "mobile/fwhelper.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStyleFactory>
|
||||
#include <QSettings>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGuiApplication>
|
||||
#include <QFontDatabase>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
#include "mobile/qmlui.h"
|
||||
QObject *bmsInterfaceSingletontypeProvider(QQmlEngine */*engine*/, QJSEngine */*scriptEngine*/)
|
||||
{
|
||||
auto *interface = new BMSInterface();
|
||||
interface->bmsConfig()->loadParamsXml("://res/config.xml");
|
||||
interface->infoConfig()->loadParamsXml("://res/info.xml");
|
||||
return interface;
|
||||
}
|
||||
|
||||
#define NEW_GUI 1
|
||||
QObject *utilitySingletontypeProvider(QQmlEngine */*engine*/, QJSEngine */*scriptEngine*/)
|
||||
{
|
||||
auto *utility = new Utility();
|
||||
return utility;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
constexpr char const *APP_NAME = "ENNOID-BMS Tool";
|
||||
// Settings
|
||||
QCoreApplication::setOrganizationName("DieBie");
|
||||
QCoreApplication::setOrganizationDomain("diebie.nl");
|
||||
QCoreApplication::setApplicationName(APP_NAME);
|
||||
Q_INIT_RESOURCE(res);
|
||||
Q_INIT_RESOURCE(qml_icons);
|
||||
Q_INIT_RESOURCE(qml_items);
|
||||
|
||||
// DPI settings
|
||||
// TODO: http://www.qcustomplot.com/index.php/support/forum/1344
|
||||
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
|
||||
#ifdef USE_MOBILE
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
#else
|
||||
QCoreApplication::setAttribute(Qt::AA_Use96Dpi);
|
||||
QCoreApplication::setOrganizationName("Cubo");
|
||||
QCoreApplication::setOrganizationDomain("Cubo.rus");
|
||||
QCoreApplication::setApplicationName("Cubo Verde BMS Tool");
|
||||
|
||||
QSettings set;
|
||||
bool scaleAuto = true;
|
||||
double scale = 1.0;
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
if (set.contains("app_scale_auto")) {
|
||||
scaleAuto = set.value("app_scale_auto").toBool();
|
||||
} else {
|
||||
set.setValue("app_scale_auto", scaleAuto);
|
||||
}
|
||||
|
||||
if (scaleAuto) {
|
||||
QApplication tmp(argc, argv);
|
||||
QRect rec = tmp.desktop()->screenGeometry();
|
||||
int height = rec.height();
|
||||
int width = rec.width();
|
||||
double ptFont = tmp.font().pointSizeF();
|
||||
if (ptFont < 0.0) {
|
||||
ptFont = tmp.font().pixelSize();
|
||||
}
|
||||
|
||||
if (width > 3000 && height > 1700) {
|
||||
scale = 1.5;
|
||||
} else {
|
||||
if (ptFont > 11.0) {
|
||||
scale = ptFont / 11.0;
|
||||
}
|
||||
}
|
||||
|
||||
set.setValue("app_scale_factor", scale);
|
||||
} else if (set.contains("app_scale_factor")) {
|
||||
scale = set.value("app_scale_factor").toDouble();
|
||||
}
|
||||
|
||||
set.setValue("app_scale_factor", scale);
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
scale = 1.0;
|
||||
#endif
|
||||
|
||||
if (scale > 1.01) {
|
||||
qputenv("QT_SCALE_FACTOR", QString::number(scale).toLocal8Bit());
|
||||
}
|
||||
#endif
|
||||
|
||||
QApplication a(argc, argv);
|
||||
|
||||
#if NEW_GUI
|
||||
// Fonts
|
||||
QFontDatabase::addApplicationFont("://res/fonts/Artifakt-Element.ttf");
|
||||
app.setFont(QFont("Artifakt Element", 16, QFont::Medium));
|
||||
|
||||
qApp->setFont(QFont("Artifakt Element", 12));
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
#else
|
||||
// Fonts
|
||||
QFontDatabase::addApplicationFont("://res/fonts/DejaVuSans.ttf");
|
||||
QFontDatabase::addApplicationFont("://res/fonts/DejaVuSans-Bold.ttf");
|
||||
QFontDatabase::addApplicationFont("://res/fonts/DejaVuSans-BoldOblique.ttf");
|
||||
QFontDatabase::addApplicationFont("://res/fonts/DejaVuSans-Oblique.ttf");
|
||||
QFontDatabase::addApplicationFont("://res/fonts/DejaVuSansMono.ttf");
|
||||
QFontDatabase::addApplicationFont("://res/fonts/DejaVuSansMono-Bold.ttf");
|
||||
QFontDatabase::addApplicationFont("://res/fonts/DejaVuSansMono-BoldOblique.ttf");
|
||||
QFontDatabase::addApplicationFont("://res/fonts/DejaVuSansMono-Oblique.ttf");
|
||||
qmlRegisterSingletonType<BMSInterface>("Cubo", 1, 0, "BmsInterface", bmsInterfaceSingletontypeProvider);
|
||||
qmlRegisterSingletonType<Utility>("Cubo", 1, 0, "Utility", utilitySingletontypeProvider);
|
||||
qmlRegisterType<BleUart>("Cubo", 1, 0, "BleUart");
|
||||
qmlRegisterType<Commands>("Cubo", 1, 0, "Commands");
|
||||
qmlRegisterType<ConfigParams>("Cubo", 1, 0, "ConfigParams");
|
||||
qmlRegisterType<FwHelper>("Cubo", 1, 0, "FwHelper");
|
||||
|
||||
qApp->setFont(QFont("DejaVu Sans", 11));
|
||||
engine.addImportPath(QStringLiteral("qrc:/"));
|
||||
engine.load(QUrl(QStringLiteral("qrc:/MainWindow.qml")));
|
||||
|
||||
// Style
|
||||
a.setStyleSheet("");
|
||||
a.setStyle(QStyleFactory::create("Fusion"));
|
||||
#endif
|
||||
|
||||
#ifdef USE_MOBILE
|
||||
QmlUi q;
|
||||
q.startQmlUi();
|
||||
#else
|
||||
|
||||
#if NEW_GUI
|
||||
|
||||
MainWindowNew w;
|
||||
w.setWindowTitle(APP_NAME);
|
||||
w.show();
|
||||
|
||||
//} else {
|
||||
// a.closeAllWindows();
|
||||
// return 0;
|
||||
//}
|
||||
#else
|
||||
MainWindow w;
|
||||
w.show();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
return a.exec();
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user