gui: prevent moving to position out of monitor range
authorGiWoong Kim <giwoong.kim@samsung.com>
Mon, 11 Jan 2016 06:42:34 +0000 (15:42 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 13 Jan 2016 01:21:26 +0000 (10:21 +0900)
Change-Id: I755b7d8700e99fd3f4f1889159113e32a8ceb1dc
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/mainwindow.cpp

index aa2120eb0bca010b1d32aaf2835f369081fd7b5f..aea516a6131f78de8a510de90f79116f9ce560b3 100644 (file)
@@ -36,6 +36,7 @@
 #include "displayglwidget.h"
 #include "displayswwidget.h"
 #include "resource/ui_strings.h"
+#include "uiutil.h"
 
 extern "C" {
 #include "util/ui_operations.h"
@@ -363,6 +364,11 @@ void MainWindow::closeController()
 /* override */
 void MainWindow::resize(const QSize &size)
 {
+    if (size.width() <= 0 || size.height() <= 0) {
+        qWarning() << "Invalid scale size. Cannot be less than zero." << size;
+        return;
+    }
+
     setFixedSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
     QWidget::resize(size);
 }
@@ -387,6 +393,17 @@ void MainWindow::resizeEvent(QResizeEvent *event)
 
     QWidget::resizeEvent(event);
     setFixedSize(size());
+
+    /* correctional position */
+    int xx = pos().x();
+    int yy = pos().y();
+    QRect hostBounds = UiUtil::getHostScreenBounds();
+    xx = qMax(xx, hostBounds.x());
+    yy = qMax(yy, hostBounds.y());
+    // shift a little bit from screen edge to inside of bounds
+    xx = qMin(xx, hostBounds.x() + hostBounds.width() - 100);
+    yy = qMin(yy, hostBounds.y() + hostBounds.height() - 100);
+    move(xx, yy);
 }
 
 /* override */