From: Bocklage, Jens Date: Fri, 9 Dec 2016 11:14:02 +0000 (+0100) Subject: Integrate Home app into HomeScreen X-Git-Tag: 3.0.0~35 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=staging%2FHomeScreen.git;a=commitdiff_plain;h=f2b8bddb94a451c4bd822ef723a8b739236f4b4f Integrate Home app into HomeScreen Home is located in ces2017 repo. But since it has to use HomeScreen internal components (layermanager and applauncher), I had to move it to main HomeScreen app. Signed-off-by: Bocklage, Jens --- diff --git a/HomeScreen/HomeScreen.pro b/HomeScreen/HomeScreen.pro index 1ad42bf..d48b6e5 100644 --- a/HomeScreen/HomeScreen.pro +++ b/HomeScreen/HomeScreen.pro @@ -61,9 +61,13 @@ OTHER_FILES += \ HEADERS += \ src2/statusbarmodel.h \ src2/statusbarserver.h \ - src2/applicationlauncher.h + src2/applicationlauncher.h \ + src2/applicationmodel.h \ + src2/appinfo.h SOURCES += \ + src2/applicationmodel.cpp \ + src2/appinfo.cpp \ src2/statusbarmodel.cpp \ src2/statusbarserver.cpp \ src2/applicationlauncher.cpp @@ -72,6 +76,7 @@ RESOURCES += \ resources/homescreen.qrc RESOURCES += \ + qml/images/Home/home.qrc \ qml/images/MediaPlayer/mediaplayer.qrc \ qml/images/MediaMusic/mediamusic.qrc \ qml/images/Weather/weather.qrc \ @@ -79,10 +84,3 @@ RESOURCES += \ qml/images/Status/status.qrc \ qml/images/images.qrc \ qml/qml.qrc - - -copydata.commands = $(COPY_DIR) $$PWD/resources/colorschemes $$OUT_PWD -HomeScreen.depends = $(HomeScreen) copydata -export(HomeScreen.depends) -export(copydata.commands) -QMAKE_EXTRA_TARGETS += HomeScreen copydata diff --git a/HomeScreen/qml/Home.qml b/HomeScreen/qml/Home.qml new file mode 100644 index 0000000..cfcd1c8 --- /dev/null +++ b/HomeScreen/qml/Home.qml @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2016 The Qt Company Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import QtQuick 2.2 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.0 +import Home 1.0 + +Item { + id: root + + Image { + anchors.fill: parent + anchors.topMargin: -218 + anchors.bottomMargin: -215 + source: './images/AGL_HMI_Background_Car-01.png' + } + + property int pid: -1 + + GridView { + anchors.centerIn: parent + width: cellHeight * 3 + height: cellHeight * 3 + cellWidth: 320 + cellHeight: 320 + + model: ApplicationModel {} + delegate: MouseArea { + width: 320 + height: 320 + Image { + anchors.fill: parent + source: './images/HMI_AppLauncher_%1_%2-01.png'.arg(model.icon).arg(pressed ? 'Active' : 'Inactive') + } + onClicked: { + console.log("app is ", model.id) + pid = launcher.launch(model.id) + layoutHandler.makeMeVisible(pid) + + applicationArea.visible = true + appLauncherAreaLauncher.visible = false + layoutHandler.showAppLayer() + } + } + } +} diff --git a/HomeScreen/qml/ShortcutArea.qml b/HomeScreen/qml/ShortcutArea.qml index 9ef8701..d9931cb 100644 --- a/HomeScreen/qml/ShortcutArea.qml +++ b/HomeScreen/qml/ShortcutArea.qml @@ -17,20 +17,12 @@ import QtQuick 2.2 import QtQuick.Layouts 1.1 -import HomeScreen 1.0 Item { id: root width: 785 height: 218 - ApplicationLauncher { - id: launcher - } - - LayoutHandler { - id: layoutHandler - } ListModel { id: applicationModel @@ -40,7 +32,7 @@ Item { } ListElement { name: 'Multimedia' - application: 'radio@0.1' + application: 'mediaplayer@0.1' } ListElement { name: 'HVAC' @@ -67,8 +59,18 @@ Item { active: model.index === root.currentIndex onClicked: { root.currentIndex = active ? -1 : model.index - pid = launcher.launch(model.application) - layoutHandler.makeMeVisible(pid) + if (0 === model.index) { + appLauncherAreaLauncher.visible = true + applicationArea.visible = false + layoutHandler.hideAppLayer() + } + else { + applicationArea.visible = true + appLauncherAreaLauncher.visible = false + pid = launcher.launch(model.application) + layoutHandler.makeMeVisible(pid) + layoutHandler.showAppLayer() + } } } } diff --git a/HomeScreen/qml/images/Home/AGL_HMI_Background_Car-01.png b/HomeScreen/qml/images/Home/AGL_HMI_Background_Car-01.png new file mode 100644 index 0000000..b0072d8 Binary files /dev/null and b/HomeScreen/qml/images/Home/AGL_HMI_Background_Car-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Connectivity_Active-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Connectivity_Active-01.png new file mode 100644 index 0000000..888d0bd Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Connectivity_Active-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Connectivity_Inactive-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Connectivity_Inactive-01.png new file mode 100644 index 0000000..ab83b0e Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Connectivity_Inactive-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Dashboard_Active-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Dashboard_Active-01.png new file mode 100644 index 0000000..11d39e5 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Dashboard_Active-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Dashboard_Inactive-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Dashboard_Inactive-01.png new file mode 100644 index 0000000..6c0b914 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Dashboard_Inactive-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_HVAC_Active-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_HVAC_Active-01.png new file mode 100644 index 0000000..efc11e9 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_HVAC_Active-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_HVAC_Inactive-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_HVAC_Inactive-01.png new file mode 100644 index 0000000..b528376 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_HVAC_Inactive-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Multimedia_Active-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Multimedia_Active-01.png new file mode 100644 index 0000000..1c99ac4 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Multimedia_Active-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Multimedia_Inactive-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Multimedia_Inactive-01.png new file mode 100644 index 0000000..0bed61d Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Multimedia_Inactive-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Navigation_Active-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Navigation_Active-01.png new file mode 100644 index 0000000..e7ad085 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Navigation_Active-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Navigation_Inactive-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Navigation_Inactive-01.png new file mode 100644 index 0000000..dd40750 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Navigation_Inactive-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_POI_Active-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_POI_Active-01.png new file mode 100644 index 0000000..2df01d3 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_POI_Active-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_POI_Inactive-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_POI_Inactive-01.png new file mode 100644 index 0000000..ec62b87 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_POI_Inactive-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Phone_Active-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Phone_Active-01.png new file mode 100644 index 0000000..2150581 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Phone_Active-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Phone_Inactive-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Phone_Inactive-01.png new file mode 100644 index 0000000..61dcedc Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Phone_Inactive-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Radio_Active-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Radio_Active-01.png new file mode 100644 index 0000000..1aa5a01 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Radio_Active-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Radio_Inactive-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Radio_Inactive-01.png new file mode 100644 index 0000000..616983e Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Radio_Inactive-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Settings_Active-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Settings_Active-01.png new file mode 100644 index 0000000..1d13fd6 Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Settings_Active-01.png differ diff --git a/HomeScreen/qml/images/Home/HMI_AppLauncher_Settings_Inactive-01.png b/HomeScreen/qml/images/Home/HMI_AppLauncher_Settings_Inactive-01.png new file mode 100644 index 0000000..027f1fe Binary files /dev/null and b/HomeScreen/qml/images/Home/HMI_AppLauncher_Settings_Inactive-01.png differ diff --git a/HomeScreen/qml/images/Home/home.qrc b/HomeScreen/qml/images/Home/home.qrc new file mode 100644 index 0000000..7dde212 --- /dev/null +++ b/HomeScreen/qml/images/Home/home.qrc @@ -0,0 +1,23 @@ + + + AGL_HMI_Background_Car-01.png + HMI_AppLauncher_Connectivity_Active-01.png + HMI_AppLauncher_Connectivity_Inactive-01.png + HMI_AppLauncher_Dashboard_Active-01.png + HMI_AppLauncher_Dashboard_Inactive-01.png + HMI_AppLauncher_HVAC_Active-01.png + HMI_AppLauncher_HVAC_Inactive-01.png + HMI_AppLauncher_Multimedia_Active-01.png + HMI_AppLauncher_Multimedia_Inactive-01.png + HMI_AppLauncher_Navigation_Active-01.png + HMI_AppLauncher_Navigation_Inactive-01.png + HMI_AppLauncher_Phone_Active-01.png + HMI_AppLauncher_Phone_Inactive-01.png + HMI_AppLauncher_POI_Active-01.png + HMI_AppLauncher_POI_Inactive-01.png + HMI_AppLauncher_Radio_Active-01.png + HMI_AppLauncher_Radio_Inactive-01.png + HMI_AppLauncher_Settings_Active-01.png + HMI_AppLauncher_Settings_Inactive-01.png + + diff --git a/HomeScreen/qml/main.qml b/HomeScreen/qml/main.qml index 542f395..143d649 100644 --- a/HomeScreen/qml/main.qml +++ b/HomeScreen/qml/main.qml @@ -18,6 +18,7 @@ import QtQuick 2.2 import QtQuick.Window 2.1 import QtQuick.Layouts 1.1 +import HomeScreen 1.0 Window { visible: true @@ -26,6 +27,14 @@ Window { height: container.height * container.scale title: 'HomeScreen' + ApplicationLauncher { + id: launcher + } + + LayoutHandler { + id: layoutHandler + } + Image { id: container anchors.centerIn: parent @@ -48,6 +57,16 @@ Window { Layout.fillWidth: true Layout.fillHeight: true Layout.preferredHeight: 1920 - 218 - 215 + + visible: true + } + + Home { + id: appLauncherAreaLauncher + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: 1920 - 218 - 215 + visible: false } MediaArea { diff --git a/HomeScreen/qml/qml.qrc b/HomeScreen/qml/qml.qrc index a916b03..3d699e0 100644 --- a/HomeScreen/qml/qml.qrc +++ b/HomeScreen/qml/qml.qrc @@ -1,5 +1,6 @@ + Home.qml main.qml MediaArea.qml MediaAreaBlank.qml diff --git a/HomeScreen/src/main.cpp b/HomeScreen/src/main.cpp index 99f98c9..ac798a9 100644 --- a/HomeScreen/src/main.cpp +++ b/HomeScreen/src/main.cpp @@ -23,7 +23,7 @@ #include "../src2/applicationlauncher.h" #include "../src2/statusbarmodel.h" #include "layouthandler.h" - +#include "../src2/applicationmodel.h" int main(int argc, char *argv[]) { @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) qDBusRegisterMetaType >(); qmlRegisterType("HomeScreen", 1, 0, "ApplicationLauncher"); + qmlRegisterType("Home", 1, 0, "ApplicationModel"); qmlRegisterType("HomeScreen", 1, 0, "StatusBarModel"); qmlRegisterType("HomeScreen", 1, 0, "LayoutHandler"); diff --git a/HomeScreen/src2/appinfo.cpp b/HomeScreen/src2/appinfo.cpp new file mode 100644 index 0000000..6b61632 --- /dev/null +++ b/HomeScreen/src2/appinfo.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH + * Copyright (C) 2016 The Qt Company Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "appinfo.h" + +#include + +class AppInfo::Private : public QSharedData +{ +public: + Private(); + Private(const Private &other); + + QString id; + QString version; + int width; + int height; + QString name; + QString description; + QString shortname; + QString author; + QString iconPath; +}; + +AppInfo::Private::Private() + : width(-1) + , height(-1) +{ +} + +AppInfo::Private::Private(const Private &other) + : QSharedData(other) + , id(other.id) + , version(other.version) + , width(other.width) + , height(other.height) + , name(other.name) + , description(other.description) + , shortname(other.shortname) + , author(other.author) + , iconPath(other.iconPath) +{ +} + +AppInfo::AppInfo() + : d(new Private) +{ +} + +AppInfo::AppInfo(const QString &icon, const QString &name, const QString &id) + : d(new Private) +{ + d->iconPath = icon; + d->name = name; + d->id = id; +} + +AppInfo::AppInfo(const AppInfo &other) + : d(other.d) +{ +} + +AppInfo::~AppInfo() +{ +} + +AppInfo &AppInfo::operator =(const AppInfo &other) +{ + d = other.d; + return *this; +} + +QString AppInfo::id() const +{ + return d->id; +} + +QString AppInfo::version() const +{ + return d->version; +} + +int AppInfo::width() const +{ + return d->width; +} + +int AppInfo::height() const +{ + return d->height; +} + +QString AppInfo::name() const +{ + return d->name; +} + +QString AppInfo::description() const +{ + return d->description; +} + +QString AppInfo::shortname() const +{ + return d->shortname; +} + +QString AppInfo::author() const +{ + return d->author; +} + +QString AppInfo::iconPath() const +{ + return d->iconPath; +} + +void AppInfo::read(const QJsonObject &json) +{ + d->id = json["id"].toString(); + d->version = json["version"].toString(); + d->width = json["width"].toInt(); + d->height = json["height"].toInt(); + d->name = json["name"].toString(); + d->description = json["description"].toString(); + d->shortname = json["shortname"].toString(); + d->author = json["author"].toString(); + d->iconPath = json["iconPath"].toString(); +} + +QDBusArgument &operator <<(QDBusArgument &argument, const AppInfo &appInfo) +{ + argument.beginStructure(); + argument << appInfo.d->id; + argument << appInfo.d->version; + argument << appInfo.d->width; + argument << appInfo.d->height; + argument << appInfo.d->name; + argument << appInfo.d->description; + argument << appInfo.d->shortname; + argument << appInfo.d->author; + argument << appInfo.d->iconPath; + argument.endStructure(); + + return argument; +} + +const QDBusArgument &operator >>(const QDBusArgument &argument, AppInfo &appInfo) +{ + argument.beginStructure(); + argument >> appInfo.d->id; + argument >> appInfo.d->version; + argument >> appInfo.d->width; + argument >> appInfo.d->height; + argument >> appInfo.d->name; + argument >> appInfo.d->description; + argument >> appInfo.d->shortname; + argument >> appInfo.d->author; + argument >> appInfo.d->iconPath; + argument.endStructure(); + return argument; +} diff --git a/HomeScreen/src2/appinfo.h b/HomeScreen/src2/appinfo.h new file mode 100644 index 0000000..a800a80 --- /dev/null +++ b/HomeScreen/src2/appinfo.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH + * Copyright (C) 2016 The Qt Company Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APPINFO_H +#define APPINFO_H + +#include +#include + +class AppInfo +{ + Q_GADGET + Q_PROPERTY(QString id READ id) + Q_PROPERTY(QString version READ version) + Q_PROPERTY(int width READ width) + Q_PROPERTY(int height READ height) + Q_PROPERTY(QString name READ name) + Q_PROPERTY(QString description READ description) + Q_PROPERTY(QString shortname READ shortname) + Q_PROPERTY(QString author READ author) + Q_PROPERTY(QString iconPath READ iconPath) +public: + AppInfo(); + AppInfo(const QString &icon, const QString &name, const QString &id); + AppInfo(const AppInfo &other); + virtual ~AppInfo(); + AppInfo &operator =(const AppInfo &other); + void swap(AppInfo &other) { qSwap(d, other.d); } + + QString id() const; + QString version() const; + int width() const; + int height() const; + QString name() const; + QString description() const; + QString shortname() const; + QString author() const; + QString iconPath() const; + + void read(const QJsonObject &json); + + friend QDBusArgument &operator <<(QDBusArgument &argument, const AppInfo &appInfo); + friend const QDBusArgument &operator >>(const QDBusArgument &argument, AppInfo &appInfo); + +private: + class Private; + QSharedDataPointer d; +}; + +Q_DECLARE_SHARED(AppInfo) +Q_DECLARE_METATYPE(AppInfo) +Q_DECLARE_METATYPE(QList) + +#endif // APPINFO_H diff --git a/HomeScreen/src2/applicationmodel.cpp b/HomeScreen/src2/applicationmodel.cpp new file mode 100644 index 0000000..b8bbb38 --- /dev/null +++ b/HomeScreen/src2/applicationmodel.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2016 The Qt Company Ltd. + * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "applicationmodel.h" +#include "appinfo.h" + +#include +#include + +class ApplicationModel::Private +{ +public: + Private(ApplicationModel *parent); + +private: + ApplicationModel *q; +public: + QDBusInterface proxy; + QList data; +}; + +ApplicationModel::Private::Private(ApplicationModel *parent) + : q(parent) + , proxy(QStringLiteral("org.agl.homescreenappframeworkbinder"), QStringLiteral("/AppFramework"), QStringLiteral("org.agl.appframework"), QDBusConnection::sessionBus()) +{ + QDBusReply> reply = proxy.call("getAvailableApps"); + if (false)/*reply.isValid()) TODO: test for CES! */ { + data = reply.value(); + } else { + data.append(AppInfo(QStringLiteral("HVAC"), QStringLiteral("HVAC"), QStringLiteral("hvac@0.1"))); + data.append(AppInfo(QStringLiteral("Navigation"), QStringLiteral("NAVIGATION"), QStringLiteral("navigation@0.1"))); + data.append(AppInfo(QStringLiteral("Phone"), QStringLiteral("PHONE"), QStringLiteral("phone@0.1"))); + data.append(AppInfo(QStringLiteral("Radio"), QStringLiteral("RADIO"), QStringLiteral("radio@0.1"))); + data.append(AppInfo(QStringLiteral("Multimedia"), QStringLiteral("MULTIMEDIA"), QStringLiteral("multimedia@0.1"))); + data.append(AppInfo(QStringLiteral("Connectivity"), QStringLiteral("CONNECTIVITY"), QStringLiteral("connectivity@0.1"))); + data.append(AppInfo(QStringLiteral("Dashboard"), QStringLiteral("DASHBOARD"), QStringLiteral("dashboard@0.1"))); + data.append(AppInfo(QStringLiteral("Settings"), QStringLiteral("SETTINGS"), QStringLiteral("settings@0.1"))); + data.append(AppInfo(QStringLiteral("POI"), QStringLiteral("POINT OF\nINTEREST"), QStringLiteral("poi@0.1"))); + } +} + +ApplicationModel::ApplicationModel(QObject *parent) + : QAbstractListModel(parent) + , d(new Private(this)) +{ +} + +ApplicationModel::~ApplicationModel() +{ + delete d; +} + +int ApplicationModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return d->data.count(); +} + +QVariant ApplicationModel::data(const QModelIndex &index, int role) const +{ + QVariant ret; + if (!index.isValid()) + return ret; + + switch (role) { + case Qt::DecorationRole: + ret = d->data[index.row()].iconPath(); + break; + case Qt::DisplayRole: + ret = d->data[index.row()].name(); + break; + case Qt::UserRole: + ret = d->data[index.row()].id(); + break; + default: + break; + } + + return ret; +} + +QHash ApplicationModel::roleNames() const +{ + QHash roles; + roles[Qt::DecorationRole] = "icon"; + roles[Qt::DisplayRole] = "name"; + roles[Qt::UserRole] = "id"; + return roles; +} diff --git a/HomeScreen/src2/applicationmodel.h b/HomeScreen/src2/applicationmodel.h new file mode 100644 index 0000000..bffc4c9 --- /dev/null +++ b/HomeScreen/src2/applicationmodel.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2016 The Qt Company Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APPLICATIONMODEL_H +#define APPLICATIONMODEL_H + +#include + +class ApplicationModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit ApplicationModel(QObject *parent = nullptr); + ~ApplicationModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + +private: + class Private; + Private *d; +}; + +#endif // APPLICATIONMODEL_H