4 * Copyright (C) 2015 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,
31 #include "config-host.h"
33 #include "generalpurposecon.h"
34 #include "resource/ui_strings.h"
35 #include "menu/advancedmenuitem.h"
37 GeneralPurposeCon::GeneralPurposeCon(MainWindow *window)
39 qDebug("create general purpose controller");
43 void GeneralPurposeCon::createHeaderBarAndBorder(QGraphicsScene *scene, bool isFloating)
45 UiInformation *uiInfo = mainWindow->getUiInfo();
46 QSize size = uiInfo->getConSize();
49 scene->addRect(0, 0, size.width(), GPC_HEAD_BAR_HEIGHT, QPen(Qt::NoPen),
50 QBrush(uiInfo->getVMColor()));
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);
59 scene->addLine(bsize, size.height() - bsize, size.width(), size.height() - bsize, borderPen);
61 scene->addLine(size.width() - bsize, GPC_HEAD_BAR_HEIGHT + bsize, size.width() - bsize, size.height(), borderPen);
65 QList<HWKeyButton *> GeneralPurposeCon::createButtons(QGraphicsScene *scene, QWidget *parent, ControllerForm *form)
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);
71 QList<HWKeyButton *> buttonList;
74 createKeyList(parent, form->getKeyList(), topLeft, form->getRowCount(), buttonList);
75 topLeft.setY(topLeft.y()
76 + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * form->getRowCount());
79 for (int i = 0; i < form->getSubFormList().count(); i++) {
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);
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());
95 void GeneralPurposeCon::createKeyList(QWidget *parent, QList<HardwareKey *> keyList,
96 QPoint topLeft, int count, QList<HWKeyButton *> &buttonList)
102 HardwareKey *hwKey = NULL;
103 HWKeyButton *keyButton = NULL;
106 int loop = ceil(keyList.count() / (float) count);
108 for (int c = 0; c < loop; c++) {
109 for (int i = 0; i < count && index < keyList.count(); i++) {
110 hwKey = keyList.at(index++);
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();
122 tooltip.replace(XML_QT_METAKEY_STRING, XML_QT_CTRLKEY_STRING);
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) {
132 bool find = setMenuSlot(keyButton, hwKey->getName(), mainWindow->getUiInfo()->getMenuList());
134 QObject::connect(keyButton, SIGNAL(clicked()), mainWindow->getPopupMenu(),
135 SLOT(slotUndefinedMenu()));
138 buttonList.append(keyButton);
143 bool GeneralPurposeCon::setMenuSlot(HWKeyButton *button, QString name, QList<MenuItem *> &list)
145 MenuItem *item = NULL;
147 for (int i = 0; i < list.count(); i++) {
149 if (item->getType() == MenuItemType::advancedItem) {
150 find = setMenuSlot(button, name, ((AdvancedMenuItem *)item)->getMenuList());
155 if (QString::compare(name, item->getName()) == 0) {
156 QObject::connect(button,
157 SIGNAL(clicked()), mainWindow->getPopupMenu(), item->getSlot());
167 GeneralPurposeCon::~GeneralPurposeCon()
169 qDebug("destroy general purpose controller");