controller: draw a docking guide line 85/29385/2
authorGiWoong Kim <giwoong.kim@samsung.com>
Tue, 14 Oct 2014 01:56:13 +0000 (10:56 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Tue, 28 Oct 2014 08:11:01 +0000 (01:11 -0700)
Emulator draws a guide line for docking when controller
has available position. And the dockable rules were
modified to enhance docking feature.

Change-Id: I271c26a3d5fc3fe15cf3a7e0b7004fd7ad164f0a
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/dockingconview.cpp
tizen/src/ui/floatingconview.cpp
tizen/src/ui/floatingconview.h

index 81919de2648948ece34a075911e7f13d48d094aa..dee2b3f1b5873f3c360204bb740bfe41c4fb91c7 100644 (file)
@@ -81,6 +81,7 @@ void DockingConView::mousePressEvent(QMouseEvent *event)
     QGraphicsView::mousePressEvent(event);
 
     if (bezelItem->isKeyHandling() == true) {
+        /* do nothing */
         return;
     }
 
@@ -104,6 +105,7 @@ void DockingConView::mouseReleaseEvent(QMouseEvent *event)
     QGraphicsView::mouseReleaseEvent(event);
 
     if (bezelItem->isKeyHandling() == true) {
+        /* do nothing */
         return;
     }
 
@@ -128,10 +130,11 @@ void DockingConView::mouseMoveEvent(QMouseEvent *event)
     QGraphicsView::mouseMoveEvent(event);
 
     if (bezelItem->isKeyHandling() == true) {
+        /* do nothing */
         return;
     }
 
-    if (grabPos != QPoint(-1, -1)) {
+    if (grabPos != QPoint(-1, -1) && rubberBand != NULL) {
         rubberBand->setGeometry(
             QRect(rubberPos + (event->globalPos() - grabPos), size()));
     }
index ca1c6b22191ba8ab1e483151fd81737cc0337236..a6572dcbad201f5771cf9d00895ef35043ec6989 100644 (file)
@@ -47,6 +47,7 @@ FloatingConView::FloatingConView(ControllerForm *conForm, QGraphicsScene *scene,
 
     conPos = QPoint(-1, -1);
     grabPos = QPoint(-1, -1);
+    rubberBand = new QRubberBand(QRubberBand::Rectangle, NULL);
 
     createItems(conForm);
 }
@@ -103,12 +104,32 @@ int FloatingConView::isDockable(QWidget *object, QWidget *subject)
         DOCKABLE_AREA_WIDTH,
         subject->size().height());
 
-    if (rectTarget.intersects(rectDockableRC) == true) {
-        return Qt::AlignRight | Qt::AlignCenter;
-    } else if (rectTarget.intersects(rectDockableRT) == true) {
-        return Qt::AlignRight | Qt::AlignTop;
-    } else if (rectTarget.intersects(rectDockableRB) == true) {
-        return Qt::AlignRight | Qt::AlignBottom;
+    // TODO: define recursive function
+    QRect interRC = rectTarget.intersected(rectDockableRC);
+    QRect interRT = rectTarget.intersected(rectDockableRT);
+    QRect interRB = rectTarget.intersected(rectDockableRB);
+
+    QRect *interBiggest = NULL;
+
+    if ((interRC.width() * interRC.height()) < (interRT.width() * interRT.height())) {
+        interBiggest = &interRT;
+    } else {
+        interBiggest = &interRC;
+    }
+
+    if ((interBiggest->width() * interBiggest->height()) < (interRB.width() * interRB.height())) {
+        interBiggest = &interRB;
+    }
+
+    if (interBiggest != NULL &&
+        interBiggest->isNull() == false && interBiggest->isEmpty() == false) {
+        if (interBiggest == &interRC) {
+            return Qt::AlignRight | Qt::AlignCenter;
+        } else if (interBiggest == &interRT) {
+            return Qt::AlignRight | Qt::AlignTop;
+        } else if (interBiggest == &interRB) {
+            return Qt::AlignRight | Qt::AlignBottom;
+        }
     }
 
     return -1;
@@ -119,6 +140,7 @@ void FloatingConView::mousePressEvent(QMouseEvent *event)
     QGraphicsView::mousePressEvent(event);
 
     if (bezelItem->isKeyHandling() == true) {
+        /* do nothing */
         return;
     }
 
@@ -133,20 +155,23 @@ void FloatingConView::mouseReleaseEvent(QMouseEvent *event)
     QGraphicsView::mouseReleaseEvent(event);
 
     if (bezelItem->isKeyHandling() == true) {
+        /* do nothing */
         return;
     }
 
     if (event->button() == Qt::LeftButton) {
         grabPos = QPoint(-1, -1);
+        if (rubberBand != NULL) {
+            rubberBand->hide();
+        }
     }
 
-    QWidget *con = ((QWidget *)parent);
-    QWidget *dst = ((QWidget *)con->parent());
+    const FloatingController *con = parent;
+    MainWindow *win = ((MainWindow *)con->parent());
 
-    int dockPos = isDockable(dst, con);
+    int dockPos = isDockable((QWidget *)win, (QWidget *)parent);
     if (dockPos != -1) {
         /* toggle */
-        MainWindow *win = (MainWindow *)dst;
         win->openController(win->getUIState()->conState.conFormIndex, dockPos);
         return;
     }
@@ -157,10 +182,37 @@ void FloatingConView::mouseMoveEvent(QMouseEvent *event)
     QGraphicsView::mouseMoveEvent(event);
 
     if (bezelItem->isKeyHandling() == true) {
+        /* do nothing */
         return;
     }
 
     if (grabPos != QPoint(-1, -1)) {
+        /* draw guide for dockable position */
+        const FloatingController *con = parent;
+        MainWindow *win = ((MainWindow *)con->parent());
+
+        if (rubberBand != NULL) {
+            int dockPos = isDockable((QWidget *)win, (QWidget *)con);
+            if (dockPos != -1) {
+                int vShift = 0;
+
+                if (win->size().height() > size().height()) {
+                    if (dockPos & Qt::AlignCenter) {
+                        vShift = (win->size().height() / 2) - (size().height() / 2);
+                    } else if (dockPos & Qt::AlignBottom) {
+                        vShift = win->size().height() - size().height();
+                    }
+                }
+
+                QPoint rubberPos(win->pos().x() + win->size().width(),
+                    win->pos().y() + vShift);
+                rubberBand->setGeometry(QRect(rubberPos, size()));
+                rubberBand->show();
+            } else {
+                rubberBand->hide();
+            }
+        }
+
         parent->move(conPos + (event->globalPos() - grabPos));
     }
 }
@@ -168,4 +220,10 @@ void FloatingConView::mouseMoveEvent(QMouseEvent *event)
 FloatingConView::~FloatingConView()
 {
     qDebug("destroy floating controller view");
+
+    if (rubberBand != NULL) {
+        rubberBand->close();
+        delete rubberBand;
+        rubberBand = NULL;
+    }
 }
index 71ef154bb30119bfe27b380b0829ad9c9c3eedbe..f2e996f46855f5e1bd2e4482ab596d70fc72db09 100644 (file)
@@ -30,6 +30,8 @@
 #ifndef FLOATINGCONVIEW_H
 #define FLOATINGCONVIEW_H
 
+#include <QRubberBand>
+
 #include "skinview.h"
 #include "skinbezelitem.h"
 #include "controllerform.h"
@@ -58,6 +60,7 @@ private:
 
     FloatingController *parent;
     SkinBezelItem *bezelItem;
+    QRubberBand *rubberBand;
 };
 
 #endif // FLOATINGCONVIEW_H