4 * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
7 * GiWoong Kim <giwoong.kim@samsung.com>
8 * Sangho Park <sangho1206.park@samsung.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
30 #include "floatingconview.h"
31 #include "mainwindow.h"
32 #include "skinkeyitem.h"
33 #include "controller/generalpurposecon.h"
34 #include "resource/ui_strings.h"
36 #define DOCKABLE_AREA_WIDTH 30
38 FloatingConView::FloatingConView(QWidget *parent,
39 ControllerForm *conForm, QGraphicsScene *scene) : SkinView(parent, scene)
41 this->parent = (FloatingController *)parent;
43 setStyleSheet("FloatingConView { background: transparent; border-style: none; }" +
44 QString(STYLE_TOOLTIP));
46 conPos = SKINVIEW_NULLITY_POSITION;
47 rubberBand = new QRubberBand(QRubberBand::Rectangle, NULL);
52 void FloatingConView::createItems(ControllerForm *conForm)
55 bezelItem = createBezelItem(NULL, conForm);
56 scene()->addItem(bezelItem);
58 if (conForm->isGeneralPurpose() == false) {
60 QList<HardwareKey *> &keyList = conForm->getKeyList();
61 HardwareKey *hwKey = NULL;
62 for (int i = 0; i < keyList.count(); i++) {
63 hwKey = keyList.at(i);
65 createKeyItem(bezelItem, conForm, hwKey);
69 GeneralPurposeCon *generalCon = new GeneralPurposeCon(parent->getMainWindow());
71 generalCon->createHeaderBarAndBorder(scene(), true);
72 QList<HWKeyButton *> buttons
73 = generalCon->createButtons(scene(), parentWidget(), conForm);
78 void FloatingConView::grabWindow(QPoint pos)
80 SkinView::grabWindow(pos);
82 conPos = parent->pos();
86 void FloatingConView::releaseWindow()
88 SkinView::releaseWindow();
90 conPos = SKINVIEW_NULLITY_POSITION;
94 QRegion FloatingConView::getKeyWinRegion(
95 QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type)
97 return ((MainWindow *)parent->parentWidget())->
98 getUiInfo()->getConKeyRegion(base, keyRect, type);
102 void FloatingConView::resizeEvent(QResizeEvent *event)
106 SkinView::resizeEvent(event);
109 int FloatingConView::isDockable(QWidget *object, QWidget *subject)
111 const int heightOneThird = object->size().height() / 3;
114 QRect rectDockableRC(object->pos().x() + object->size().width() - 1,
115 object->pos().y() + heightOneThird,
119 QRect rectDockableRT(object->pos().x() + object->size().width() - 1,
124 QRect rectDockableRB(object->pos().x() + object->size().width() - 1,
125 object->pos().y() + (heightOneThird * 2),
129 /* ControllerWidget */
130 QRect rectTarget(subject->pos().x() - 1,
133 subject->size().height());
135 // TODO: define recursive function
136 QRect interRC = rectTarget.intersected(rectDockableRC);
137 QRect interRT = rectTarget.intersected(rectDockableRT);
138 QRect interRB = rectTarget.intersected(rectDockableRB);
140 QRect *interBiggest = NULL;
142 if ((interRC.width() * interRC.height()) < (interRT.width() * interRT.height())) {
143 interBiggest = &interRT;
145 interBiggest = &interRC;
148 if ((interBiggest->width() * interBiggest->height()) < (interRB.width() * interRB.height())) {
149 interBiggest = &interRB;
152 if (interBiggest != NULL &&
153 interBiggest->isNull() == false && interBiggest->isEmpty() == false) {
154 if (interBiggest == &interRC) {
155 return Qt::AlignRight | Qt::AlignCenter;
156 } else if (interBiggest == &interRT) {
157 return Qt::AlignRight | Qt::AlignTop;
158 } else if (interBiggest == &interRB) {
159 return Qt::AlignRight | Qt::AlignBottom;
167 void FloatingConView::mousePressEvent(QMouseEvent *event)
169 SkinView::mousePressEvent(event);
171 if (bezelItem->isHWKeyHandling() == true) {
176 if (event->button() == Qt::LeftButton) {
177 grabWindow(event->globalPos());
182 void FloatingConView::mouseReleaseEvent(QMouseEvent *event)
184 SkinView::mouseReleaseEvent(event);
186 if (bezelItem->isHWKeyHandling() == true) {
191 if (event->button() == Qt::LeftButton) {
192 if (rubberBand != NULL) {
199 MainWindow *win = ((MainWindow *)parent->parentWidget());
201 int dockPos = isDockable((QWidget *)win, (QWidget *)parent);
205 win->getUiState()->getConState()->getConFormIndex(), dockPos);
211 void FloatingConView::mouseMoveEvent(QMouseEvent *event)
213 SkinView::mouseMoveEvent(event);
215 if (bezelItem->isHWKeyHandling() == true) {
220 if (isGrabWindow() == true) {
221 /* draw guide for dockable position */
222 const FloatingController *con = parent;
223 MainWindow *win = ((MainWindow *)con->parent());
225 if (rubberBand != NULL) {
226 int dockPos = isDockable((QWidget *)win, (QWidget *)con);
230 if (win->size().height() > size().height()) {
231 if (dockPos & Qt::AlignCenter) {
232 vShift = (win->size().height() / 2) - (size().height() / 2);
233 } else if (dockPos & Qt::AlignBottom) {
234 vShift = win->size().height() - size().height();
238 QPoint rubberPos(win->pos().x() + win->size().width(),
239 win->pos().y() + vShift);
240 rubberBand->setGeometry(QRect(rubberPos, size()));
247 parent->move(conPos + (event->globalPos() - grabPos));
252 void FloatingConView::focusInEvent(QFocusEvent *event)
254 const FloatingController *con = parent;
255 MainWindow *win = ((MainWindow *)con->parent());
256 win->activateWindow();
259 FloatingConView::~FloatingConView()
261 qDebug("destroy floating controller view");
263 if (rubberBand != NULL) {