skin: check that image file of H/W button exist or not
authorjihye <jihye424.kim@samsung.com>
Wed, 1 Feb 2017 04:58:30 +0000 (13:58 +0900)
committerJiHye Kim <jihye424.kim@samsung.com>
Wed, 1 Feb 2017 10:54:31 +0000 (19:54 +0900)
- 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 <jihye424.kim@samsung.com>
tizen/src/ui/controller/hwkeybutton.cpp
tizen/src/ui/controller/hwkeybutton.h
tizen/src/ui/layout/hardwarekey.cpp
tizen/src/ui/layout/hardwarekey.h
tizen/src/ui/xmllayoutparser.cpp

index 16c109b..0c8afa2 100644 (file)
@@ -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)
 {
index 807ae0a..cba5ff0 100644 (file)
@@ -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);
 
index 3c8ee3e..9647a49 100644 (file)
@@ -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 */
index 3e20a02..0efc1c5 100644 (file)
@@ -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
index 25838d7..4d0ba95 100644 (file)
@@ -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,