menu: controller can connected to the menu action 23/25623/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Thu, 7 Aug 2014 10:09:33 +0000 (19:09 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Thu, 7 Aug 2014 10:19:22 +0000 (19:19 +0900)
Change-Id: Idd67931bb1bc410424a0f56523f83750ff196386
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/controllerwidget.cpp
tizen/src/ui/controllerwidget.h
tizen/src/ui/mainwindow.cpp
tizen/src/ui/mainwindow.h
tizen/src/ui/menu/aboutdialog.h
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h
tizen/src/ui/uistate.cpp
tizen/src/ui/uistate.h

index b60cddb90ef9229e5e0467e790d39187518e3384..f3b3867b549614956d39735c32d5b87a90f4263e 100644 (file)
@@ -1,11 +1,13 @@
 #include <QtWidgets>
 
 #include "controllerwidget.h"
+#include "mainwindow.h"
 
-ControllerWidget::ControllerWidget(ControllerForm *conForm, QWidget *parent) :
-    QDialog(parent)
+ControllerWidget::ControllerWidget(ControllerForm *conForm,
+    QAction *menu, QWidget *parent) : QDialog(parent)
 {
     this->conForm = conForm;
+    this->menu = menu;
 
     setStyleSheet("border-style: none");
     setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
@@ -26,9 +28,17 @@ ControllerWidget::ControllerWidget(ControllerForm *conForm, QWidget *parent) :
 
 void ControllerWidget::showEvent(QShowEvent *event)
 {
+    menu->setChecked(true);
     setRegion(conForm->conImg[ControllerForm::normal]);
 }
 
+void ControllerWidget::closeEvent(QCloseEvent *event) {
+    menu->setChecked(false);
+
+    MainWindow *win = ((MainWindow *)this->parent());
+    win->getUIState()->activatedCon = NULL;
+}
+
 void ControllerWidget::setRegion(QImage baseImage)
 {
     //qDebug("set region");
index 36b5a29b4488ccc8c343f45e2e61136e1ac7c29d..fb8a006551dbb392a9a91b60c9d86c165ba99bd5 100644 (file)
@@ -11,17 +11,19 @@ class ControllerWidget : public QDialog
     Q_OBJECT
 
 public:
-    explicit ControllerWidget(ControllerForm *conForm, QWidget *parent = 0);
+    explicit ControllerWidget(ControllerForm *conForm, QAction *menu, QWidget *parent = 0);
     ~ControllerWidget();
 
 protected:
     void showEvent(QShowEvent *event);
+    void closeEvent(QCloseEvent *event);
 
     void setRegion(QImage baseImage);
 
 private:
     SkinControllerView *conView;
     ControllerForm *conForm;
+    QAction *menu;
 };
 
 #endif // CONTROLLERWIDGET_H
index 6c7fff83ffb043cbebe0368e3093830af58e022e..3a025ee5a3555e0cac1a5877a18ed0d64858a2fd 100644 (file)
@@ -1,5 +1,3 @@
-#include <QtWidgets>
-
 #include "mainwindow.h"
 #include "skinform.h"
 
@@ -60,7 +58,6 @@ MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
     skinView = NULL;
     display = NULL;
     conView = NULL;
-    con = NULL;
 
     /* windowing */
     setWindowTitle("Emulator");
@@ -164,7 +161,7 @@ UIState *MainWindow::getUIState()
 
 ControllerWidget *MainWindow::getController()
 {
-    return con;
+    return getUIState()->activatedCon;
 }
 
 void MainWindow::openController(int index)
@@ -179,20 +176,20 @@ void MainWindow::openController(int index)
     }
 
     ControllerForm *conForm = uiInfo->controllerList.at(index);
-    con = new ControllerWidget(conForm, this);
+    QAction *action = (QAction *)popupMenu->getControllerMapper()->mapping(index);
+    getUIState()->activatedCon = new ControllerWidget(conForm, action, this);
 
     QPoint globalPos = mapToGlobal(QPoint(0, 0));
-    con->move(globalPos.x() + size().width(), globalPos.y());
-    con->show();
+    getUIState()->activatedCon->move(globalPos.x() + size().width(), globalPos.y());
+    getUIState()->activatedCon->show();
 }
 
 void MainWindow::closeController()
 {
-    if (con != NULL) {
+    if (getUIState()->activatedCon != NULL) {
         qDebug("close controller");
 
-        con->close();
-        con = NULL;
+        getUIState()->activatedCon->close();
     }
 }
 
index 71cda0c7b31a180a5644ac01d158cacd336436c7..0aa90a15d3c211c0f8843d5f4bb7dde4dda48205 100644 (file)
@@ -64,10 +64,10 @@ public slots:
 
 protected:
     void resizeEvent(QResizeEvent *event);
+    void closeEvent(QCloseEvent *);
 
     void updateSkin();
     void setRegion(QImage baseImage);
-    void closeEvent(QCloseEvent *);
     QLabel *label;
 
 private:
@@ -78,8 +78,6 @@ private:
     SkinControllerView *conView;
     QThread *swapperThread;
     DisplaySwapper *swapper;
-
-    ControllerWidget *con;
 };
 
 #endif // MAINWINDOW_H
index 36a3e5affd2ae7d1f966149b1fade70fb631ecc3..57e314f9a6bf9e015857cb068c34707748a349c8 100644 (file)
@@ -6,6 +6,7 @@
 class AboutDialog : public QDialog
 {
     Q_OBJECT
+
 public:
     explicit AboutDialog(QWidget *parent = 0);
     ~AboutDialog();
index 312b32cd3fa6e240e5948dcfcbf7558e29d58ab4..890e7c05032182029747dcda80e0c0767183d15d 100644 (file)
@@ -25,7 +25,7 @@ ContextMenu::ContextMenu(QWidget *parent) :
     /* = Rotate menu = */
     QMenu *rotateMenu = addMenu(QIcon(QPixmap(":/icons/rotate.png")), "Rotate");
     QActionGroup *rotateGroup = new QActionGroup(this);
-    QSignalMapper *rotateMapper = new QSignalMapper(this);
+    rotateMapper = new QSignalMapper(this);
     connect(rotateMapper, SIGNAL(mapped(int)), this, SLOT(slotRotate(int)));
 
     action = rotateMenu->addAction("Portrait");
@@ -59,13 +59,12 @@ ContextMenu::ContextMenu(QWidget *parent) :
     /* = Scale menu = */
     QMenu *scaleMenu = addMenu(QIcon(QPixmap(":/icons/scale.png")), "Scale");
     QActionGroup *scaleGroup = new QActionGroup(this);
-    QSignalMapper *scaleMapper = new QSignalMapper(this);
+    scaleMapper = new QSignalMapper(this);
     connect(scaleMapper, SIGNAL(mapped(int)), this, SLOT(slotScale(int)));
 
     action = scaleMenu->addAction("1x");
     action->setActionGroup(scaleGroup);
     action->setCheckable(true);
-    //action->setChecked(true); /* default */
     scaleMapper->setMapping(action, 100);
     connect(action, SIGNAL(triggered()), scaleMapper, SLOT(map()));
 
@@ -100,7 +99,7 @@ ContextMenu::ContextMenu(QWidget *parent) :
     if (win->uiInfo->controllerList.isEmpty() == false) {
         controllerMenu = addMenu("Controller");
         QActionGroup *controllerGroup = new QActionGroup(this);
-        QSignalMapper *controllerMapper = new QSignalMapper(this);
+        controllerMapper = new QSignalMapper(this);
         connect(controllerMapper, SIGNAL(mapped(int)), this, SLOT(slotController(int)));
 
         for (int i = 0; i < win->uiInfo->controllerList.count(); i++) {
@@ -110,9 +109,6 @@ ContextMenu::ContextMenu(QWidget *parent) :
             controllerMapper->setMapping(action, i);
             connect(action, SIGNAL(triggered()), controllerMapper, SLOT(map()));
         }
-
-        action = (QAction *)controllerMapper->mapping(0);
-        action->setChecked(true);
     }
 
     /* = Advanced menu = */
@@ -365,6 +361,21 @@ void ContextMenu::slotClose()
     this->longPressTimer->start();
 }
 
+QSignalMapper *ContextMenu::getRotateMapper()
+{
+    return rotateMapper;
+}
+
+QSignalMapper *ContextMenu::getScaleMapper()
+{
+    return scaleMapper;
+}
+
+QSignalMapper *ContextMenu::getControllerMapper()
+{
+    return controllerMapper;
+}
+
 ContextMenu::~ContextMenu()
 {
     qDebug("destroy menu");
index 0bfeeab62bf61643753b33e48b4a09e2b2830ea4..0034d451a34ec3b9d0e41a4cdd2ae04ec944a71f 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef CONTEXTMENU_H
 #define CONTEXTMENU_H
 
-#include <QMenu>
-#include <QTimer>
+#include <QtWidgets>
+
 #include "detailedinfodialog.h"
 #include "aboutdialog.h"
 
@@ -22,6 +22,10 @@ public:
     explicit ContextMenu(QWidget *parent = 0);
     ~ContextMenu();
 
+    QSignalMapper *getRotateMapper();
+    QSignalMapper *getScaleMapper();
+    QSignalMapper *getControllerMapper();
+
 signals:
 
 public slots:
@@ -41,5 +45,9 @@ private:
     QTimer *longPressTimer;
     DetailedInfoDialog *infoDialog;
     AboutDialog *aboutDialog;
+
+    QSignalMapper *rotateMapper;
+    QSignalMapper *scaleMapper;
+    QSignalMapper *controllerMapper;
 };
 #endif // CONTEXTMENU_H
index 0928bae8ab5ccaf109a45c15b2450c008c3db63e..e187b5b793dfff03e26b159ccb025ab02cac09dd 100644 (file)
@@ -3,6 +3,7 @@
 UIState::UIState() :
     formAngle(0), formScale(100)
 {
+    activatedCon = NULL;
 }
 
 int UIState::getFormIndex(int angle)
index f556df5eb0c95483891ffe498be5e077c9878de4..e466d51f14b9cb0e08341dbb9e64cacf36aaa0c9 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <QtWidgets>
 
+#include "controllerwidget.h"
+
 class UIState
 {
 public:
@@ -14,7 +16,8 @@ public:
     qreal getScaleFactor(); /* current */
 
     int formAngle;
-    int formScale;
+    int formScale; /* percentage */
+    ControllerWidget *activatedCon;
 };
 
 #endif // UISTATE_H