From b554bae932fe509a25bd604b5af82f735fbc9714 Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Fri, 1 Aug 2014 18:29:59 +0900 Subject: [PATCH] ui: add mouse handler to controller widget desc Change-Id: Ia815064d952151ac2eaad37178e5c73d64d26e4a Signed-off-by: GiWoong Kim --- tizen/src/display/qt5_supplement.cpp | 4 ++- tizen/src/ui/controllerwidget.cpp | 4 +++ tizen/src/ui/controllerwidget.h | 2 ++ tizen/src/ui/mainwindow.cpp | 38 ++++++++++++++++------------ tizen/src/ui/mainwindow.h | 6 +++++ tizen/src/ui/skincontrollerview.cpp | 37 ++++++++++++++++++++++++++- tizen/src/ui/skincontrollerview.h | 7 +++++ tizen/src/ui/skinview.cpp | 4 +++ 8 files changed, 84 insertions(+), 18 deletions(-) diff --git a/tizen/src/display/qt5_supplement.cpp b/tizen/src/display/qt5_supplement.cpp index ed4409789d..54af3bef0c 100644 --- a/tizen/src/display/qt5_supplement.cpp +++ b/tizen/src/display/qt5_supplement.cpp @@ -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) { diff --git a/tizen/src/ui/controllerwidget.cpp b/tizen/src/ui/controllerwidget.cpp index 6ec8f31201..32f4f1a73e 100644 --- a/tizen/src/ui/controllerwidget.cpp +++ b/tizen/src/ui/controllerwidget.cpp @@ -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); diff --git a/tizen/src/ui/controllerwidget.h b/tizen/src/ui/controllerwidget.h index f2e7863baf..ced9503a41 100644 --- a/tizen/src/ui/controllerwidget.h +++ b/tizen/src/ui/controllerwidget.h @@ -14,6 +14,8 @@ public: explicit ControllerWidget(ControllerLayout *conLayout, QWidget *parent = 0); ~ControllerWidget(); +protected: + private: SkinControllerView *conView; }; diff --git a/tizen/src/ui/mainwindow.cpp b/tizen/src/ui/mainwindow.cpp index 38cc138cd9..7cdce59b3f 100644 --- a/tizen/src/ui/mainwindow.cpp +++ b/tizen/src/ui/mainwindow.cpp @@ -1,10 +1,7 @@ #include #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 diff --git a/tizen/src/ui/mainwindow.h b/tizen/src/ui/mainwindow.h index ffc10916b9..3a4b2f544c 100644 --- a/tizen/src/ui/mainwindow.h +++ b/tizen/src/ui/mainwindow.h @@ -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 diff --git a/tizen/src/ui/skincontrollerview.cpp b/tizen/src/ui/skincontrollerview.cpp index 73e762c2fa..4f6dc2b8cf 100644 --- a/tizen/src/ui/skincontrollerview.cpp +++ b/tizen/src/ui/skincontrollerview.cpp @@ -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"); diff --git a/tizen/src/ui/skincontrollerview.h b/tizen/src/ui/skincontrollerview.h index f9743f751a..c9e3c40291 100644 --- a/tizen/src/ui/skincontrollerview.h +++ b/tizen/src/ui/skincontrollerview.h @@ -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); }; diff --git a/tizen/src/ui/skinview.cpp b/tizen/src/ui/skinview.cpp index c9be238b8e..2e1e67407f 100644 --- a/tizen/src/ui/skinview.cpp +++ b/tizen/src/ui/skinview.cpp @@ -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); -- 2.34.1