#include "guicontroller.h" // Qt // Project #include "guiview.h" #include "maintimer.h" using namespace Gui; GuiController *GuiController::_instance = nullptr; void GuiController::registerView() { qRegisterMetaType("GuiAction"); qmlRegisterType ("Gui.View", 0, 1, "GuiView"); qmlRegisterUncreatableType ("Gui.Actions", 0, 1, "GuiActions",QStringLiteral("Used only for enums no need to have an object")); } GuiController::GuiController(QObject *parent) : QObject(parent) { registerView(); connect(this ,&GuiController::actionRequested, this, &GuiController::actionEvaluation); } GuiController *GuiController::I() { if (!_instance) { _instance = new GuiController(); } return _instance; } void GuiController::init() { connect(&_viewer, &QQuickView::statusChanged, this, &GuiController::onUiStatusChanged); const QUrl url(QML("main")); _viewer.setSource(url); } void GuiController::onUiStatusChanged(QQuickView::Status vStatus) { bool ok = vStatus == QQuickView::Ready; if (ok) { _viewer.show(); } emit initialized(ok); } /*! * \brief GuiController::actionEvaluation * This method evaluated that if the action is accepted or not,\n * Regarding to the current state and the action.\n * These actions are only user actions and there is only one user interaction,\n * So no need to capture from which screen this action comes since we have the current state.\n * Sometimes GuiController requires to investigate with the ApplicationController to get approval from HD device.\n * \param vAction - User requested Action */ void GuiController::actionEvaluation(GuiAction vAction) { static bool requested = false; qDebug() << "actionRequested : " << vAction; // TEST : check state and evaluate. if (!requested) { requested = true; qDebug() << "Ask again: " << vAction; actionEvaluated(vAction, false); return; } requested = false; qDebug() << "Got it: " << vAction; actionEvaluated(vAction, true); }