ui: add mouse handler to controller widget 83/25283/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Fri, 1 Aug 2014 09:29:59 +0000 (18:29 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Fri, 1 Aug 2014 09:29:59 +0000 (18:29 +0900)
desc

Change-Id: Ia815064d952151ac2eaad37178e5c73d64d26e4a
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/display/qt5_supplement.cpp
tizen/src/ui/controllerwidget.cpp
tizen/src/ui/controllerwidget.h
tizen/src/ui/mainwindow.cpp
tizen/src/ui/mainwindow.h
tizen/src/ui/skincontrollerview.cpp
tizen/src/ui/skincontrollerview.h
tizen/src/ui/skinview.cpp

index ed4409789d0e85f29da3c32e84eb793a51d9075c..54af3bef0c8806aa6e909ba7614bfeadd45b459c 100644 (file)
@@ -261,7 +261,9 @@ void loadControllerLayoutFromXML(QFile *file, UIInformation *uiInfo/* out */)
 
         ControllerLayout *layout = new ControllerLayout();
         layout->conImg[ControllerLayout::normal].load(
-                    fileInfo.absolutePath() + "/" + layoutType->mainImageName());
+            fileInfo.absolutePath() + "/" + layoutType->mainImageName());
+        layout->conImg[ControllerLayout::pressed].load(
+            fileInfo.absolutePath() + "/" + layoutType->pressedImageName());
 
         keyListType = layoutType->keyListType();
         if (keyListType != NULL) {
index 6ec8f31201d865207965fa925cf14f8b20170123..32f4f1a73ef8946f613db63be77b8af2a80b4cd6 100644 (file)
@@ -5,8 +5,12 @@
 ControllerWidget::ControllerWidget(ControllerLayout *conLayout, QWidget *parent) :
     QLabel(parent)
 {
+    //setStyleSheet("background: transparent");
     setStyleSheet("border-style: none");
 
+    setWindowFlags(Qt::FramelessWindowHint);
+    setAttribute(Qt::WA_TranslucentBackground);
+
     QHBoxLayout *layout = new QHBoxLayout(this);
     layout->setMargin(0);
     layout->setSpacing(0);
index f2e7863baf805dca3f2574e27fcf1fc7176e7ba8..ced9503a414aa411f13fb11c7ccbea5cc3ed85e9 100644 (file)
@@ -14,6 +14,8 @@ public:
     explicit ControllerWidget(ControllerLayout *conLayout, QWidget *parent = 0);
     ~ControllerWidget();
 
+protected:
+
 private:
     SkinControllerView *conView;
 };
index 38cc138cd9722d07e845d9bf6c38c54f46c88414..7cdce59b3f0669ff049a435664870f635bb5f451 100644 (file)
@@ -1,10 +1,7 @@
 #include <QtWidgets>
 
 #include "mainwindow.h"
-#include "displaywidget.h"
 #include "skinlayout.h"
-#include "skincontrollerview.h"
-#include "controllerwidget.h"
 
 QOpenGLContext *qt5GLContext = NULL;
 QSurfaceFormat qt5GLFormat;
@@ -47,6 +44,7 @@ void DisplaySwapper::swapBuffers()
     c.wakeAll();
 }
 
+
 MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
     QWidget(parent)
 {
@@ -62,6 +60,7 @@ MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
     skinView = NULL;
     display = NULL;
     conView = NULL;
+    con = NULL;
 
     /* windowing */
     setWindowTitle("Emulator");
@@ -69,21 +68,15 @@ MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
 
     //setStyleSheet("background:transparent;");
     //setAttribute(Qt::WA_TranslucentBackground);
-    //setWindowFlags(Qt::FramelessWindowHint);
+    setWindowFlags(Qt::FramelessWindowHint);
 
     QHBoxLayout *winLayout = new QHBoxLayout(this);
     winLayout->setMargin(0);
     winLayout->setSpacing(0);
-
     /* scene */
     QGraphicsScene* skinScene = new QGraphicsScene(this);
-
     /* view */
     skinView = new SkinView(skinScene, this);
-    skinView->setStyleSheet("background: transparent");
-    //skinView->setStyleSheet("border-style: none");
-    skinView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-    skinView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     winLayout->addWidget(skinView);
 
     if (uiInfo->controllerList.count() > 0) {
@@ -98,7 +91,7 @@ MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
 
         /* floated controller */
         ControllerLayout *conLayout = uiInfo->controllerList.at(0);
-        ControllerWidget *con = new ControllerWidget(conLayout);
+        con = new ControllerWidget(conLayout);
         con->show();
     }
 
@@ -133,6 +126,7 @@ MainWindow::MainWindow(UIInformation *uiInfo, QWidget *parent) :
     connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
             SLOT(showContextMenu(const QPoint&)));
 
+    /* swapper */
     swapperThread = new QThread(this);
 
     swapper = new DisplaySwapper(context);
@@ -162,11 +156,7 @@ void MainWindow::makeCurrent(bool value)
 
 void MainWindow::showContextMenu(const QPoint& pos)
 {
-    QPoint globalPos = this->mapToGlobal(pos);
-    // for QAbstractScrollArea and derived classes you would use:
-    // QPoint globalPos = myWidget->viewport()->mapToGlobal(pos);
-
-    QAction* selectedItem = popupMenu->exec(globalPos);
+    QAction* selectedItem = popupMenu->exec(mapToGlobal(pos));
     if (selectedItem) {
         //qDebug("%s", selectedItem->text().toLocal8Bit().data());
     } else {
@@ -179,6 +169,18 @@ UIState *MainWindow::getUIState()
     return &(uiInfo->uiState);
 }
 
+ControllerWidget *MainWindow::getController()
+{
+    return con;
+}
+
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+    qDebug("resize main window");
+
+    resize(skinView->size());
+}
+
 void MainWindow::rotate(int angle)
 {
     qDebug("window rotate : %d", angle);
@@ -187,6 +189,8 @@ void MainWindow::rotate(int angle)
 
     skinView->rotate();
     display->rotate(getUIState()->layoutAngle);
+
+    adjustSize();
 }
 
 void MainWindow::scale(int scale)
@@ -197,6 +201,8 @@ void MainWindow::scale(int scale)
 
     skinView->adjustSize();
     display->scale(getUIState()->layoutScale);
+
+    adjustSize();
 }
 
 void MainWindow::updateSkin() // TODO: temp
index ffc10916b9c289ab1e11a1a0ae5d169691ccfe35..3a4b2f544c6fce95b6bceb39a7059101e5ab010a 100644 (file)
@@ -9,6 +9,7 @@
 #include "skinbezelitem.h"
 #include "uiinformation.h"
 #include "skincontrollerview.h"
+#include "controllerwidget.h"
 
 extern "C" {
 #include "skin/maruskin_operation.h"
@@ -49,6 +50,7 @@ public:
     UIState *getUIState(void);
     void rotate(int angle);
     void scale(int scale);
+    ControllerWidget *getController();
 
     UIInformation *uiInfo;
     QLabel *getLabel();
@@ -60,6 +62,8 @@ public slots:
     void showContextMenu(const QPoint& pos);
 
 protected:
+    void resizeEvent(QResizeEvent *event);
+
     void updateSkin();
     void setRegion(QImage baseImage);
     void closeEvent(QCloseEvent *);
@@ -73,6 +77,8 @@ private:
     SkinControllerView *conView;
     QThread *swapperThread;
     DisplaySwapper *swapper;
+
+    ControllerWidget *con;
 };
 
 #endif // MAINWINDOW_H
index 73e762c2fa512b1a2b90cb0f28004f2296f31761..4f6dc2b8cf5445228838c996936a9a408afaf3e2 100644 (file)
@@ -6,12 +6,16 @@ SkinControllerView::SkinControllerView(ControllerLayout *conLayout, QGraphicsSce
     QGraphicsView(scene, parent)
 {
     setStyleSheet("background: transparent");
+    //setAttribute(Qt::WA_TranslucentBackground);
     setStyleSheet("border-style: none");
+
     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
     setAlignment(Qt::AlignLeft | Qt::AlignTop);
 
+    grabWinPos = QPoint(-1, -1);
+    grabPos = QPoint(-1, -1);
+
     createItems(conLayout);
 }
 
@@ -41,6 +45,37 @@ void SkinControllerView::resizeEvent(QResizeEvent *event)
     Q_UNUSED(event)
 }
 
+void SkinControllerView::mousePressEvent(QMouseEvent *event)
+{
+    if (event->button() == Qt::LeftButton) {
+        QWidget *win = ((QWidget *) this->parent());
+        grabWinPos = win->pos();
+        grabPos = event->globalPos();
+    }
+
+    QGraphicsView::mousePressEvent(event);
+}
+
+void SkinControllerView::mouseReleaseEvent(QMouseEvent *event)
+{
+    if (event->button() == Qt::LeftButton) {
+        grabPos = QPoint(-1, -1);
+    }
+
+    QGraphicsView::mouseReleaseEvent(event);
+}
+
+void SkinControllerView::mouseMoveEvent(QMouseEvent *event)
+{
+    QWidget *win = ((QWidget *)this->parent());
+
+    if (grabPos != QPoint(-1, -1)) {
+        win->move(grabWinPos + (event->globalPos() - grabPos));
+    }
+
+    QGraphicsView::mouseMoveEvent(event);
+}
+
 SkinControllerView::~SkinControllerView()
 {
     qDebug("destroy scontroller view");
index f9743f751a6fa8ce63310632bd2283c79455e5f5..c9e3c402915dba188825821be4f68386ebe8d8e1 100644 (file)
@@ -13,6 +13,13 @@ public:
 protected:
     void resizeEvent(QResizeEvent *event);
 
+    void mousePressEvent(QMouseEvent *event);
+    void mouseReleaseEvent(QMouseEvent *event);
+    void mouseMoveEvent(QMouseEvent *event);
+
+    QPoint grabWinPos;
+    QPoint grabPos;
+
 private:
     void createItems(ControllerLayout *conLayout);
 };
index c9be238b8eeddce39b706ff26f6554b967c43308..2e1e67407fd5ed1c1265b3b5a2e738aa83ecd6d8 100644 (file)
@@ -7,6 +7,10 @@
 SkinView::SkinView(QGraphicsScene *scene, QWidget *parent) :
     QGraphicsView(scene, parent)
 {
+    setStyleSheet("border-style: none");
+
+    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     setAlignment(Qt::AlignLeft | Qt::AlignTop);
 
     grabWinPos = QPoint(-1, -1);