From a55c207367bb37a012cdb0b2bc231d948f580a13 Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Tue, 25 Aug 2015 18:47:05 +0900 Subject: hwkey: HW key re-masking on skin do re-masking when side key(volume or power HW key on mobile) is pressed Change-Id: Ic2f36366a15ad4d3ef1c2c84c73c55b858091377 Signed-off-by: GiWoong Kim --- tizen/src/ui/controller/dockingconview.cpp | 19 ++++++-- tizen/src/ui/controller/dockingconview.h | 3 ++ tizen/src/ui/controller/floatingconview.cpp | 18 +++++-- tizen/src/ui/controller/floatingconview.h | 3 ++ tizen/src/ui/layout/hardwarekey.cpp | 2 +- tizen/src/ui/layout/hardwarekey.h | 2 +- tizen/src/ui/mainview.cpp | 42 +++++++++++----- tizen/src/ui/mainview.h | 4 +- tizen/src/ui/skinkeyitem.cpp | 43 ++++++++++++----- tizen/src/ui/skinkeyitem.h | 16 +++--- tizen/src/ui/skinview.cpp | 23 ++++++++- tizen/src/ui/skinview.h | 8 ++- tizen/src/ui/uiinformation.cpp | 75 +++++++++++++++++++++++------ tizen/src/ui/uiinformation.h | 7 ++- 14 files changed, 206 insertions(+), 59 deletions(-) diff --git a/tizen/src/ui/controller/dockingconview.cpp b/tizen/src/ui/controller/dockingconview.cpp index 3e430a2a2b..a94a602ea8 100644 --- a/tizen/src/ui/controller/dockingconview.cpp +++ b/tizen/src/ui/controller/dockingconview.cpp @@ -49,7 +49,7 @@ DockingConView::DockingConView(QWidget *parent, void DockingConView::createItems(ControllerForm *conForm) { /* bezel */ - bezelItem = createBezelItem(conForm); + bezelItem = createBezelItem(NULL, conForm); scene()->addItem(bezelItem); /* HW keys */ @@ -60,9 +60,7 @@ void DockingConView::createItems(ControllerForm *conForm) for (int i = 0; i < keyList.count(); i++) { hwKey = keyList.at(i); if (hwKey != NULL) { - new SkinKeyItem(bezelItem, hwKey, - conForm->skinImg[LayoutForm::pressed].copy(hwKey->getRegion()), - conForm->getHoverType()); + createKeyItem(bezelItem, conForm, hwKey); } } } else { @@ -75,6 +73,15 @@ void DockingConView::createItems(ControllerForm *conForm) } } +/* override */ +QRegion DockingConView::getKeyWinRegion( + QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type) +{ + return ((MainWindow *)parent->parentWidget())-> + uiInfo->getConKeyRegion(base, keyRect, type); +} + +/* override */ void DockingConView::resizeEvent(QResizeEvent *event) { /* do nothing */ @@ -82,6 +89,7 @@ void DockingConView::resizeEvent(QResizeEvent *event) SkinView::resizeEvent(event); } +/* override */ void DockingConView::mousePressEvent(QMouseEvent *event) { SkinView::mousePressEvent(event); @@ -108,6 +116,7 @@ void DockingConView::mousePressEvent(QMouseEvent *event) setConViewStatus(CONVIEW_PRESSED); } +/* override */ void DockingConView::mouseDoubleClickEvent(QMouseEvent *event) { SkinView::mouseDoubleClickEvent(event); @@ -125,6 +134,7 @@ void DockingConView::mouseDoubleClickEvent(QMouseEvent *event) setConViewStatus(CONVIEW_DOUBLECLICKED); } +/* override */ void DockingConView::mouseReleaseEvent(QMouseEvent *event) { SkinView::mouseReleaseEvent(event); @@ -152,6 +162,7 @@ void DockingConView::mouseReleaseEvent(QMouseEvent *event) setConViewStatus(CONVIEW_RELEASED); } +/* override */ void DockingConView::mouseMoveEvent(QMouseEvent *event) { SkinView::mouseMoveEvent(event); diff --git a/tizen/src/ui/controller/dockingconview.h b/tizen/src/ui/controller/dockingconview.h index ecec99fe48..3854972378 100644 --- a/tizen/src/ui/controller/dockingconview.h +++ b/tizen/src/ui/controller/dockingconview.h @@ -57,6 +57,9 @@ public: int getConViewStatus(); protected: + QRegion getKeyWinRegion( + QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type); + void resizeEvent(QResizeEvent *event); void mousePressEvent(QMouseEvent *event); void mouseDoubleClickEvent(QMouseEvent *event); diff --git a/tizen/src/ui/controller/floatingconview.cpp b/tizen/src/ui/controller/floatingconview.cpp index 293920e007..f2809860bc 100644 --- a/tizen/src/ui/controller/floatingconview.cpp +++ b/tizen/src/ui/controller/floatingconview.cpp @@ -50,7 +50,7 @@ FloatingConView::FloatingConView(QWidget *parent, void FloatingConView::createItems(ControllerForm *conForm) { /* bezel */ - bezelItem = createBezelItem(conForm); + bezelItem = createBezelItem(NULL, conForm); scene()->addItem(bezelItem); /* HW keys */ @@ -61,9 +61,7 @@ void FloatingConView::createItems(ControllerForm *conForm) for (int i = 0; i < keyList.count(); i++) { hwKey = keyList.at(i); if (hwKey != NULL) { - new SkinKeyItem(bezelItem, hwKey, - conForm->skinImg[LayoutForm::pressed].copy(hwKey->getRegion()), - conForm->getHoverType()); + createKeyItem(bezelItem, conForm, hwKey); } } } else { @@ -76,6 +74,15 @@ void FloatingConView::createItems(ControllerForm *conForm) } } +/* override */ +QRegion FloatingConView::getKeyWinRegion( + QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type) +{ + return ((MainWindow *)parent->parentWidget())-> + uiInfo->getConKeyRegion(base, keyRect, type); +} + +/* override */ void FloatingConView::resizeEvent(QResizeEvent *event) { /* do nothing */ @@ -140,6 +147,7 @@ int FloatingConView::isDockable(QWidget *object, QWidget *subject) return -1; } +/* override */ void FloatingConView::mousePressEvent(QMouseEvent *event) { SkinView::mousePressEvent(event); @@ -155,6 +163,7 @@ void FloatingConView::mousePressEvent(QMouseEvent *event) } } +/* override */ void FloatingConView::mouseReleaseEvent(QMouseEvent *event) { SkinView::mouseReleaseEvent(event); @@ -182,6 +191,7 @@ void FloatingConView::mouseReleaseEvent(QMouseEvent *event) } } +/* override */ void FloatingConView::mouseMoveEvent(QMouseEvent *event) { SkinView::mouseMoveEvent(event); diff --git a/tizen/src/ui/controller/floatingconview.h b/tizen/src/ui/controller/floatingconview.h index 71b05c1894..c31938b735 100644 --- a/tizen/src/ui/controller/floatingconview.h +++ b/tizen/src/ui/controller/floatingconview.h @@ -45,6 +45,9 @@ public: ~FloatingConView(); protected: + QRegion getKeyWinRegion( + QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type); + void resizeEvent(QResizeEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); diff --git a/tizen/src/ui/layout/hardwarekey.cpp b/tizen/src/ui/layout/hardwarekey.cpp index b09e86f59e..db1d584934 100644 --- a/tizen/src/ui/layout/hardwarekey.cpp +++ b/tizen/src/ui/layout/hardwarekey.cpp @@ -63,7 +63,7 @@ bool HardwareKey::hasLongPressKeycode() return (keycodeType->getLongPressKeycode() > 0); } -QRect HardwareKey::getRegion() +QRect &HardwareKey::getRect() { return region; } diff --git a/tizen/src/ui/layout/hardwarekey.h b/tizen/src/ui/layout/hardwarekey.h index 9d0531b01e..af25b9f59a 100644 --- a/tizen/src/ui/layout/hardwarekey.h +++ b/tizen/src/ui/layout/hardwarekey.h @@ -45,7 +45,7 @@ public: KeycodeType *getKeycodeType(); int getKeycode(); bool hasLongPressKeycode(); - QRect getRegion(); + QRect &getRect(); QString getTooltip(); QKeySequence getKeySequence(); diff --git a/tizen/src/ui/mainview.cpp b/tizen/src/ui/mainview.cpp index fec57b6ff0..1c626242b1 100644 --- a/tizen/src/ui/mainview.cpp +++ b/tizen/src/ui/mainview.cpp @@ -38,8 +38,8 @@ MainView::MainView(QGraphicsScene *scene, QWidget *parent) : SkinView(parent, scene) { this->win = ((MainWindow *)parent); - this->kbdHelper = new KeyboardHelper(this); this->grabWinPos = QPoint(-1, -1); + this->kbdHelper = new KeyboardHelper(this); updateLayout(); } @@ -47,7 +47,7 @@ MainView::MainView(QGraphicsScene *scene, QWidget *parent) : void MainView::createItems(MainForm *form) { /* bezel */ - SkinBezelItem *bezelItem = createBezelItem(form); + bezelItem = createBezelItem(NULL, form); scene()->addItem(bezelItem); /* HW keys */ @@ -57,13 +57,18 @@ void MainView::createItems(MainForm *form) for (int i = 0; i < keyList.count(); i++) { hwKey = keyList.at(i); if (hwKey != NULL) { - new SkinKeyItem(bezelItem, hwKey, - form->skinImg[LayoutForm::pressed].copy(hwKey->getRegion()), - form->getHoverType()); + createKeyItem(bezelItem, form, hwKey); } } } +/* override */ +QRegion MainView::getKeyWinRegion( + QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type) +{ + return win->uiInfo->getMainKeyRegion(base, keyRect, type); +} + KeyboardHelper *MainView::getKbdHelper() { return kbdHelper; @@ -114,31 +119,46 @@ void MainView::resizeEvent(QResizeEvent *event) /* override */ void MainView::mousePressEvent(QMouseEvent *event) { + SkinView::mousePressEvent(event); + + if (bezelItem->isHWKeyHandling() == true) { + /* do nothing */ + return; + } + if (event->button() == Qt::LeftButton) { grabWindow(event->globalPos()); } - - SkinView::mousePressEvent(event); } /* override */ void MainView::mouseReleaseEvent(QMouseEvent *event) { + SkinView::mouseReleaseEvent(event); + + if (bezelItem->isHWKeyHandling() == true) { + /* do nothing */ + return; + } + if (event->button() == Qt::LeftButton) { releaseWindow(); } - - SkinView::mouseReleaseEvent(event); } /* override */ void MainView::mouseMoveEvent(QMouseEvent *event) { + SkinView::mouseMoveEvent(event); + + if (bezelItem->isHWKeyHandling() == true) { + /* do nothing */ + return; + } + if (isGrabWindow() == true) { win->move(grabWinPos + (event->globalPos() - grabPos)); } - - SkinView::mouseMoveEvent(event); } /* override */ diff --git a/tizen/src/ui/mainview.h b/tizen/src/ui/mainview.h index f5244b5f1c..a829952bef 100644 --- a/tizen/src/ui/mainview.h +++ b/tizen/src/ui/mainview.h @@ -52,8 +52,9 @@ public: void updateLayout(); protected: - void resizeEvent(QResizeEvent *event); + QRegion getKeyWinRegion(QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type); + void resizeEvent(QResizeEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); @@ -62,6 +63,7 @@ protected: void focusOutEvent(QFocusEvent *event); MainWindow *win; + SkinBezelItem *bezelItem; QPoint grabWinPos; KeyboardHelper *kbdHelper; diff --git a/tizen/src/ui/skinkeyitem.cpp b/tizen/src/ui/skinkeyitem.cpp index 241c27ca91..5cc4d44f11 100644 --- a/tizen/src/ui/skinkeyitem.cpp +++ b/tizen/src/ui/skinkeyitem.cpp @@ -30,19 +30,22 @@ #include #include "skinkeyitem.h" +#include "skinview.h" extern "C" { #include "emul_state.h" #include "util/ui_operations.h" } -SkinKeyItem::SkinKeyItem(SkinBezelItem *parent, - HardwareKey *hwKey, QImage pressedImg, HoverType *hover) : - QGraphicsRectItem(hwKey->getRegion(), (QGraphicsItem *)parent) +SkinKeyItem::SkinKeyItem(QGraphicsItem *parent, HardwareKey *hwKey, + QImage pressedImg, bool reMasking, HoverType *hover) : + QGraphicsRectItem(hwKey->getRect(), parent) { - this->bezelParent = parent; - this->pressedImg = pressedImg; + this->viewer = (SkinView *)scene()->views().at(0); + this->bezelParent = (SkinBezelItem *)parent; this->hwKey = hwKey; + this->pressedImg = pressedImg; + this->reMasking = reMasking; this->isPressed = false; if (hover != NULL) { @@ -69,6 +72,18 @@ void SkinKeyItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { bezelParent->setHWKeyHandling(isPressed = true); + hoverPen.setColor(Qt::transparent); + update(); + + if (reMasking == true && viewer != NULL) { + /* re-masking for HW key region */ + qDebug() << "HW key re-masking:" << hwKey->getName(); + + QWidget *target = viewer->topLevelWidget(); + target->setMask(viewer->getKeyWinRegion( + target, hwKey->getRect(), LayoutForm::pressed)); + } + if (hwKey->hasLongPressKeycode() == true) { /* long press checking first */ longPressTimer->start(); @@ -76,12 +91,8 @@ void SkinKeyItem::mousePressEvent(QGraphicsSceneMouseEvent *event) } const int keycode = hwKey->getKeycode(); - qDebug() << hwKey->getName() << "key pressed:" << keycode; do_hw_key_event(KEY_PRESSED, keycode); - - hoverPen.setColor(Qt::transparent); - update(); } /* override */ @@ -89,6 +100,15 @@ void SkinKeyItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { bezelParent->setHWKeyHandling(isPressed = false); + update(); + + if (reMasking == true && viewer != NULL) { + /* reset re-masking */ + QWidget *target = viewer->topLevelWidget(); + target->setMask(viewer->getKeyWinRegion( + target, hwKey->getRect(), LayoutForm::normal)); + } + int keycode = hwKey->getKeycode(); if (hwKey->hasLongPressKeycode() == true) { @@ -108,8 +128,6 @@ void SkinKeyItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) qDebug() << hwKey->getName() << "key released:" << keycode; do_hw_key_event(KEY_RELEASED, keycode); - - update(); } /* override */ @@ -139,7 +157,8 @@ void SkinKeyItem::paint(QPainter *painter, if (hoverPen.color() != Qt::transparent) { painter->setPen(hoverPen); - painter->drawRect(rect()); + painter->drawRect(rect().x(), rect().y(), + rect().width() - 1, rect().height() - 1); } if (isPressed == true) { diff --git a/tizen/src/ui/skinkeyitem.h b/tizen/src/ui/skinkeyitem.h index c5fec95002..0032f8f434 100644 --- a/tizen/src/ui/skinkeyitem.h +++ b/tizen/src/ui/skinkeyitem.h @@ -38,19 +38,17 @@ #include "layout/hardwarekey.h" #include "layout/hovertype.h" +class SkinView; + class SkinKeyItem : public QObject, public QGraphicsRectItem { Q_OBJECT public: - SkinKeyItem(SkinBezelItem *parent, - HardwareKey *hwKey, QImage pressedImg, HoverType *hover); + SkinKeyItem(QGraphicsItem *parent, HardwareKey *hwKey, + QImage pressedImg, bool reMasking, HoverType *hover); ~SkinKeyItem(); - HardwareKey *hwKey; - QImage pressedImg; - QTimer *longPressTimer; - protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); @@ -64,11 +62,17 @@ protected slots: void longPressHook(); private: + SkinView *viewer; SkinBezelItem *bezelParent; + HardwareKey *hwKey; + + QImage pressedImg; + bool reMasking; bool isPressed; QColor hoverColor; QPen hoverPen; QBrush brush; + QTimer *longPressTimer; }; #endif // SKINKEYITEM_H diff --git a/tizen/src/ui/skinview.cpp b/tizen/src/ui/skinview.cpp index a0ecc2f8c7..9030163031 100644 --- a/tizen/src/ui/skinview.cpp +++ b/tizen/src/ui/skinview.cpp @@ -27,6 +27,8 @@ * */ +#include + #include "skinview.h" SkinView::SkinView(QWidget *parent, QGraphicsScene *scene) : @@ -40,12 +42,29 @@ SkinView::SkinView(QWidget *parent, QGraphicsScene *scene) : setAlignment(Qt::AlignLeft | Qt::AlignTop); } -SkinBezelItem *SkinView::createBezelItem(LayoutForm *form) +SkinBezelItem *SkinView::createBezelItem(QGraphicsItem *parent, LayoutForm *form) { - return new SkinBezelItem(NULL, + return new SkinBezelItem(parent, QPixmap::fromImage(form->skinImg[LayoutForm::normal])); } +SkinKeyItem *SkinView::createKeyItem(QGraphicsItem *parent, + LayoutForm *form, HardwareKey *hwKey) +{ + bool reMasking = false; + + QImage normalKeyImg = form->skinImg[LayoutForm::normal].copy(hwKey->getRect()); + QImage pressedKeyImg = form->skinImg[LayoutForm::pressed].copy(hwKey->getRect()); + QImage normalMask = normalKeyImg.createAlphaMask(); + QImage pressedMask = pressedKeyImg.createAlphaMask(); + if (normalMask != pressedMask) { + reMasking = true; + } + + return new SkinKeyItem(parent, hwKey, + pressedKeyImg, reMasking, form->getHoverType()); +} + SkinView::~SkinView() { /* do nothing */ diff --git a/tizen/src/ui/skinview.h b/tizen/src/ui/skinview.h index 4874de3496..a45b35dd4b 100644 --- a/tizen/src/ui/skinview.h +++ b/tizen/src/ui/skinview.h @@ -33,6 +33,7 @@ #include #include "skinbezelitem.h" +#include "skinkeyitem.h" #include "layout/layoutform.h" class SkinView : public QGraphicsView @@ -41,8 +42,13 @@ public: SkinView(QWidget *parent, QGraphicsScene *scene); ~SkinView(); + virtual QRegion getKeyWinRegion( + QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type) = 0; + protected: - SkinBezelItem *createBezelItem(LayoutForm *form); + SkinBezelItem *createBezelItem(QGraphicsItem *parent, LayoutForm *form); + SkinKeyItem *createKeyItem(QGraphicsItem *parent, + LayoutForm *form, HardwareKey *hwKey); QPoint grabPos; }; diff --git a/tizen/src/ui/uiinformation.cpp b/tizen/src/ui/uiinformation.cpp index f0774ab2ed..c864d17b15 100644 --- a/tizen/src/ui/uiinformation.cpp +++ b/tizen/src/ui/uiinformation.cpp @@ -76,7 +76,12 @@ MainForm *UIInformation::getMainForm() index = uiState.mainFormIndex = 0; } - return mainFormList.at(index); + MainForm *mainForm = mainFormList.at(index); + if (mainForm == NULL) { + qFatal(MSG_INVALID_MAIN_FORM); + } + + return mainForm; } DisplayType *UIInformation::getMainFormDisplayType() @@ -100,12 +105,8 @@ ControllerForm *UIInformation::getConForm() /* size */ QSize UIInformation::getMainSize() { - MainForm *mainForm = getMainForm(); - if (mainForm == NULL) { - qFatal(MSG_INVALID_MAIN_FORM); - } - - return mainForm->skinImg[LayoutForm::normal].size() * uiState.getScaleFactor(); + return getMainForm()-> + skinImg[LayoutForm::normal].size() * uiState.getScaleFactor(); } QSize UIInformation::getConSize() @@ -136,13 +137,7 @@ QSize UIInformation::getUiSize() /* region */ QRegion UIInformation::getMainRegion() { - MainForm *mainForm = getMainForm(); - if (mainForm == NULL) { - qWarning("main form is null"); - return QRegion(0, 0, 0, 0); - } - - QImage *mainImage = &(mainForm->skinImg[LayoutForm::normal]); + QImage *mainImage = &(getMainForm()->skinImg[LayoutForm::normal]); QImage regionImage = mainImage->scaled( mainImage->width() * uiState.getScaleFactor(), mainImage->height() * uiState.getScaleFactor()).createAlphaMask(); @@ -188,6 +183,58 @@ QRegion UIInformation::getUiRegion() return uiRegion; } +QRegion UIInformation::getMainKeyRegion( + QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type) +{ + QRegion baseRegion = base->mask().subtracted(QRect( + keyRect.topLeft() * uiState.getScaleFactor(), + keyRect.size() * uiState.getScaleFactor())); + + QImage keyImage = getMainForm()->skinImg[type].copy(keyRect); + QImage regionImage = keyImage.scaled( + keyImage.width() * uiState.getScaleFactor(), + keyImage.height() * uiState.getScaleFactor()).createAlphaMask(); + + QRegion keyRegion(QBitmap::fromImage(regionImage)); + keyRegion.translate(keyRect.topLeft() * uiState.getScaleFactor()); + + return baseRegion.united(keyRegion); +} + +QRegion UIInformation::getConKeyRegion( + QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type) +{ + if (getConForm() == NULL) { + qWarning("controller form is null"); + return QRegion(); + } + + QRegion baseRegion; + QRegion keyRegion; + + if (uiState.conState.dockingCon != NULL) { + /* docking controller */ + const int shiftW = getMainSize().width(); + + baseRegion = getUiRegion().subtracted(QRect( + keyRect.x() + shiftW, keyRect.y(), + keyRect.width(), keyRect.height())); + + QImage keyImage = getConForm()->skinImg[type].copy(keyRect); + keyRegion = QRegion(QBitmap::fromImage(keyImage.createAlphaMask())); + keyRegion.translate(keyRect.left() + shiftW, keyRect.top()); + } else { + baseRegion = base->mask().subtracted(QRect( + keyRect.x(), keyRect.y(), keyRect.width(), keyRect.height())); + + QImage keyImage = getConForm()->skinImg[type].copy(keyRect); + keyRegion = QRegion(QBitmap::fromImage(keyImage.createAlphaMask())); + keyRegion.translate(keyRect.left(), keyRect.top()); + } + + return baseRegion.united(keyRegion); +} + UIInformation::~UIInformation() { qDebug("destroy UI info"); diff --git a/tizen/src/ui/uiinformation.h b/tizen/src/ui/uiinformation.h index 1e8c02d12b..97b24d0ceb 100644 --- a/tizen/src/ui/uiinformation.h +++ b/tizen/src/ui/uiinformation.h @@ -63,10 +63,13 @@ public: ControllerForm *getConForm(); QSize getMainSize(); QSize getConSize(); - QSize getUiSize(); /* size included main, docking con */ + QSize getUiSize(); /* main + docking con */ + QRegion getMainRegion(); QRegion getConRegion(); - QRegion getUiRegion(); /* size included main, docking con */ + QRegion getUiRegion(); /* main + docking con */ + QRegion getMainKeyRegion(QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type); + QRegion getConKeyRegion(QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type); }; #endif // UIINFORMATION_H -- cgit v1.2.3