Home: Use icon from AFM, display a black area with text if icon unloadable sandbox/mfritzsch/afw-icons
authormfritzsch <marcus_fritzsch@mentor.com>
Fri, 5 May 2017 14:49:03 +0000 (16:49 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Mon, 15 May 2017 16:25:15 +0000 (18:25 +0200)
* Try to find icons in the AFM_ICON_PATH.
* If none was found, use the builtin.
* If Home.qml cannot load the icon, display a shaded circle
  that approximates the size of the icons, and contains the
  icon name as text.
* Enables proper scrolling of Home icons (and clipping to its
  dimensions).

Change-Id: Ic921b357870648e675cda41985da2e985f4a0e6c

homescreen/homescreen.pro
homescreen/qml/Home.qml
homescreen/src/applicationmodel.cpp

index 1ca59b6..357bd64 100644 (file)
@@ -19,6 +19,9 @@ CONFIG += c++11
 
 include(../interfaces/interfaces.pri)
 
+AFM_ICON_DIR = '$$system(pkg-config --variable=icondir afm-main || echo /var/local/lib/afm/icons/)'
+QMAKE_CXXFLAGS += -DAFM_ICON_DIR='\\\"$$AFM_ICON_DIR\\\"'
+
 SOURCES += \
     src/main.cpp \
     src/homescreencontrolinterface.cpp \
index aa3a129..af3f56e 100644 (file)
@@ -32,20 +32,70 @@ Item {
 
     GridView {
         anchors.centerIn: parent
-        width: cellHeight * 3
-        height: cellHeight * 3
+        width: cellWidth * 3
+        height: parent.height
         cellWidth: 320
         cellHeight: 320
-        interactive: false
+        interactive: true
+        clip: true
 
         model: ApplicationModel {}
+
         delegate: MouseArea {
             width: 320
             height: 320
-            Image {
+
+            Item {
+                width: parent.width
+                height: parent.height
                 anchors.fill: parent
-                source: './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
+
+                // These images contain the item text at the bottom,
+                // is it possible to crop the image in QML?
+                Image {
+                    id: img
+                    clip: true
+                    width: parent.width
+                    height: parent.height
+                    fillMode: Image.PreserveAspectCrop
+                    source: model.icon.substr(0, 5) === "file:"
+                        ? model.icon
+                        : './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive')
+                }
+
+                // Show this rect and the text below if the image could not be loaded
+                Rectangle {
+                    anchors {
+                        fill: parent
+                        margins: 50
+                    }
+                    border {
+                        color: "#64fdcb"
+                        width: 3
+                    }
+                    color: pressed ? "#11bcb9" : "#202020"
+                    radius: parent.width / 2 // circle'd rectangle...
+                    visible: img.status == Image.Error
+                }
+
+                Text {
+                    property int font_size: 26
+
+                    font.family: roboto
+                    font.capitalization: Font.AllUppercase
+                    font.bold: false
+                    font.pixelSize: font_size
+                    text: model.name
+                    color: "#ffffff"
+                    anchors {
+                        horizontalCenter: parent.horizontalCenter
+                        top: img.top
+                        topMargin: parent.height / 2 - font_size / 2
+                    }
+                    visible: img.status == Image.Error
+                }
             }
+
             onClicked: {
                 console.log("app is ", model.id)
                 pid = launcher.launch(model.id)
index c43e1bc..e74411a 100644 (file)
@@ -36,8 +36,23 @@ public:
 };
 
 namespace {
+    QString find_icon_file(QString s)
+    {
+        auto f = QFileInfo(QString(AFM_ICON_DIR), s);
+        if (f.exists()) {
+            return f.absoluteFilePath();
+        }
+        return QString();
+    }
+
     QString get_icon_name(QJsonObject const &i)
     {
+        QString icon_file_name = find_icon_file(i["id"].toString());
+
+        if (! icon_file_name.isEmpty()) {
+            return QStringLiteral("file:") + icon_file_name;
+        }
+
         QString icon = i["id"].toString().split("@").front();
         if (icon == "hvac" || icon == "poi") {
             icon = icon.toUpper();
@@ -46,6 +61,7 @@ namespace {
         } else {
             icon[0] = icon[0].toUpper();
         }
+
         return icon;
     }
 }
@@ -55,7 +71,7 @@ ApplicationModel::Private::Private()
     QString apps = afm_user_daemon_proxy->runnables(QStringLiteral(""));
     QJsonDocument japps = QJsonDocument::fromJson(apps.toUtf8());
     for (auto const &app : japps.array()) {
-        QJsonObject const &jso = app.toObject();
+        auto const &jso = app.toObject();
         auto const name = jso["name"].toString();
         auto const id = jso["id"].toString();
         auto const icon = get_icon_name(jso);