summaryrefslogtreecommitdiff
path: root/tizen/src/ui/controller/generalpurposecon.cpp
blob: 9a5c31e4cf78cc62b9082876e2bae3bb1ca9167e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Qt UI
 *
 * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact:
 * GiWoong Kim <giwoong.kim@samsung.com>
 * Sangho Park <sangho1206.park@samsung.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 * Contributors:
 * - S-Core Co., Ltd
 *
 */

#include "config-host.h"

#include "generalpurposecon.h"
#include "resource/ui_strings.h"

GeneralPurposeCon::GeneralPurposeCon()
{
    qDebug("create general purpose controller");
}

void GeneralPurposeCon::createHeaderBarAndBorder(QGraphicsScene *scene, UiInformation *uiInfo, bool isFloating)
{
    QSize size = uiInfo->getConSize();

    // draw color bar
    scene->addRect(0, 0, size.width(), GPC_HEAD_BAR_HEIGHT, QPen(Qt::NoPen),
            QBrush(uiInfo->getVMColor()));

    if (GPC_BORDER_SIZE > 0) {
        float bsize = GPC_BORDER_SIZE / 2;
        QPen borderPen(QColor(153, 153, 153), GPC_BORDER_SIZE, Qt::SolidLine);
        if (isFloating) { // draw left border
            scene->addLine(bsize, GPC_HEAD_BAR_HEIGHT + bsize, bsize, size.height(), borderPen);
        }
        // draw bottom border
        scene->addLine(bsize, size.height() - bsize, size.width(), size.height() - bsize, borderPen);
        // draw right border
        scene->addLine(size.width() - bsize, GPC_HEAD_BAR_HEIGHT + bsize, size.width() - bsize, size.height(), borderPen);
    }
}

QList<HWKeyButton *> GeneralPurposeCon::createButtons(QWidget *parent, ControllerForm *form)
{
    QPoint topLeft = form->getCenteralRect().topLeft();
    topLeft.setX(topLeft.x() + GPC_LEFT_SPACING + GPC_BORDER_SIZE);
    topLeft.setY(topLeft.y() + GPC_HEAD_SPACING);

    QList<HWKeyButton *> buttonList;

    // H/W key list
    createKeyList(parent, form->getKeyList(), topLeft, buttonList);
    topLeft.setY(topLeft.y()
            + (GPC_KEYBUTTON_VSPACING + GPC_KEYBUTTON_HEIGHT) * form->getKeyList().count());

    // Menu key list
    for (int i = 0; i < form->getSubFormList().count(); i++) {
        ControllerForm *subForm = form->getSubFormList().at(i);
        createKeyList(parent, subForm->getKeyList(), topLeft, buttonList);
        topLeft.setY(topLeft.y()
                + (GPC_KEYBUTTON_VSPACING + GPC_KEYBUTTON_HEIGHT) * subForm->getKeyList().count());
    }

    return buttonList;
}

void GeneralPurposeCon::createKeyList(QWidget *parent, QList<HardwareKey *> keyList,
                                        QPoint topLeft, QList<HWKeyButton *> &buttonList)
{
    HardwareKey *hwKey = NULL;
    HWKeyButton *keyButton = NULL;

    for (int i = 0; i < keyList.count(); i++) {
        hwKey = keyList.at(i);
        if (hwKey != NULL) {
            keyButton = new HWKeyButton(parent, hwKey,
                    QSize(GPC_KEYBUTTON_WIDTH, GPC_KEYBUTTON_HEIGHT));
            QString tooltip = hwKey->getTooltip();
            if (tooltip.isEmpty() == true) {
                if (hwKey->getKeySequence().isEmpty() == false) {
                    tooltip = hwKey->getKeySequence().toString();
                #ifdef CONFIG_DARWIN
                    tooltip.replace(XML_QT_METAKEY_STRING, XML_QT_CTRLKEY_STRING);
                #endif
                }
            }

            keyButton->setToolTip(hwKey->getName() + "  " + tooltip);
            keyButton->move(topLeft.x(), topLeft.y()
                   + (GPC_KEYBUTTON_VSPACING + GPC_KEYBUTTON_HEIGHT) * i);
            buttonList.append(keyButton);
        }
    }
}

GeneralPurposeCon::~GeneralPurposeCon()
{
    qDebug("destroy general purpose controller");
}