diff options
Diffstat (limited to 'tizen')
-rw-r--r-- | tizen/src/ui/controller/hwkeybutton.cpp | 87 | ||||
-rw-r--r-- | tizen/src/ui/controller/hwkeybutton.h | 3 | ||||
-rw-r--r-- | tizen/src/ui/layout/hardwarekey.cpp | 40 | ||||
-rw-r--r-- | tizen/src/ui/layout/hardwarekey.h | 8 | ||||
-rw-r--r-- | 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 16c109bc0c..0c8afa28c1 100644 --- a/tizen/src/ui/controller/hwkeybutton.cpp +++ b/tizen/src/ui/controller/hwkeybutton.cpp @@ -28,6 +28,7 @@ */ #include <QDebug> +#include <QFile> #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 807ae0aeaa..cba5ff0989 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 3c8ee3ea0d..9647a49b2c 100644 --- a/tizen/src/ui/layout/hardwarekey.cpp +++ b/tizen/src/ui/layout/hardwarekey.cpp @@ -26,7 +26,8 @@ * - S-Core Co., Ltd * */ - +#include <QFileInfo> +#include <QDir> #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 3e20a02210..0efc1c5e10 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 25838d7f26..4d0ba95a76 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, |