ui: added qt ui execution on qemu runtime 94/24994/9
authorsungmin ha <sungmin82.ha@samsung.com>
Fri, 25 Jul 2014 05:09:20 +0000 (14:09 +0900)
committersungmin ha <sungmin82.ha@samsung.com>
Mon, 28 Jul 2014 09:25:40 +0000 (18:25 +0900)
Change-Id: Iec80186871d67bd2b2e5c576b3d4372aa0b1412c
Signed-off-by: sungmin ha <sungmin82.ha@samsung.com>
.gitignore
configure
tizen/src/Makefile.objs
tizen/src/display/qt5_supplement.cpp
tizen/src/ui/Makefile.objs [new file with mode: 0644]
tizen/src/ui/images.qrc [deleted file]
tizen/src/ui/mainwindow.cpp
tizen/src/ui/mainwindow.h
tizen/src/ui/menu/Makefile.objs [new file with mode: 0644]
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/xml/Makefile.objs [new file with mode: 0644]

index 262fa1a3821718c616aa0cbcb3a9d97d888a2da8..58f6ce0ab99df526701e6a40cb3569d86bf609bd 100644 (file)
@@ -132,3 +132,4 @@ fsdev/virtfs-proxy-helper
 check-hax
 check-cam
 moc_*.cpp
+qrc_*.cpp
index 1dfa9d08cfff4dd553b36ff67bf65eff3f2a36cf..aa7bc7945f45438497054151560ecf78898d9c16 100755 (executable)
--- a/configure
+++ b/configure
@@ -2087,7 +2087,7 @@ fi
 qtversion=""
 if test "$qt" != "no"; then
     if test "$qtabi" = "5.0" ; then
-        qtpackage="Qt5Widgets"
+        qtpackage="Qt5Widgets Qt5Qml Qt5OpenGL"
         qtversion="5.0.0"
 
         if $pkg_config --exists "$qtpackage >= $qtversion"; then
index 508e120e7e47f9b37a3e21960983f8fe217d776b..02e27ba19075afedec6e326355f980a049e3ab09 100644 (file)
@@ -8,6 +8,9 @@ obj-y += emulator.o emulator_legacy.o emulator_options.o emul_state.o
 # utils
 obj-y += util/
 
+# ui
+obj-y += ui/
+
 # maru display
 obj-y += display/
 
index e72ea7565624472bc263913354da426542c3092b..7c154165ce3b3f1f545c334a5e3d5bb33be147cf 100644 (file)
 #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;
 
@@ -55,30 +70,93 @@ QLabel *QT5Console::getLabel()
 
 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)
@@ -97,3 +175,122 @@ void qt5_mouse_warp(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;
+}
diff --git a/tizen/src/ui/Makefile.objs b/tizen/src/ui/Makefile.objs
new file mode 100644 (file)
index 0000000..2e5a8e4
--- /dev/null
@@ -0,0 +1,30 @@
+TIZEN_UI = $(SRC_PATH)/tizen/src/ui
+QEMU_CFLAGS += -fPIC $(QT_CFLAGS) -I$(TIZEN_UI) -DCONFIG_MARU
+
+$(TIZEN_UI)/qrc_resource.o: $(TIZEN_UI)/qrc_resource.cpp
+$(TIZEN_UI)/qrc_resource.cpp:
+       rcc -name resource $(TIZEN_UI)/resource/resource.qrc -o $(TIZEN_UI)/qrc_resource.cpp
+
+obj-$(CONFIG_QT) += controllerlayout.o
+obj-$(CONFIG_QT) += displaywidget.o moc_displaywidget.o
+obj-$(CONFIG_QT) += hardwarekey.o
+obj-$(CONFIG_QT) += mainwindow.o moc_mainwindow.o
+obj-$(CONFIG_QT) += skinbezelitem.o
+obj-$(CONFIG_QT) += skincontrollerview.o
+obj-$(CONFIG_QT) += skinkeyitem.o
+obj-$(CONFIG_QT) += skinlayout.o
+obj-$(CONFIG_QT) += skinview.o
+obj-$(CONFIG_QT) += uiinformation.o
+obj-$(CONFIG_QT) += uistate.o
+obj-$(CONFIG_QT) += qrc_resource.o
+
+obj-$(CONFIG_QT) += xml/
+
+obj-$(CONFIG_QT) += menu/
+
+$(obj)/moc_displaywidget.o: $(obj)/moc_displaywidget.cpp
+$(obj)/moc_displaywidget.cpp: $(obj)/displaywidget.h
+       moc $< -o $@
+$(obj)/moc_mainwindow.o: $(obj)/moc_mainwindow.cpp
+$(obj)/moc_mainwindow.cpp: $(obj)/mainwindow.h
+       moc $< -o $@
diff --git a/tizen/src/ui/images.qrc b/tizen/src/ui/images.qrc
deleted file mode 100644 (file)
index 391d768..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<RCC>
-    <qresource prefix="/">
-        <file>icons/emulator_icon.ico</file>
-        <file>icons/shell.png</file>
-    </qresource>
-    <qresource prefix="/images"/>
-</RCC>
index 48ce11f99845f52d3c640d85a8c37b8416a23dd4..5a4b609ae7a14acf298a3a5e7a6796e22751ae90 100644 (file)
@@ -5,9 +5,18 @@
 #include "skinlayout.h"
 #include "skincontrollerview.h"
 
+#ifdef CONFIG_MARU
+extern "C" void shutdown_qemu_gracefully(void);
+#endif
+
 MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
     QWidget(parent)
 {
+    label = new QLabel();
+    label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+    label->setAlignment(Qt::AlignCenter);
+    label->setFixedSize(720 / 2, 1280 / 2);
+
     /* initialize */
     this->uiInfo = uiInfo;
 
@@ -63,6 +72,11 @@ MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
             SLOT(showContextMenu(const QPoint&)));
 }
 
+QLabel *MainWindow::getLabel()
+{
+    return label;
+}
+
 void MainWindow::showContextMenu(const QPoint& pos)
 {
     QPoint globalPos = this->mapToGlobal(pos);
@@ -77,7 +91,7 @@ void MainWindow::showContextMenu(const QPoint& pos)
     }
 }
 
-inline UIState *MainWindow::getUIState()
+UIState *MainWindow::getUIState()
 {
     return &(uiInfo->uiState);
 }
@@ -124,3 +138,20 @@ MainWindow::~MainWindow()
 {
     qDebug("destory main window");
 }
+
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+    int r = QMessageBox::warning(this,
+                                 "Warning!",
+                                 "Do you really want to quit this program?",
+                                 QMessageBox::Yes | QMessageBox::Default,
+                                 QMessageBox::No);
+    if (r == QMessageBox::Yes) {
+#ifdef CONFIG_MARU
+        /* force close */
+        shutdown_qemu_gracefully();
+#endif
+    } else {
+        event->ignore();
+    }
+}
index 47a276f63eb90a4f4dca2c51a1f6a6d2d4d7b347..2ffd47dc5a445b28c1af832140eb8c79141361f0 100644 (file)
@@ -22,18 +22,21 @@ public:
     explicit MainWindow(UIInformation *uiInfo, QWidget *parent = 0);
     ~MainWindow();
 
-    UIState *getUIState();
+    UIState *getUIState(void);
     void rotate(int angle);
     void scale(int scale);
 
     UIInformation *uiInfo;
-
+    QLabel *getLabel();
+    QImage *image;
 public slots:
     void showContextMenu(const QPoint& pos);
 
 protected:
     void updateSkin();
     void setRegion(QImage baseImage);
+    void closeEvent(QCloseEvent *);
+    QLabel *label;
 
 private:
     /* windowing */
diff --git a/tizen/src/ui/menu/Makefile.objs b/tizen/src/ui/menu/Makefile.objs
new file mode 100644 (file)
index 0000000..f5b5313
--- /dev/null
@@ -0,0 +1,13 @@
+obj-$(CONFIG_QT) += aboutdialog.o moc_aboutdialog.o
+obj-$(CONFIG_QT) += detailedinfodialog.o moc_detailedinfodialog.o
+obj-$(CONFIG_QT) += contextmenu.o moc_contextmenu.o
+
+$(obj)/moc_aboutdialog.o: $(obj)/moc_aboutdialog.cpp
+$(obj)/moc_aboutdialog.cpp: $(obj)/aboutdialog.h
+       moc $< -o $@
+$(obj)/moc_detailedinfodialog.o: $(obj)/moc_detailedinfodialog.cpp
+$(obj)/moc_detailedinfodialog.cpp: $(obj)/detailedinfodialog.h
+       moc $< -o $@
+$(obj)/moc_contextmenu.o: $(obj)/moc_contextmenu.cpp
+$(obj)/moc_contextmenu.cpp: $(obj)/contextmenu.h
+       moc $< -o $@
index 3666e3f72fa1375923a03ee832c96a0763b18bcb..9e30a4ff187b3bef8fa3de71ed6f17b8720e4c67 100644 (file)
@@ -5,6 +5,10 @@
 #include "detailedinfodialog.h"
 #include "aboutdialog.h"
 
+#ifdef CONFIG_MARU
+extern "C" void shutdown_qemu_gracefully(void);
+#endif
+
 ContextMenu::ContextMenu(QWidget *parent) :
     QMenu(parent)
 {
@@ -177,7 +181,7 @@ void ContextMenu::slotShell()
     QString command = "/usr/bin/gnome-terminal";
     QStringList arguments;
 
-    QString sdbPath = "/home/giwoongkim/tizen-sdk/tools/sdb";
+    QString sdbPath = "~/tizen-sdk/tools/sdb";
     arguments << "-x" << sdbPath << "shell";
 
     QProcess *terminal = new QProcess(this);
@@ -196,6 +200,27 @@ void ContextMenu::slotForceClose()
 {
     qDebug("force close");
 
+    QMessageBox *msg = new QMessageBox();
+    QMessageBox::StandardButton *reply = new QMessageBox::StandardButton();
+    *reply = msg->question((QWidget *)this->parent(), "Emulator",
+        "If you force stop an emulator, it may cause some problems.\n"
+        "Are you sure you want to continue?",
+        QMessageBox::Yes | QMessageBox::No,
+        QMessageBox::Yes);
+
+    if (*reply == QMessageBox::Yes) {
+        qDebug() << "exit!";
+#ifdef CONFIG_MARU
+        /* force close */
+        shutdown_qemu_gracefully();
+#endif
+//        MainWindow *win = (MainWindow *)this->parent();
+//        win->~MainWindow();
+    } else {
+        qDebug() << "cancel";
+    }
+
+/*
     QMessageBox::StandardButton reply;
     reply = QMessageBox::question((QWidget *)this->parent(), "Emulator",
         "If you force stop an emulator, it may cause some problems.\n"
@@ -208,13 +233,12 @@ void ContextMenu::slotForceClose()
     } else {
         qDebug() << "cancel";
     }
+*/
 }
 
 void ContextMenu::slotClose()
 {
     qDebug("close");
-
-    QApplication::exit();
 }
 
 ContextMenu::~ContextMenu()
diff --git a/tizen/src/ui/xml/Makefile.objs b/tizen/src/ui/xml/Makefile.objs
new file mode 100644 (file)
index 0000000..9a9378a
--- /dev/null
@@ -0,0 +1,18 @@
+obj-$(CONFIG_QT) += layouttype.o moc_layouttype.o
+obj-$(CONFIG_QT) += hardwarekeytype.o moc_hardwarekeytype.o
+obj-$(CONFIG_QT) += regiontype.o moc_regiontype.o
+obj-$(CONFIG_QT) += keylisttype.o moc_keylisttype.o
+
+$(obj)/moc_layouttype.o: $(obj)/moc_layouttype.cpp
+$(obj)/moc_layouttype.cpp: $(obj)/layouttype.h
+       moc $< -o $@
+$(obj)/moc_hardwarekeytype.o: $(obj)/moc_hardwarekeytype.cpp
+$(obj)/moc_hardwarekeytype.cpp: $(obj)/hardwarekeytype.h
+       moc $< -o $@
+$(obj)/moc_regiontype.o: $(obj)/moc_regiontype.cpp
+$(obj)/moc_regiontype.cpp: $(obj)/regiontype.h
+       moc $< -o $@
+$(obj)/moc_keylisttype.o: $(obj)/moc_keylisttype.cpp
+$(obj)/moc_keylisttype.cpp: $(obj)/keylisttype.h
+       moc $< -o $@
+