From 359bac47796f112f77c8fe3ff7e9bd6535eb4251 Mon Sep 17 00:00:00 2001 From: jihye Date: Wed, 1 Feb 2017 13:58:30 +0900 Subject: [PATCH] skin: check that image file of H/W button exist or not - privite image file: if image file exist in controller directory of skin - default image file: if image file not exist Change-Id: Ide0e45db1f232a6c12bfb14721a668b129bab90d Signed-off-by: jihye --- tizen/src/ui/controller/hwkeybutton.cpp | 87 ++++++++++++++++++++++++++------- tizen/src/ui/controller/hwkeybutton.h | 3 ++ tizen/src/ui/layout/hardwarekey.cpp | 40 ++++++++++++++- tizen/src/ui/layout/hardwarekey.h | 8 ++- tizen/src/ui/xmllayoutparser.cpp | 5 +- 5 files changed, 122 insertions(+), 21 deletions(-) diff --git a/tizen/src/ui/controller/hwkeybutton.cpp b/tizen/src/ui/controller/hwkeybutton.cpp index 16c109b..0c8afa2 100644 --- a/tizen/src/ui/controller/hwkeybutton.cpp +++ b/tizen/src/ui/controller/hwkeybutton.cpp @@ -28,6 +28,7 @@ */ #include +#include #include "hwkeybutton.h" @@ -36,30 +37,27 @@ extern "C" { #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) { @@ -80,6 +78,59 @@ HWKeyButton::HWKeyButton(QWidget *parent, HardwareKey *hwKey, QSize size) : } } +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) { diff --git a/tizen/src/ui/controller/hwkeybutton.h b/tizen/src/ui/controller/hwkeybutton.h index 807ae0a..cba5ff0 100644 --- a/tizen/src/ui/controller/hwkeybutton.h +++ b/tizen/src/ui/controller/hwkeybutton.h @@ -43,6 +43,9 @@ public: virtual const char *getSlot(); protected: + virtual void initialize(QSize size); + virtual void initialize(QString name, QSize size); + void showEvent(QShowEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); diff --git a/tizen/src/ui/layout/hardwarekey.cpp b/tizen/src/ui/layout/hardwarekey.cpp index 3c8ee3e..9647a49 100644 --- a/tizen/src/ui/layout/hardwarekey.cpp +++ b/tizen/src/ui/layout/hardwarekey.cpp @@ -26,7 +26,8 @@ * - S-Core Co., Ltd * */ - +#include +#include #include "hardwarekey.h" HardwareKey::HardwareKey(QString name, const KeycodeType &keycodeType, @@ -37,6 +38,9 @@ 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() @@ -74,6 +78,40 @@ QKeySequence HardwareKey::getKeySequence() 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 */ diff --git a/tizen/src/ui/layout/hardwarekey.h b/tizen/src/ui/layout/hardwarekey.h index 3e20a02..0efc1c5 100644 --- a/tizen/src/ui/layout/hardwarekey.h +++ b/tizen/src/ui/layout/hardwarekey.h @@ -48,13 +48,19 @@ public: QRect &getRect(); QString getTooltip(); QKeySequence getKeySequence(); - + void setImagePath(QString path); + QString getNormalImagePath(); + QString getHoverImagePath(); + QString getPushImagePath(); private: QString name; KeycodeType keycodeType; QRect region; QString tooltip; QKeySequence keySequence; + QString normalImagePath; + QString hoverImagePath; + QString pushImagePath; }; #endif // HARDWAREKEY_H diff --git a/tizen/src/ui/xmllayoutparser.cpp b/tizen/src/ui/xmllayoutparser.cpp index 25838d7..4d0ba95 100644 --- a/tizen/src/ui/xmllayoutparser.cpp +++ b/tizen/src/ui/xmllayoutparser.cpp @@ -258,7 +258,10 @@ HardwareKey *XmlLayoutParser::parseKey(QXmlStreamReader &xml, const int depth) token = xml.readNext(); } - return new HardwareKey(keyName, keycodeType, keyRegion, keyTooptip, keySequence); + HardwareKey *key = new HardwareKey(keyName, keycodeType, keyRegion, keyTooptip, keySequence); + key->setImagePath(this->xmlPath); + + return key; } int XmlLayoutParser::parseKeyList(QXmlStreamReader &xml, -- 2.7.4