From: sungmin ha Date: Fri, 25 Jul 2014 05:09:20 +0000 (+0900) Subject: ui: added qt ui execution on qemu runtime X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f2b6129445bb6777127128cbfd82e8fe4220416;p=sdk%2Femulator%2Fqemu.git ui: added qt ui execution on qemu runtime Change-Id: Iec80186871d67bd2b2e5c576b3d4372aa0b1412c Signed-off-by: sungmin ha --- diff --git a/.gitignore b/.gitignore index 262fa1a382..58f6ce0ab9 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,4 @@ fsdev/virtfs-proxy-helper check-hax check-cam moc_*.cpp +qrc_*.cpp diff --git a/configure b/configure index 1dfa9d08cf..aa7bc7945f 100755 --- 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 diff --git a/tizen/src/Makefile.objs b/tizen/src/Makefile.objs index 508e120e7e..02e27ba190 100644 --- a/tizen/src/Makefile.objs +++ b/tizen/src/Makefile.objs @@ -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/ diff --git a/tizen/src/display/qt5_supplement.cpp b/tizen/src/display/qt5_supplement.cpp index e72ea75656..7c154165ce 100644 --- a/tizen/src/display/qt5_supplement.cpp +++ b/tizen/src/display/qt5_supplement.cpp @@ -29,7 +29,22 @@ #include #include "qt5_supplement.h" +#include +#include +#include +#include +#include + +#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("EmulatorComponent", 1, 0, "Region"); + qmlRegisterType("EmulatorComponent", 1, 0, "Key"); + qmlRegisterType("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("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 index 0000000000..2e5a8e47e7 --- /dev/null +++ b/tizen/src/ui/Makefile.objs @@ -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 index 391d768810..0000000000 --- a/tizen/src/ui/images.qrc +++ /dev/null @@ -1,7 +0,0 @@ - - - icons/emulator_icon.ico - icons/shell.png - - - diff --git a/tizen/src/ui/mainwindow.cpp b/tizen/src/ui/mainwindow.cpp index 48ce11f998..5a4b609ae7 100644 --- a/tizen/src/ui/mainwindow.cpp +++ b/tizen/src/ui/mainwindow.cpp @@ -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(); + } +} diff --git a/tizen/src/ui/mainwindow.h b/tizen/src/ui/mainwindow.h index 47a276f63e..2ffd47dc5a 100644 --- a/tizen/src/ui/mainwindow.h +++ b/tizen/src/ui/mainwindow.h @@ -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 index 0000000000..f5b5313760 --- /dev/null +++ b/tizen/src/ui/menu/Makefile.objs @@ -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 $@ diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index 3666e3f72f..9e30a4ff18 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -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 index 0000000000..9a9378ad85 --- /dev/null +++ b/tizen/src/ui/xml/Makefile.objs @@ -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 $@ +