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"
36 GeneralPurposeCon::GeneralPurposeCon()
38 qDebug("create general purpose controller");
41 void GeneralPurposeCon::createHeaderBarAndBorder(QGraphicsScene *scene, UiInformation *uiInfo, bool isFloating)
43 QSize size = uiInfo->getConSize();
46 scene->addRect(0, 0, size.width(), GPC_HEAD_BAR_HEIGHT, QPen(Qt::NoPen),
47 QBrush(uiInfo->getVMColor()));
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);
56 scene->addLine(bsize, size.height() - bsize, size.width(), size.height() - bsize, borderPen);
58 scene->addLine(size.width() - bsize, GPC_HEAD_BAR_HEIGHT + bsize, size.width() - bsize, size.height(), borderPen);
62 QList<HWKeyButton *> GeneralPurposeCon::createButtons(QGraphicsScene *scene, QWidget *parent, ControllerForm *form)
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);
68 QList<HWKeyButton *> buttonList;
71 createKeyList(parent, form->getKeyList(), topLeft, form->getRowCount(), buttonList);
72 topLeft.setY(topLeft.y()
73 + (GPC_KEYBUTTON_HEIGHT + GPC_KEYBUTTON_VSPACING) * form->getRowCount());
76 for (int i = 0; i < form->getSubFormList().count(); i++) {
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);
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());
92 void GeneralPurposeCon::createKeyList(QWidget *parent, QList<HardwareKey *> keyList,
93 QPoint topLeft, int count, QList<HWKeyButton *> &buttonList)
99 HardwareKey *hwKey = NULL;
100 HWKeyButton *keyButton = NULL;
103 int loop = ceil(keyList.count() / (float) count);
105 for (int c = 0; c < loop; c++) {
106 for (int i = 0; i < count && index < keyList.count(); i++) {
107 hwKey = keyList.at(index++);
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();
119 tooltip.replace(XML_QT_METAKEY_STRING, XML_QT_CTRLKEY_STRING);
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);
132 GeneralPurposeCon::~GeneralPurposeCon()
134 qDebug("destroy general purpose controller");