From d1af9f59ff6ee064aa08fba098627307149198a8 Mon Sep 17 00:00:00 2001 From: Jihye Won Date: Wed, 7 Oct 2015 18:18:00 +0900 Subject: [PATCH] Qt: add a "Move" function to move an emulator The Move function can improve user convenience when the skin bezel is too small to grab the emulator Change-Id: I4729326650ca42364252625c6ec4b0dbf370414c Signed-off-by: Jihye Won --- tizen/src/ui/Makefile.objs | 1 + tizen/src/ui/mainwindow.cpp | 27 ++++++++ tizen/src/ui/mainwindow.h | 10 +++ tizen/src/ui/menu/contextmenu.cpp | 38 ++++++++++ tizen/src/ui/menu/contextmenu.h | 4 +- tizen/src/ui/menu/menuitem.h | 1 + tizen/src/ui/resource/ui_strings.h | 1 + tizen/src/ui/transwidget.cpp | 108 +++++++++++++++++++++++++++++ tizen/src/ui/transwidget.h | 50 +++++++++++++ tizen/src/ui/xmllayoutkeyword.h | 1 + tizen/src/ui/xmllayoutparser.cpp | 48 ++----------- 11 files changed, 246 insertions(+), 43 deletions(-) create mode 100644 tizen/src/ui/transwidget.cpp create mode 100644 tizen/src/ui/transwidget.h diff --git a/tizen/src/ui/Makefile.objs b/tizen/src/ui/Makefile.objs index 830894104f..6b912b06d5 100644 --- a/tizen/src/ui/Makefile.objs +++ b/tizen/src/ui/Makefile.objs @@ -12,6 +12,7 @@ obj-$(CONFIG_QT) += displaybase.o obj-$(CONFIG_QT) += displayglwidget.o moc_displayglwidget.o obj-$(CONFIG_QT) += displayswwidget.o moc_displayswwidget.o obj-$(CONFIG_QT) += displayswapper.o moc_displayswapper.o +obj-$(CONFIG_QT) += transwidget.o obj-$(CONFIG_QT) += mainwindow.o moc_mainwindow.o obj-$(CONFIG_QT) += skinbezelitem.o obj-$(CONFIG_QT) += skinkeyitem.o moc_skinkeyitem.o diff --git a/tizen/src/ui/mainwindow.cpp b/tizen/src/ui/mainwindow.cpp index 074070436e..729c026c08 100644 --- a/tizen/src/ui/mainwindow.cpp +++ b/tizen/src/ui/mainwindow.cpp @@ -4,6 +4,7 @@ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: + * Jihye Won * Hyunjin Lee * SungMin Ha * GiWoong Kim @@ -64,6 +65,7 @@ MainWindow::MainWindow(UiInformation *uiInfo, QWidget *parent) : this->screenWidget = NULL; this->captureRequestHandler = NULL; this->captureRequestData = NULL; + this->transWidget = NULL; /* windowing */ setWindowTitle(EMULATOR_TITLE); @@ -557,3 +559,28 @@ void MainWindow::closeEvent(QCloseEvent *event) event->ignore(); } } + +/* emulator move function */ +void MainWindow::createTransWidget() +{ + qDebug("create transparent widget"); + + if (this->uiInfo == NULL) { + qWarning("UiInfo object is null."); + return; + } + + this->transWidget = new TransWidget(this); + this->transWidget->show(); +} + +void MainWindow::setTransWidget(TransWidget *widget) +{ + this->transWidget = widget; +} + +TransWidget *MainWindow::getTransWidget() +{ + return this->transWidget; +} + diff --git a/tizen/src/ui/mainwindow.h b/tizen/src/ui/mainwindow.h index a28c207b8b..0a8c99cc12 100644 --- a/tizen/src/ui/mainwindow.h +++ b/tizen/src/ui/mainwindow.h @@ -4,6 +4,7 @@ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: + * Jihye Won * Hyunjin Lee * SungMin Ha * GiWoong Kim @@ -46,6 +47,7 @@ #include "controller/dockingcontroller.h" #include "controller/floatingcontroller.h" #include "input/keyboardshortcut.h" +#include "transwidget.h" class MainWindow : public QWidget { @@ -79,6 +81,11 @@ public: void startDisplaySwapper(); void terminateDisplaySwapper(); + /* emulator move function */ + void createTransWidget(); + void setTransWidget(TransWidget *widget); + TransWidget *getTransWidget(); + public slots: void showContextMenu(const QPoint& pos); @@ -111,6 +118,9 @@ private: void (*captureRequestHandler)(void *data); void *captureRequestData; + + /* emulator move function */ + TransWidget *transWidget; }; #endif // MAINWINDOW_H diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index e7adef375a..44c5100224 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -106,6 +106,10 @@ void ContextMenu::createItems(QMenu *menu, QList &list) /* Always On Top menu */ createOnTopItem(menu, item); break; + case MenuItemType::moveItem: + /* Move menu */ + createMoveItem(menu, item); + break; case MenuItemType::switchItem: /* Rotate menu */ createSwitchItem(menu, item); @@ -217,6 +221,32 @@ void ContextMenu::createOnTopItem(QMenu *menu, MenuItem *item) item->setAction(actionTopMost); } +void ContextMenu::createMoveItem(QMenu *menu, MenuItem *item) +{ + if (menu == NULL || item == NULL) { + return; + } + + QString menuName = item->getName(); + actionMove = menu->addAction( + menuName.isEmpty() ? MENU_MOVE_ITEM_TEXT : menuName); + connect(actionMove, SIGNAL(triggered()), this, SLOT(slotMove())); + + /* shortcut */ + QMap shortcutMap = item->getShortcutMap(); + QShortcut *shortcut = NULL; + + if (shortcutMap.isEmpty() == false) { + shortcut = new QShortcut( + item->getShortcutMap().begin().value(), parent); + connect(shortcut, SIGNAL(activated()), this, SLOT(slotMove())); + + actionMove->setShortcut(shortcut->key()); + } + + item->setAction(actionMove); +} + void ContextMenu::createSwitchItem(QMenu *menu, MenuItem *item) { if (menu == NULL || item == NULL) { @@ -636,6 +666,14 @@ void ContextMenu::slotTopMostShortcut() qDebug() << "shortcut:" << actionTopMost->text() << actionTopMost->isChecked(); } +void ContextMenu::slotMove() +{ + if (parent->getTransWidget() == NULL) { + parent->createTransWidget(); + parent->getTransWidget()->setCursor(Qt::SizeAllCursor); + } +} + void ContextMenu::slotSwitch(int index) { qDebug("switch: %d", index); diff --git a/tizen/src/ui/menu/contextmenu.h b/tizen/src/ui/menu/contextmenu.h index e19f5114df..83e0772569 100644 --- a/tizen/src/ui/menu/contextmenu.h +++ b/tizen/src/ui/menu/contextmenu.h @@ -75,7 +75,7 @@ public slots: void slotDetailedInfo(); void slotTopMost(bool on); void slotTopMostShortcut(); - + void slotMove(); void slotSwitch(int index); void slotSwitchShortcutPrev(); void slotSwitchShortcutNext(); @@ -107,6 +107,7 @@ protected: void createInfoItem(QMenu *menu, MenuItem *item); void createOnTopItem(QMenu *menu, MenuItem *item); + void createMoveItem(QMenu *menu, MenuItem *item); void createSwitchItem(QMenu *menu, MenuItem *item); void createScaleItem(QMenu *menu, MenuItem *item); void createControllerItem(QMenu *menu, MenuItem *item); @@ -138,6 +139,7 @@ private: QAction *actionDetailedInfo; QAction *actionTopMost; + QAction *actionMove; QAction *actionShell; QAction *actionControlPanel; QAction *actionScreenShot; diff --git a/tizen/src/ui/menu/menuitem.h b/tizen/src/ui/menu/menuitem.h index f5dcea1c4e..f7859ebb12 100644 --- a/tizen/src/ui/menu/menuitem.h +++ b/tizen/src/ui/menu/menuitem.h @@ -41,6 +41,7 @@ namespace MenuItemType advancedItem, infoItem, onTopItem, + moveItem, switchItem, scaleItem, controllerItem, diff --git a/tizen/src/ui/resource/ui_strings.h b/tizen/src/ui/resource/ui_strings.h index ee64927598..99b17e2226 100644 --- a/tizen/src/ui/resource/ui_strings.h +++ b/tizen/src/ui/resource/ui_strings.h @@ -72,6 +72,7 @@ /* context menu */ #define MENU_ONTOP_ITEM_TEXT "Always on Top" +#define MENU_MOVE_ITEM_TEXT "Move" #define MENU_SWITCH_ITEM_TEXT "Switch" #define MENU_SCALE_ITEM_TEXT "Scale" #define MENU_CONTROLLER_ITEM_TEXT "Controller" diff --git a/tizen/src/ui/transwidget.cpp b/tizen/src/ui/transwidget.cpp new file mode 100644 index 0000000000..7a0777992c --- /dev/null +++ b/tizen/src/ui/transwidget.cpp @@ -0,0 +1,108 @@ +/* + * Qt UI + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jihye Won + * GiWoong Kim + * SeokYeon Hwang + * Sangho Park + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include "transwidget.h" +#include +#include +#include "mainwindow.h" + +TransWidget::TransWidget(QWidget *parent) : QWidget(parent) +{ + qDebug("transparent widget is created."); + +#if defined(CONFIG_DARWIN) + setWindowFlags(Qt::Window); + setWindowFlags(Qt::FramelessWindowHint); +#elif defined(CONFIG_LINUX) + setWindowFlags(Qt::FramelessWindowHint); +#endif + + setAttribute(Qt::WA_NoSystemBackground); + setAttribute(Qt::WA_TranslucentBackground); + setAttribute(Qt::WA_DeleteOnClose); + resize(parent->size()); + qDebug() << "transparent widget size: " << parent->size(); + installEventFilter(this); + isGrab = false; +} + +/* override */ +bool TransWidget::eventFilter(QObject *obj, QEvent *event) +{ + TransWidget *widget = dynamic_cast(obj); + + if (widget != NULL) { + + QMouseEvent *mouseEvent = dynamic_cast(event); + if (mouseEvent == NULL) { + return QObject::eventFilter(obj, event); + } + + MainWindow *parent = qobject_cast(this->parent()); + if (parent == NULL) { + qWarning() << "parent object(MainWindow) is null."; + return QObject::eventFilter(obj, event); + } + + if (event->type() == QEvent::MouseButtonPress) { + if (mouseEvent->button() == Qt::LeftButton) { + isGrab = true; + grabPos = parent->mapToGlobal(QPoint(0,0)) - mouseEvent->globalPos(); + } + if (mouseEvent->button() == Qt::RightButton) { + mouseEvent->ignore(); /* filtering */ + return true; + } + } else if (event->type() == QEvent::MouseMove) { + if(isGrab == true) { + parent->move(mouseEvent->globalPos() + grabPos); + } + } else if (event->type() == QEvent::MouseButtonRelease) { + qDebug() << "The position of the emulator: " << this->mapToGlobal(QPoint(0,0)); + close(); + return true; + } + } + + return QObject::eventFilter(obj, event); +} + +TransWidget::~TransWidget() +{ + qDebug("destroy transparent widget"); + removeEventFilter(this); + MainWindow *parent = qobject_cast(this->parent()); + if (parent == NULL) { + qWarning() << "parent object(MainWindow) is null."; + } else { + parent->setTransWidget(NULL); + } +} diff --git a/tizen/src/ui/transwidget.h b/tizen/src/ui/transwidget.h new file mode 100644 index 0000000000..033c5c7a7c --- /dev/null +++ b/tizen/src/ui/transwidget.h @@ -0,0 +1,50 @@ +/* + * Qt UI + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jihye Won + * GiWoong Kim + * SeokYeon Hwang + * Sangho Park + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef TRANSWIDGET_H +#define TRANSWIDGET_H + +#include +#include + +class TransWidget : public QWidget +{ +public: + explicit TransWidget(QWidget *parent = 0); + ~TransWidget(); + bool isGrab; + QPoint grabPos; + +protected: + bool eventFilter(QObject *obj, QEvent *event); +}; + +#endif // TRANSWIDGET_H diff --git a/tizen/src/ui/xmllayoutkeyword.h b/tizen/src/ui/xmllayoutkeyword.h index dd84f762c6..996ed5ed32 100644 --- a/tizen/src/ui/xmllayoutkeyword.h +++ b/tizen/src/ui/xmllayoutkeyword.h @@ -70,6 +70,7 @@ #define ADVANCED_MENU_KEYWORD "advancedItem" #define INFO_MENU_KEYWORD "infoItem" #define ONTOP_MENU_KEYWORD "onTopItem" +#define MOVE_MENU_KEYWORD "moveItem" #define SWITCH_MENU_KEYWORD "switchItem" #define SCALE_MENU_KEYWORD "scaleItem" #define CONTROLLER_MENU_KEYWORD "controllerItem" diff --git a/tizen/src/ui/xmllayoutparser.cpp b/tizen/src/ui/xmllayoutparser.cpp index c5bc763de4..485d6dc993 100644 --- a/tizen/src/ui/xmllayoutparser.cpp +++ b/tizen/src/ui/xmllayoutparser.cpp @@ -459,74 +459,38 @@ int XmlLayoutParser::parseMenuList( if (token == QXmlStreamReader::StartElement) { if (xml.name() == SEPARATOR_MENU_KEYWORD) { item = new MenuItem(MenuItemType::separator, NULL); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == ADVANCED_MENU_KEYWORD) { item = (MenuItem *)parseAdvancedMenuItem(xml); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == INFO_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::infoItem); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == ONTOP_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::onTopItem); - if (item != NULL) { - list.append(item); - } + } else if (xml.name() == MOVE_MENU_KEYWORD) { + item = parseGeneralMenuItem(xml, MenuItemType::moveItem); } else if (xml.name() == SWITCH_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::switchItem); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == SCALE_MENU_KEYWORD) { item = (MenuItem *)parseScaleMenuItem(xml); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == CONTROLLER_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::controllerItem); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == HOSTKBD_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::hostKeyboardItem); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == SHELL_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::shellItem); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == ECP_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::controlPanelItem); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == SCREENSHOT_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::screenShotItem); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == ABOUT_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::aboutItem); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == FORCECLOSE_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::forceCloseItem); - if (item != NULL) { - list.append(item); - } } else if (xml.name() == CLOSE_MENU_KEYWORD) { item = parseGeneralMenuItem(xml, MenuItemType::closeItem); - if (item != NULL) { - list.append(item); - } + } + + if (item != NULL) { + list.append(item); } } -- 2.34.1