#include <QApplication>
#include "qt5_supplement.h"
+#include <QQmlComponent>
+#include <QQmlEngine>
+#include <QQmlProperty>
+#include <QtQuick/QQuickItem>
+#include <QtQuick/QQuickWindow>
+
+#include "mainwindow.h"
+#include "uiinformation.h"
+#include "hardwarekey.h"
+#include "ui/xml/hardwarekeytype.h"
+#include "ui/xml/keylisttype.h"
+#include "ui/xml/layouttype.h"
+
//using namespace std;
+void loadSkinLayoutFromXML(QFile *, UIInformation *);
+void loadControllerLayoutFromXML(QFile *, UIInformation *);
static QApplication *app;
static int argc = 0;
static char *argv[0];
-static QT5Console *console;
+//static QT5Console *console;
+static MainWindow *mainwindow;
+static UIInformation *uiInfo;
-void qt5_prepare(void)
+void qt5_skin_init(void)
{
+ Q_INIT_RESOURCE(resource);
+
+// QApplication app(argc, argv);
+
app = new QApplication(argc, argv);
- console = new QT5Console();
- console->show();
+ uiInfo = new UIInformation();
+
+ /* parameter parsing */
+ // TODO:
+ QString vmName = "test";
+ int basePort = 26100;
+
+ uiInfo->vmName = vmName;
+ uiInfo->basePort = basePort;
+
+#if 0
+ /* wearable */
+ uiInfo.resolution.setWidth(320);
+ uiInfo.resolution.setHeight(320);
+ uiInfo.skinPath = "/skins/wearable-320x320-1btn/";
+#elif 1
+ /* mobile */
+ uiInfo->resolution.setWidth(720);
+ uiInfo->resolution.setHeight(1280);
+ uiInfo->skinPath = "/skins/mobile-720x1280-3btn/";
+
+ uiInfo->uiState.layoutScale = 50;
+#endif
+ /* XML */
+ // TODO: convert QML to XML
+
+ // Register custom QML element
+ qmlRegisterType<RegionType>("EmulatorComponent", 1, 0, "Region");
+ qmlRegisterType<HardwareKeyType>("EmulatorComponent", 1, 0, "Key");
+ qmlRegisterType<KeyListType>("EmulatorComponent", 1, 0, "KeyList");
+
+ QFile skinXMLFile(":" + uiInfo->skinPath + "layout.qml");
+ loadSkinLayoutFromXML(&skinXMLFile, uiInfo);
+
+ QFile conXMLFile(":" + uiInfo->skinPath + "controller-layout/Basic/layout.qml");
+ loadControllerLayoutFromXML(&conXMLFile, uiInfo);
+
+ /* GUI */
+ qDebug("start!");
+ mainwindow = new MainWindow(uiInfo);
+// mainwindow->move(100, 100); // TODO: MRU
+ mainwindow->show();
+
+// MainWindow window(&uiInfo);
+// window.move(100, 100); // TODO: MRU
+// window.show();
+
+// app.exec();
+}
+
+void qt5_prepare(void)
+{
+ qt5_skin_init();
+
+// app = new QApplication(argc, argv);
+// console = new QT5Console();
+// console->show();
}
int qt5_get_win_id(void)
{
- return console->winId();
+ return mainwindow->winId();
+// return console->winId();
}
void qt5_update_internal(void *data, int width, int height)
{
QPixmap pixmap = QPixmap();
- QLabel *label = console->getLabel();
+// QLabel *label = console->getLabel();
+ QLabel *label = mainwindow->getLabel();
QImage image = QImage((uchar *)data, width, height, QImage::Format_ARGB32);
pixmap.convertFromImage(image);
-
label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatio,
Qt::SmoothTransformation));
+ label->show();
}
void qt5_switch_internal(void)
void sdl_mouse_define(void)
{
}
+
+void loadSkinLayoutFromXML(QFile *file, UIInformation *uiInfo/* out */)
+{
+ if (file->exists() == false) {
+ qDebug("skin xml file is null");
+ return;
+ }
+
+ qDebug("load skin layout from %s", file->fileName().toLocal8Bit().data());
+
+ qmlRegisterType<LayoutType>("EmulatorComponent", 1, 0, "Layout");
+
+ /* QML */
+ QQmlEngine *engine = new QQmlEngine();
+ QQmlComponent *component = new QQmlComponent(engine);
+
+ QUrl qmlSource("qrc" + file->fileName());
+ // Other possible QML files that are used engine->addImportPath("qrc:/other");
+ component->loadUrl(qmlSource);
+ if (!component->isReady()) {
+ qWarning("%s", qPrintable(component->errorString()));
+ //return -1;
+ }
+ QObject *object = component->create();
+
+ if (object != NULL) {
+ QFileInfo fileInfo(*file);
+ qDebug() << "xml version :" << QQmlProperty::read(object, "version").toString();
+
+ LayoutType *layoutType = NULL;
+ KeyListType *keyListType = NULL;
+ HardwareKeyType *hwKeyType = NULL;
+
+ QObjectList layoutTypeList = object->children();
+ for (int index = 0; index < layoutTypeList.count(); index++) {
+ SkinLayout *layout = new SkinLayout(); /* dst */
+
+ layoutType = (LayoutType *)layoutTypeList.at(index); /* src */
+
+ layout->displayRegion = layoutType->displayRegion();
+ layout->skinImg[SkinLayout::normal].load(
+ fileInfo.absolutePath() + "/" + layoutType->mainImageName());
+ layout->skinImg[SkinLayout::pressed].load(
+ fileInfo.absolutePath() + "/" + layoutType->pressedImageName());
+
+ keyListType = layoutType->keyListType();
+ if (keyListType != NULL) {
+ for (int i = 0; i < keyListType->list.count(); i++) {
+ hwKeyType = keyListType->list.at(i);
+ if (hwKeyType != NULL) {
+ layout->keyList.append(
+ new HardwareKey(hwKeyType->objectName(), hwKeyType->keycode(),
+ hwKeyType->region(), hwKeyType->tooltip()));
+ }
+ }
+ }
+
+ uiInfo->layoutList.append(layout);
+ }
+
+ delete object;
+ }
+
+ delete component;
+ delete engine;
+}
+
+void loadControllerLayoutFromXML(QFile *file, UIInformation *uiInfo/* out */)
+{
+ if (file->exists() == false) {
+ qDebug("con xml file is null");
+ return;
+ }
+
+ qDebug("load con layout from %s", file->fileName().toLocal8Bit().data());
+
+ /* QML */
+ QQmlEngine *engine = new QQmlEngine();
+ QQmlComponent *component = new QQmlComponent(engine);
+
+ QUrl qmlSource("qrc" + file->fileName());
+ component->loadUrl(qmlSource);
+ if (!component->isReady()) {
+ qWarning("%s", qPrintable(component->errorString()));
+ }
+ QObject *object = component->create();
+
+ if (object != NULL) {
+ QFileInfo fileInfo(*file);
+ qDebug() << "xml version :" << QQmlProperty::read(object, "version").toString();
+
+ LayoutType *layoutType = (LayoutType *)object;
+ KeyListType *keyListType = NULL;
+ HardwareKeyType *hwKeyType = NULL;
+
+ ControllerLayout *layout = new ControllerLayout();
+ layout->conImg[ControllerLayout::normal].load(
+ fileInfo.absolutePath() + "/" + layoutType->mainImageName());
+
+ keyListType = layoutType->keyListType();
+ if (keyListType != NULL) {
+ for (int i = 0; i < keyListType->list.count(); i++) {
+ hwKeyType = keyListType->list.at(i);
+ if (hwKeyType != NULL) {
+ layout->keyList.append(
+ new HardwareKey(hwKeyType->objectName(), hwKeyType->keycode(),
+ hwKeyType->region(), hwKeyType->tooltip()));
+ }
+ }
+ }
+
+ uiInfo->controllerList.append(layout);
+
+ delete object;
+ }
+
+ delete component;
+ delete engine;
+}