From cd433418a715611ea692db3432458a67d962b15e Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Fri, 15 Jan 2016 16:47:28 +0900 Subject: [PATCH] menu: refactoring for Move function - cancel the moving mode before the layout changing - use override functions instead of event filter - delete unnecessary functions - modify function and variable names Change-Id: I0e97f3c9816ab4f107796bba0616a6ab590184ff Signed-off-by: GiWoong Kim --- tizen/src/ui/mainwindow.cpp | 33 +++++++------ tizen/src/ui/mainwindow.h | 3 +- tizen/src/ui/menu/contextmenu.cpp | 5 +- tizen/src/ui/transwidget.cpp | 82 ++++++++++++++----------------- tizen/src/ui/transwidget.h | 15 ++++-- 5 files changed, 66 insertions(+), 72 deletions(-) diff --git a/tizen/src/ui/mainwindow.cpp b/tizen/src/ui/mainwindow.cpp index 1035ebf770..2f25c16f60 100644 --- a/tizen/src/ui/mainwindow.cpp +++ b/tizen/src/ui/mainwindow.cpp @@ -428,6 +428,9 @@ void MainWindow::switchForm(int index) { qDebug("window switch: %d", index); + /* terminate the moving mode */ + destroyTransWidget(); + /* cancel HW key shortcuts */ keyboardShortcut->cancelHwKeyShortcuts(uiInfo->getMainForm()->getKeyList()); @@ -462,6 +465,9 @@ void MainWindow::scaleForm(int scale) { qDebug("window scale: %d", scale); + /* terminate the moving mode */ + destroyTransWidget(); + /* scale changing */ getUiState()->setScalePct(scale); @@ -576,31 +582,26 @@ void MainWindow::closeEvent(QCloseEvent *event) /* emulator move function */ void MainWindow::createTransWidget() { - qDebug("create transparent widget"); + qDebug("enter the moving mode"); - if (this->uiInfo == NULL) { - qWarning("UiInfo object is null."); - return; + if (isTransWidgetCreated() == false) { + transWidget = new TransWidget(this); } - this->transWidget = new TransWidget(this); - this->transWidget->show(); + transWidget->show(); } -void MainWindow::setTransWidget(TransWidget *widget) +void MainWindow::destroyTransWidget() { - this->transWidget = widget; -} + qDebug("leave the moving mode"); -TransWidget *MainWindow::getTransWidget() -{ - return this->transWidget; + if (isTransWidgetCreated() == true) { + transWidget->close(); + transWidget = NULL; + } } bool MainWindow::isTransWidgetCreated() { - if (this->transWidget == NULL) { - return false; - } - return true; + return (transWidget != NULL); } diff --git a/tizen/src/ui/mainwindow.h b/tizen/src/ui/mainwindow.h index 24a15a879a..2178ec72b4 100644 --- a/tizen/src/ui/mainwindow.h +++ b/tizen/src/ui/mainwindow.h @@ -83,8 +83,7 @@ public: /* emulator move function */ void createTransWidget(); - void setTransWidget(TransWidget *widget); - TransWidget *getTransWidget(); + void destroyTransWidget(); bool isTransWidgetCreated(); public slots: diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index 5f8a5ae4e4..dc32443223 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -705,10 +705,7 @@ void ContextMenu::slotOnTopShortcut() void ContextMenu::slotMove() { - if (parent->getTransWidget() == NULL) { - parent->createTransWidget(); - parent->getTransWidget()->setCursor(Qt::SizeAllCursor); - } + parent->createTransWidget(); } void ContextMenu::slotSwitch(int index) diff --git a/tizen/src/ui/transwidget.cpp b/tizen/src/ui/transwidget.cpp index 88becb6b2e..592ddcbfa8 100644 --- a/tizen/src/ui/transwidget.cpp +++ b/tizen/src/ui/transwidget.cpp @@ -30,75 +30,65 @@ */ #include "transwidget.h" -#include -#include #include "mainwindow.h" TransWidget::TransWidget(QWidget *parent) : QWidget(parent) { - qDebug("transparent widget is created."); + this->win = (MainWindow *)parent; + this->isGrab = false; -#if defined(CONFIG_DARWIN) - setWindowFlags(Qt::Window); - setWindowFlags(Qt::FramelessWindowHint); -#elif defined(CONFIG_LINUX) +#ifndef CONFIG_WIN32 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; + + resize(win->size()); + qDebug() << "transparent widget size:" << win->size(); + + setCursor(Qt::SizeAllCursor); } /* override */ -bool TransWidget::eventFilter(QObject *obj, QEvent *event) +void TransWidget::mousePressEvent(QMouseEvent *event) { - TransWidget *widget = dynamic_cast(obj); - if (widget == NULL) { - return QObject::eventFilter(obj, event); - } + QWidget::mousePressEvent(event); - QMouseEvent *mouseEvent = dynamic_cast(event); - if (mouseEvent == NULL) { - return QObject::eventFilter(obj, event); + if (event->button() == Qt::LeftButton) { + isGrab = true; + grabPos = event->pos(); + } else { + qDebug("cancel the moving mode"); + win->destroyTransWidget(); } +} - MainWindow *parent = qobject_cast(this->parent()); - if (parent == NULL) { - qWarning() << "parent object(MainWindow) is null."; - return QObject::eventFilter(obj, event); - } +/* override */ +void TransWidget::mouseReleaseEvent(QMouseEvent *event) +{ + QWidget::mouseReleaseEvent(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; - } + qDebug() << "window position:" << win->pos(); - return QObject::eventFilter(obj, event); + isGrab = false; + win->destroyTransWidget(); +} + +/* override */ +void TransWidget::mouseMoveEvent(QMouseEvent *event) +{ + QWidget::mouseMoveEvent(event); + + if (isGrab == true) { + win->move(event->globalPos() - grabPos); + } } TransWidget::~TransWidget() { qDebug("destroy transparent widget"); - removeEventFilter(this); - MainWindow *parent = (MainWindow *)(this->parent()); - parent->setTransWidget(NULL); + + /* do nothing */ } diff --git a/tizen/src/ui/transwidget.h b/tizen/src/ui/transwidget.h index 033c5c7a7c..e69dabf3b2 100644 --- a/tizen/src/ui/transwidget.h +++ b/tizen/src/ui/transwidget.h @@ -35,16 +35,23 @@ #include #include +class MainWindow; + class TransWidget : public QWidget { public: - explicit TransWidget(QWidget *parent = 0); + explicit TransWidget(QWidget *parent); ~TransWidget(); - bool isGrab; - QPoint grabPos; protected: - bool eventFilter(QObject *obj, QEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + +private: + MainWindow *win; + bool isGrab; + QPoint grabPos; }; #endif // TRANSWIDGET_H -- 2.34.1