skin: control size of controller window
[sdk/emulator/qemu.git] / tizen / src / ui / controller / generalpurposecon.cpp
1 /*
2  * Qt UI
3  *
4  * Copyright (C) 2015 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 <math.h>
31 #include "config-host.h"
32
33 #include "generalpurposecon.h"
34 #include "resource/ui_strings.h"
35
36 GeneralPurposeCon::GeneralPurposeCon()
37 {
38     qDebug("create general purpose controller");
39 }
40
41 void GeneralPurposeCon::createHeaderBarAndBorder(QGraphicsScene *scene, UiInformation *uiInfo, bool isFloating)
42 {
43     QSize size = uiInfo->getConSize();
44
45     // draw color bar
46     scene->addRect(0, 0, size.width(), GPC_HEAD_BAR_HEIGHT, QPen(Qt::NoPen),
47             QBrush(uiInfo->getVMColor()));
48
49     if (GPC_BORDER_SIZE > 0) {
50         float bsize = GPC_BORDER_SIZE / 2;
51         QPen borderPen(QColor(153, 153, 153), GPC_BORDER_SIZE, Qt::SolidLine);
52         if (isFloating) { // draw left border
53             scene->addLine(bsize, GPC_HEAD_BAR_HEIGHT + bsize, bsize, size.height(), borderPen);
54         }
55         // draw bottom border
56         scene->addLine(bsize, size.height() - bsize, size.width(), size.height() - bsize, borderPen);
57         // draw right border
58         scene->addLine(size.width() - bsize, GPC_HEAD_BAR_HEIGHT + bsize, size.width() - bsize, size.height(), borderPen);
59     }
60 }
61
62 QList<HWKeyButton *> GeneralPurposeCon::createButtons(QGraphicsScene *scene, QWidget *parent, ControllerForm *form)
63 {
64     QPoint topLeft = form->getCenteralRect().topLeft();
65     topLeft.setX(topLeft.x() + GPC_LEFT_SPACING + GPC_BORDER_SIZE);
66     topLeft.setY(topLeft.y() + GPC_HEAD_SPACING);
67
68     QList<HWKeyButton *> buttonList;
69
70     // H/W key list
71     createKeyList(parent, form->getKeyList(), topLeft, form->getRowCount(), buttonList);
72     topLeft.setY(topLeft.y()
73             + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * form->getRowCount());
74
75     // Menu key list
76     for (int i = 0; i < form->getSubFormList().count(); i++) {
77         // draw separator
78         QPen borderPen(QColor(153, 153, 153), 1, Qt::SolidLine);
79         scene->addLine(0, topLeft.y() - (GPC_KEYBUTTON_VSPACING / 2),
80                        form->getCenteralRect().width() - GPC_BORDER_SIZE,
81                        topLeft.y() - (GPC_KEYBUTTON_VSPACING / 2), borderPen);
82         //
83         ControllerForm *subForm = form->getSubFormList().at(i);
84         createKeyList(parent, subForm->getKeyList(), topLeft, subForm->getRowCount(), buttonList);
85         topLeft.setY(topLeft.y()
86                 + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * form->getRowCount());
87     }
88
89     return buttonList;
90 }
91
92 void GeneralPurposeCon::createKeyList(QWidget *parent, QList<HardwareKey *> keyList,
93                                         QPoint topLeft, int count, QList<HWKeyButton *> &buttonList)
94 {
95     if (count == 0) {
96         return;
97     }
98
99     HardwareKey *hwKey = NULL;
100     HWKeyButton *keyButton = NULL;
101
102     int index = 0;
103     int loop = ceil(keyList.count() / (float) count);
104
105     for (int c = 0; c < loop; c++) {
106         for (int i = 0; i < count && index < keyList.count(); i++) {
107             hwKey = keyList.at(index++);
108             if (hwKey == NULL) {
109                 continue;
110             }
111
112             keyButton = new HWKeyButton(parent, hwKey,
113                             QSize(GPC_KEYBUTTON_WIDTH, GPC_KEYBUTTON_HEIGHT));
114             QString tooltip = hwKey->getTooltip();
115             if (tooltip.isEmpty() == true) {
116                 if (hwKey->getKeySequence().isEmpty() == false) {
117                     tooltip = hwKey->getKeySequence().toString();
118                 #ifdef CONFIG_DARWIN
119                     tooltip.replace(XML_QT_METAKEY_STRING, XML_QT_CTRLKEY_STRING);
120                 #endif
121                 }
122             }
123
124             keyButton->setToolTip(hwKey->getName() + "  " + tooltip);
125             keyButton->move(topLeft.x() + (GPC_KEYBUTTON_WIDTH + GPC_KEYBUTTON_HSPACING) * c,
126                     topLeft.y() + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * i);
127             buttonList.append(keyButton);
128         }
129     }
130 }
131
132 GeneralPurposeCon::~GeneralPurposeCon()
133 {
134     qDebug("destroy general purpose controller");
135 }
136