ApplicationUI::ApplicationUI() : QObject(), m_settings(new QSettings(this)) { m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); Q_ASSERT(res); Q_UNUSED(res); onSystemLanguageChanged(); QmlDocument *qml = QmlDocument::create("asset:///Main.qml").parent(this); qml->setContextProperty("_app", this); qml->setContextProperty("_notes", new Notes(this)); DisplayInfo display; int width = display.pixelSize().width(); int height = display.pixelSize().height(); QDeclarativePropertyMap* displayProperties = new QDeclarativePropertyMap; displayProperties->insert("width", QVariant(width)); displayProperties->insert("height", QVariant(height)); qml->setContextProperty("DisplayInfo", displayProperties); AbstractPane *root = qml->createRootObject<AbstractPane>(); Application::instance()->setScene(root); }
ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); if(!QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) { // This is an abnormal situation! Something went wrong! // Add own code to recover here qWarning() << "Recovering from a failed connect()"; } // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); DisplayInfo display; int width = display.pixelSize().width(); int height = display.pixelSize().height(); // Create root object for the UI Page *root = qml->createRootObject<Page>(); root->setProperty("screenWidth", width); root->setProperty("screenHeight", height); // Set created root object as the application scene app->setScene(root); }
FoodCompanion::FoodCompanion(bb::cascades::Application *app) : QObject(app) { // register camera utilities qmlRegisterType<CameraUtilities>("CameraUtilities", 1, 0, "CameraUtilities"); // register timer functionalities qmlRegisterType<QTimer>("QtTimer", 1, 0, "Timer"); // register SceneCover functionalities qmlRegisterType<SceneCover>("bb.cascades", 1, 0, "SceneCover"); // Since it is not possible to create an instance of the AbstractCover // it is registered as an uncreatable type (necessary for accessing // Application.cover). qmlRegisterUncreatableType<AbstractCover>("bb.cascades", 1, 0, "AbstractCover", "An AbstractCover cannot be created."); // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Retrieve the path to the app's working directory QString workingDir = QDir::currentPath(); // Build the path, add it as a context property, and expose // it to QML QDeclarativePropertyMap* dirPaths = new QDeclarativePropertyMap; dirPaths->insert("currentPath", QVariant(QString("file://" + workingDir))); dirPaths->insert("assetPath", QVariant(QString("file://" + workingDir + "/app/native/assets/"))); qml->setContextProperty("dirPaths", dirPaths); DisplayInfo display; int width = display.pixelSize().width(); int height = display.pixelSize().height(); QDeclarativePropertyMap* displayProperties = new QDeclarativePropertyMap; displayProperties->insert("width", QVariant(width)); displayProperties->insert("height", QVariant(height)); qml->setContextProperty("DisplayInfo", displayProperties); QDeclarativePropertyMap* debugMode = new QDeclarativePropertyMap; debugMode->insert("debugMode", QVariant(QBool(true))); qml->setContextProperty("DebugMode", debugMode); // Create root object for the UI AbstractPane *root = qml->createRootObject<AbstractPane>(); // Set created root object as the application scene app->setScene(root); }
int ApplicationUIBase::get_display_width() { DisplayInfo displayInfo; return displayInfo.pixelSize().width(); }
int ApplicationUIBase::get_display_height() { DisplayInfo displayInfo; return displayInfo.pixelSize().height(); }