Don't look up pid/tid on YAGL_LOG_FUNC_SET
[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 #include "menu/advancedmenuitem.h"
36
37 GeneralPurposeCon::GeneralPurposeCon(MainWindow *window)
38 {
39     qDebug("create general purpose controller");
40     mainWindow = window;
41 }
42
43 void GeneralPurposeCon::createHeaderBarAndBorder(QGraphicsScene *scene, bool isFloating)
44 {
45     UiInformation *uiInfo = mainWindow->getUiInfo();
46     QSize size = uiInfo->getConSize();
47
48     // draw color bar
49     scene->addRect(0, 0, size.width(), GPC_HEAD_BAR_HEIGHT, QPen(Qt::NoPen),
50             QBrush(uiInfo->getVMColor()));
51
52     if (GPC_BORDER_SIZE > 0) {
53         float bsize = GPC_BORDER_SIZE / 2;
54         QPen borderPen(QColor(153, 153, 153), GPC_BORDER_SIZE, Qt::SolidLine);
55         if (isFloating) { // draw left border
56             scene->addLine(bsize, GPC_HEAD_BAR_HEIGHT + bsize, bsize, size.height(), borderPen);
57         }
58         // draw bottom border
59         scene->addLine(bsize, size.height() - bsize, size.width(), size.height() - bsize, borderPen);
60         // draw right border
61         scene->addLine(size.width() - bsize, GPC_HEAD_BAR_HEIGHT + bsize, size.width() - bsize, size.height(), borderPen);
62     }
63 }
64
65 QList<HWKeyButton *> GeneralPurposeCon::createButtons(QGraphicsScene *scene, QWidget *parent, ControllerForm *form)
66 {
67     QPoint topLeft = form->getCenteralRect().topLeft();
68     topLeft.setX(topLeft.x() + GPC_LEFT_SPACING + GPC_BORDER_SIZE);
69     topLeft.setY(topLeft.y() + GPC_HEAD_SPACING);
70
71     QList<HWKeyButton *> buttonList;
72
73     // H/W key list
74     createKeyList(parent, form->getKeyList(), topLeft, form->getRowCount(), buttonList);
75     topLeft.setY(topLeft.y()
76             + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * form->getRowCount());
77
78     // Menu key list
79     for (int i = 0; i < form->getSubFormList().count(); i++) {
80         // draw separator
81         QPen borderPen(QColor(153, 153, 153), 1, Qt::SolidLine);
82         scene->addLine(0, topLeft.y() - (GPC_KEYBUTTON_VSPACING / 2),
83                        form->getCenteralRect().width() - GPC_BORDER_SIZE,
84                        topLeft.y() - (GPC_KEYBUTTON_VSPACING / 2), borderPen);
85         //
86         ControllerForm *subForm = form->getSubFormList().at(i);
87         createKeyList(parent, subForm->getKeyList(), topLeft, subForm->getRowCount(), buttonList);
88         topLeft.setY(topLeft.y()
89                 + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * form->getRowCount());
90     }
91
92     return buttonList;
93 }
94
95 void GeneralPurposeCon::createKeyList(QWidget *parent, QList<HardwareKey *> keyList,
96                                         QPoint topLeft, int count, QList<HWKeyButton *> &buttonList)
97 {
98     if (count == 0) {
99         return;
100     }
101
102     HardwareKey *hwKey = NULL;
103     HWKeyButton *keyButton = NULL;
104
105     int index = 0;
106     int loop = ceil(keyList.count() / (float) count);
107
108     for (int c = 0; c < loop; c++) {
109         for (int i = 0; i < count && index < keyList.count(); i++) {
110             hwKey = keyList.at(index++);
111             if (hwKey == NULL) {
112                 continue;
113             }
114
115             keyButton = new HWKeyButton(parent, hwKey,
116                             QSize(GPC_KEYBUTTON_WIDTH, GPC_KEYBUTTON_HEIGHT));
117             QString tooltip = hwKey->getTooltip();
118             if (tooltip.isEmpty() == true) {
119                 if (hwKey->getKeySequence().isEmpty() == false) {
120                     tooltip = hwKey->getKeySequence().toString();
121                 #ifdef CONFIG_DARWIN
122                     tooltip.replace(XML_QT_METAKEY_STRING, XML_QT_CTRLKEY_STRING);
123                 #endif
124                 }
125             }
126
127             keyButton->setToolTip(hwKey->getName() + "  " + tooltip);
128             keyButton->move(topLeft.x() + (GPC_KEYBUTTON_WIDTH + GPC_KEYBUTTON_HSPACING) * c,
129                     topLeft.y() + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * i);
130             if (hwKey->getKeycode() == 0) {
131                 // set menu slot
132                 bool find = setMenuSlot(keyButton, hwKey->getName(), mainWindow->getUiInfo()->getMenuList());
133                 if (!find) {
134                     QObject::connect(keyButton, SIGNAL(clicked()), mainWindow->getPopupMenu(),
135                             SLOT(slotUndefinedMenu()));
136                 }
137             }
138             buttonList.append(keyButton);
139         }
140     }
141 }
142
143 bool GeneralPurposeCon::setMenuSlot(HWKeyButton *button, QString name, QList<MenuItem *> &list)
144 {
145     MenuItem *item = NULL;
146     bool find = false;
147     for (int i = 0; i < list.count(); i++) {
148         item = list.at(i);
149         if (item->getType() == MenuItemType::advancedItem) {
150            find = setMenuSlot(button, name, ((AdvancedMenuItem *)item)->getMenuList());
151            if (find == true) {
152                break;
153            }
154         } else {
155             if (QString::compare(name, item->getName()) == 0) {
156                 QObject::connect(button,
157                         SIGNAL(clicked()), mainWindow->getPopupMenu(), item->getSlot());
158                 find = true;
159                 break;
160             }
161         }
162     }
163
164     return find;
165 }
166
167 GeneralPurposeCon::~GeneralPurposeCon()
168 {
169     qDebug("destroy general purpose controller");
170 }
171