Qt: add a "Move" function to move an emulator
authorJihye Won <jihye.won1@samsung.com>
Wed, 7 Oct 2015 09:18:00 +0000 (18:18 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 19 Oct 2015 06:20:53 +0000 (15:20 +0900)
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 <jihye.won1@samsung.com>
tizen/src/ui/Makefile.objs
tizen/src/ui/mainwindow.cpp
tizen/src/ui/mainwindow.h
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h
tizen/src/ui/menu/menuitem.h
tizen/src/ui/resource/ui_strings.h
tizen/src/ui/transwidget.cpp [new file with mode: 0644]
tizen/src/ui/transwidget.h [new file with mode: 0644]
tizen/src/ui/xmllayoutkeyword.h
tizen/src/ui/xmllayoutparser.cpp

index 830894104f2e34864155c44cb911e44b06462fa5..6b912b06d5673dbf2ce9bf192d7a59ed0d4ab8e0 100644 (file)
@@ -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
index 074070436e0f9f44610bcc620d80f3f6af3102c3..729c026c08ba7fc426b20561a9e988c030805c6b 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact:
+ * Jihye Won <jihye.won1@samsung.com>
  * Hyunjin Lee <hyunjin816.lee@samsung.com>
  * SungMin Ha <sungmin82.ha@samsung.com>
  * GiWoong Kim <giwoong.kim@samsung.com>
@@ -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;
+}
+
index a28c207b8bbe0814fa5dd6fb31b2994b334fbee6..0a8c99cc12765eca292eda7b5ea40c4cce747ea8 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact:
+ * Jihye Won <jihye.won1@samsung.com>
  * Hyunjin Lee <hyunjin816.lee@samsung.com>
  * SungMin Ha <sungmin82.ha@samsung.com>
  * GiWoong Kim <giwoong.kim@samsung.com>
@@ -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
index e7adef375a275a2086a0ac58f891150af5203535..44c51002241e6c4af79ad5e41f20989e132e1e1c 100644 (file)
@@ -106,6 +106,10 @@ void ContextMenu::createItems(QMenu *menu, QList<MenuItem *> &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<QString, QKeySequence> 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);
index e19f5114dfe869b65dfa3cacd18cfe72dcf80cf8..83e0772569b7c0863d0bd31bfbbd7aee804addb6 100644 (file)
@@ -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;
index f5dcea1c4e4f41975f510426c03f96c6ab520bc7..f7859ebb12172e76d80e897c7a387cd43bf9dafc 100644 (file)
@@ -41,6 +41,7 @@ namespace MenuItemType
         advancedItem,
         infoItem,
         onTopItem,
+        moveItem,
         switchItem,
         scaleItem,
         controllerItem,
index ee649275988c42e7edacab6f504e1f1be0ce3fc4..99b17e22269efec5cb9e96691714806e715c7fbf 100644 (file)
@@ -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 (file)
index 0000000..7a07779
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jihye Won <jihye.won1@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho.p@samsung.com>
+ *
+ * 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 <QDesktopWidget>
+#include <QMouseEvent>
+#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<TransWidget *>(obj);
+
+    if (widget != NULL) {
+
+        QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(event);
+        if (mouseEvent == NULL) {
+            return QObject::eventFilter(obj, event);
+        }
+
+        MainWindow *parent = qobject_cast<MainWindow*>(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<MainWindow*>(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 (file)
index 0000000..033c5c7
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Jihye Won <jihye.won1@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho.p@samsung.com>
+ *
+ * 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 <QWidget>
+#include <QEvent>
+
+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
index dd84f762c6b0c69d9237dfb39e360f3e5e4e4630..996ed5ed325f726d967f08985779fa193ee1022d 100644 (file)
@@ -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"
index c5bc763de486d32b21579b5cc74421734a26949c..485d6dc993ba940e1b9b34b8b536055fa91c3542 100644 (file)
@@ -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);
             }
         }