*/
#include <QDebug>
+#include <QFile>
#include "hwkeybutton.h"
#include "util/ui_operations.h"
}
+#define DEFAULT_NAME "keybutton"
+
HWKeyButton::HWKeyButton(QWidget *parent, HardwareKey *hwKey, QSize size) :
QPushButton(hwKey->getName(), parent)
{
this->hwKey = hwKey;
-
setText("");
setFocusPolicy(Qt::NoFocus);
- setStyleSheet(
- "QPushButton {"
- "width: " + QString::number(size.width()) + ";" +
- "height: " + QString::number(size.height()) + ";" +
- "border: none; color: white;"
- "background: url(\":images/controller-skin/" + hwKey->getName() +"_normal.png\");"
- "}"
- "QPushButton:hover {"
- "background: url(\":images/controller-skin/" + hwKey->getName() +"_hover.png\");"
- "}"
- "QPushButton:pressed {"
- "background: url(\":images/controller-skin/" + hwKey->getName() +"_pushed.png\");"
- "}"
- "QToolTip {"
- "color:#2E2E2E; background-color:#CCCCCC;"
- "}"
- );
+
+ if (!hwKey->getNormalImagePath().isEmpty()) {
+ initialize(size);
+ } else {
+ if (QFile::exists(":images/controller-skin/" + hwKey->getName() + "_normal.png")
+ && QFile::exists(":images/controller-skin/" + hwKey->getName() + "_hover.png")
+ && QFile::exists(":images/controller-skin/" + hwKey->getName() + "_pushed.png")) {
+ initialize(hwKey->getName(), size);
+ } else {
+ setText(hwKey->getName());
+ initialize(DEFAULT_NAME, size);
+ }
+ }
//FIXME: set slot for menu button
if (hwKey->getKeycode() == 0) {
}
}
+void HWKeyButton::initialize(QSize size)
+{
+ // use image file path
+ // path is absolute path
+ setStyleSheet(
+ "QPushButton {"
+ "width: " + QString::number(size.width()) + ";" +
+ "height: " + QString::number(size.height()) + ";" +
+ "border: none; color: black;"
+ "background: url(" + hwKey->getNormalImagePath() + ");"
+ "}"
+ "QPushButton:hover {"
+ "background: url(" + hwKey->getHoverImagePath() + ");"
+ "}"
+ "QPushButton:pressed {"
+ "background: url(" + hwKey->getPushImagePath() + ");"
+ "}"
+ "QToolTip {"
+ "color:#2E2E2E; background-color:#CCCCCC;"
+ "}"
+ );
+}
+
+void HWKeyButton::initialize(QString name, QSize size)
+{
+ // use key button name
+ // path is relative path
+ setStyleSheet(
+ "QPushButton {"
+ "width: " + QString::number(size.width()) + ";" +
+ "height: " + QString::number(size.height()) + ";" +
+ "border: none; color: black;"
+ "background: url(\":images/controller-skin/" + name +"_normal.png\");"
+ "}"
+ "QPushButton:hover {"
+ "background: url(\":images/controller-skin/" + name +"_hover.png\");"
+ "}"
+ "QPushButton:pressed {"
+ "background: url(\":images/controller-skin/" + name +"_pushed.png\");"
+ "}"
+ "QToolTip {"
+ "color:#2E2E2E; background-color:#CCCCCC;"
+ "}"
+ );
+}
+
+void HWKeyButton::showEvent(QShowEvent *event)
+{
+ if (!text().isEmpty()) {
+ setText(fontMetrics().elidedText(text(), Qt::ElideRight, width() * 1.2));
+ }
+}
+
/* override */
void HWKeyButton::mousePressEvent(QMouseEvent *event)
{
* - S-Core Co., Ltd
*
*/
-
+#include <QFileInfo>
+#include <QDir>
#include "hardwarekey.h"
HardwareKey::HardwareKey(QString name, const KeycodeType &keycodeType,
this->region = region;
this->tooltip = tooltip;
this->keySequence = keySequence;
+ this->normalImagePath = "";
+ this->hoverImagePath = "";
+ this->pushImagePath = "";
}
QString HardwareKey::getName()
return keySequence;
}
+void HardwareKey::setImagePath(QString path)
+{
+ if (path == NULL || path.isEmpty()) {
+ return;
+ }
+
+ QFileInfo normalImage(path + QDir::separator() + name + "_normal.png");
+ QFileInfo hoverImage(path + QDir::separator() + name + "_hover.png");
+ QFileInfo pushImage(path + QDir::separator() + name + "_pushed.png");
+
+ if (normalImage.exists() && normalImage.isFile()
+ && hoverImage.exists() && hoverImage.isFile()
+ && pushImage.exists() && pushImage.isFile()) {
+ normalImagePath = normalImage.absoluteFilePath();
+ hoverImagePath = hoverImage.absoluteFilePath();
+ pushImagePath = pushImage.absoluteFilePath();
+ }
+}
+
+QString HardwareKey::getNormalImagePath()
+{
+ return normalImagePath;
+}
+
+QString HardwareKey::getHoverImagePath()
+{
+ return hoverImagePath;
+}
+
+QString HardwareKey::getPushImagePath()
+{
+ return pushImagePath;
+}
+
HardwareKey::~HardwareKey()
{
/* do nothing */