skin: make menu key button
[sdk/emulator/qemu.git] / tizen / src / ui / controller / dockingcontroller.cpp
1 /*
2  * Qt UI
3  *
4  * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  * GiWoong Kim <giwoong.kim@samsung.com>
8  * Sangho Park <sangho1206.park@samsung.com>
9  *
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.
14  *
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.
19  *
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,
23  * MA 02110-1301, USA.
24  *
25  * Contributors:
26  * - S-Core Co., Ltd
27  *
28  */
29
30 #include "dockingcontroller.h"
31 #include "mainwindow.h"
32
33 DockingController::DockingController(ControllerForm *conForm,
34     QAction *menu, int dockPos, QWidget *parent) : QWidget(parent)
35 {
36     this->win = (MainWindow *)parent;
37     this->conForm = conForm;
38     this->menu = menu;
39     this->dockPos = dockPos;
40
41     setStyleSheet("background: transparent; border-style: none");
42
43     QGraphicsScene *conScene = new QGraphicsScene(this);
44     conScene->setBackgroundBrush(Qt::transparent);
45
46     conView = new DockingConView(this, conForm, conScene);
47     conView->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
48     conView->resize(conForm->skinImg[LayoutForm::normal].size());
49 }
50
51 ControllerForm *DockingController::getConForm()
52 {
53     return conForm;
54 }
55
56 DockingConView *DockingController::getConView()
57 {
58     return conView;
59 }
60
61 MainWindow *DockingController::getMainWindow()
62 {
63     return win;
64 }
65
66 int DockingController::getDockPos()
67 {
68     return dockPos;
69 }
70
71 void DockingController::updateGeometry()
72 {
73     const QSize mainSize = win->getUiInfo()->getMainSize();
74     const QSize conSize = win->getUiInfo()->getConSize();
75
76     int vShift = 0;
77
78     if (mainSize.height() > conSize.height()) {
79         if (dockPos & Qt::AlignCenter) {
80             vShift = (mainSize.height() - conSize.height()) / 2;
81         } else if (dockPos & Qt::AlignBottom) {
82             vShift = mainSize.height() - conSize.height();
83         }
84     }
85
86     setGeometry(mainSize.width(), vShift, conSize.width(), conSize.height());
87 }
88
89 /* override */
90 void DockingController::showEvent(QShowEvent *event)
91 {
92     qDebug("show docking controller");
93
94     updateGeometry();
95
96     if (menu != NULL) {
97         menu->setChecked(true);
98     }
99 }
100
101 /* override */
102 void DockingController::closeEvent(QCloseEvent *event) {
103     if (menu != NULL) {
104         menu->setChecked(false);
105     }
106
107     win->getUiState()->getConState()->setDockingCon(NULL);
108
109     deleteLater();
110     event->accept();
111 }
112
113 DockingController::~DockingController()
114 {
115     qDebug("destroy docking controller");
116 }