diff --git a/src/libs/core/tglobals.cpp b/src/libs/core/tglobals.cpp index 6e52e0d1789b01b502a2da2526819f4e6621911c..9f3707a0074a2c079620086e431f8ecd94b71067 100755 --- a/src/libs/core/tglobals.cpp +++ b/src/libs/core/tglobals.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2011-2016 by Tomasz Bojczuk * + * Copyright (C) 2011-2017 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -32,14 +32,15 @@ #if defined (Q_OS_ANDROID) #include <Android/tandroid.h> #endif -#include <QDir> -#include <QSettings> -#include <QCoreApplication> -#include <QDebug> +#include <QtCore/qdir.h> +#include <QtCore/qsettings.h> +#include <QtCore/qcoreapplication.h> +#include <QtCore/qdebug.h> /*static*/ QString& Tglobals::path = Tpath::main; +Tglobals* Tglobals::m_instance = nullptr; QString Tglobals::getInstPath(QString appInstPath) { QString p; @@ -64,7 +65,8 @@ TtouchProxy* onlyOneTouchProxy = 0; // It is available through TtouchProxy::inst /*end static*/ -Tglobals::Tglobals() : +Tglobals::Tglobals(QObject* parent) : + QObject(parent), m_tune(0) { version = NOOTKA_VERSION; @@ -91,11 +93,12 @@ Tglobals::Tglobals() : #endif loadSettings(config); - if (Tcore::gl() == 0) - Tcore::setGlobals(this); - else { - qDebug() << "Tglobals instance has already existed. Application is terminating!"; - exit(109); + if (!m_instance) { + Tcore::setGlobals(this); // TODO remove it, use GLOB macro instead + m_instance = this; + } else { + qDebug() << "Tglobals instance has already existed. Application is terminating!"; + exit(109); } onlyOneTouchProxy = new TtouchProxy(); } @@ -112,6 +115,7 @@ Tglobals::~Tglobals() { delete onlyOneTouchProxy; delete TtouchParams::i(); Tcore::reset(); + m_instance = nullptr; } @@ -119,6 +123,11 @@ Tglobals::~Tglobals() { //####################### PUBLIC ########################################### //########################################################################################## +QVariant Tglobals::getVar(const QString& key) { + return config->value(key); +} + + void Tglobals::loadSettings(QSettings* cfg) { cfg->beginGroup("common"); isFirstRun = cfg->value("isFirstRun", true).toBool(); diff --git a/src/libs/core/tglobals.h b/src/libs/core/tglobals.h index 25962184e230b06a48d87baa2195850710857747..257973c8d728dd936563ab75ed2610117425e31d 100644 --- a/src/libs/core/tglobals.h +++ b/src/libs/core/tglobals.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2011-2015 by Tomasz Bojczuk * + * Copyright (C) 2011-2017 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -21,7 +21,8 @@ #define TGLOBALS_H #include <nootkacoreglobal.h> -#include <QtCore/qstring.h> +#include <QtCore/qobject.h> +#include <QtCore/qvariant.h> #include <QtGui/qcolor.h> #include <music/tnote.h> #include <music/tinstrument.h> @@ -34,15 +35,27 @@ class QSettings; class TexamParams; class TaudioParams; -class NOOTKACORE_EXPORT Tglobals +#define GLOB Tglobals::instance() + + +class NOOTKACORE_EXPORT Tglobals : public QObject { + Q_OBJECT public: /** If @p true, setting are loaded from temporary config file */ - Tglobals(); + Tglobals(QObject* parent = nullptr); ~Tglobals(); + /** + * Instance (single for whole Nootka) of Tglobals class. + * Also avail through @p GLOB macro + */ + static Tglobals* instance() { return m_instance; } + + Q_INVOKABLE QVariant getVar(const QString& key); + /** This method return application install path - path from where Nootka was started. */ static QString getInstPath(QString appInstPath); static QString& path; /**< Reference to Tpath::main - Nootka resources path */ @@ -112,8 +125,9 @@ public: TlayoutParams *L; /**< Main window Layout params. */ private: - Ttune *m_tune; /**< current guitar tune */ - qint8 m_order[6]; /**< Strings order is determined in @param setTune() method */ + Ttune *m_tune; /**< current guitar tune */ + qint8 m_order[6]; /**< Strings order is determined in @param setTune() method */ + static Tglobals *m_instance; }; #endif // TGLOBALS_H diff --git a/src/main.cpp b/src/main.cpp index 0a88b292278500e89470145558defe6c680b3379..9f42f7873fcd5b919c39e87fe8aa179642946f45 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -107,6 +107,7 @@ int main(int argc, char *argv[]) // creating main window e = new QQmlApplicationEngine; e->rootContext()->setContextProperty(QStringLiteral("Tpath"), &pathObj); + e->rootContext()->setContextProperty(QStringLiteral("GLOB"), GLOB); e->load(QUrl(QStringLiteral("qrc:/MainWindow.qml"))); // #if defined (Q_OS_ANDROID) diff --git a/src/qml/MainWindow.qml b/src/qml/MainWindow.qml index dceab9dd4f8603b0e2c4b3462b89cca789fd68ed..76e4fe0416c4d5a29db36da1229cf5b86dffa982 100644 --- a/src/qml/MainWindow.qml +++ b/src/qml/MainWindow.qml @@ -23,13 +23,29 @@ import QtQuick.Window 2.0 ApplicationWindow { - id: qrabWindow + id: nootkaWindow visible: true title: "Nootka" - width: Screen.desktopAvailableWidth / 2 - height: Screen.desktopAvailableHeight / 2 + width: { + var r = GLOB.getVar("General/geometry") + return (r && r.width >= 720) ? r.width : Math.max(Screen.desktopAvailableWidth * 0.75, 720) + } + height: { + var r = GLOB.getVar("General/geometry") + return (r && r.height >= 480) ? r.height : Math.max(Screen.desktopAvailableHeight * 0.75, 480) + } + x: { + var r = GLOB.getVar("General/geometry") + return (r && r.x >= 0) ? r.x : (Screen.desktopAvailableWidth - nootkaWindow.width) / 2 + } + y: { + var r = GLOB.getVar("General/geometry") + return (r && r.y >= 0) ? r.y : (Screen.desktopAvailableHeight - nootkaWindow.height) / 2 + } header: TtoolBar {} + Component.onCompleted: {} + }