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,
33 #include "hwkeybutton.h"
36 #include "emul_state.h"
37 #include "util/ui_operations.h"
40 #define DEFAULT_NAME "keybutton"
42 HWKeyButton::HWKeyButton(QWidget *parent, HardwareKey *hwKey, QSize size) :
43 QPushButton(hwKey->getName(), parent)
47 setFocusPolicy(Qt::NoFocus);
49 if (!hwKey->getNormalImagePath().isEmpty()) {
52 if (QFile::exists(":images/controller-skin/" + hwKey->getName() + "_normal.png")
53 && QFile::exists(":images/controller-skin/" + hwKey->getName() + "_hover.png")
54 && QFile::exists(":images/controller-skin/" + hwKey->getName() + "_pushed.png")) {
55 initialize(hwKey->getName(), size);
57 setText(hwKey->getName());
58 initialize(DEFAULT_NAME, size);
63 void HWKeyButton::initialize(QSize size)
65 // use image file path
66 // path is absolute path
69 "width: " + QString::number(size.width()) + ";" +
70 "height: " + QString::number(size.height()) + ";" +
71 "border: none; color: black;"
72 "background: url(" + hwKey->getNormalImagePath() + ");"
75 "background: url(" + hwKey->getHoverImagePath() + ");"
77 "QPushButton:pressed {"
78 "background: url(" + hwKey->getPushImagePath() + ");"
81 "color:#2E2E2E; background-color:#CCCCCC;"
86 void HWKeyButton::initialize(QString name, QSize size)
88 // use key button name
89 // path is relative path
92 "width: " + QString::number(size.width()) + ";" +
93 "height: " + QString::number(size.height()) + ";" +
94 "border: none; color: black;"
95 "background: url(\":images/controller-skin/" + name +"_normal.png\");"
98 "background: url(\":images/controller-skin/" + name +"_hover.png\");"
100 "QPushButton:pressed {"
101 "background: url(\":images/controller-skin/" + name +"_pushed.png\");"
104 "color:#2E2E2E; background-color:#CCCCCC;"
109 void HWKeyButton::showEvent(QShowEvent *event)
111 if (!text().isEmpty()) {
112 setText(fontMetrics().elidedText(text(), Qt::ElideRight, width() * 1.2));
117 void HWKeyButton::mousePressEvent(QMouseEvent *event)
119 const int keycode = hwKey->getKeycode();
122 qDebug() << hwKey->getName() << "key button pressed:" << keycode;
123 do_hw_key_event(KEY_PRESSED, keycode);
126 QPushButton::mousePressEvent(event);
130 void HWKeyButton::mouseReleaseEvent(QMouseEvent *event)
132 const int keycode = hwKey->getKeycode();
135 qDebug() << hwKey->getName() << "key button released:" << keycode;
136 do_hw_key_event(KEY_RELEASED, keycode);
139 QPushButton::mouseReleaseEvent(event);
142 HWKeyButton::~HWKeyButton()