From 9f227dc72607106641269560608b0297358adfa8 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Tue, 28 Feb 2017 18:55:58 -0500 Subject: Import latest Chinook code from CES2017 repo Change-Id: I52a49fa8b3b8ba33157622c7bc78c6bfae793196 Signed-off-by: Scott Murray --- app/PresetDataObject.cpp | 63 +++++ app/PresetDataObject.h | 57 ++++ app/Radio.qml | 230 ++++++++++++++++ app/app.pri | 12 + app/app.pro | 11 + app/config.tests/libhomescreen/libhomescreen.cpp | 8 + app/config.tests/libhomescreen/libhomescreen.pro | 5 + app/images/AGL_MediaPlayer_BackArrow.svg | 56 ++++ app/images/AGL_MediaPlayer_ForwardArrow.svg | 56 ++++ app/images/AGL_MediaPlayer_Player_Pause.svg | 67 +++++ app/images/AGL_MediaPlayer_Player_Play.svg | 67 +++++ app/images/FM_Icons_AM.svg | 71 +++++ app/images/FM_Icons_FM.svg | 65 +++++ app/images/HMI_Radio_Equalizer.svg | 335 +++++++++++++++++++++++ app/images/Radio_Active_Icon.svg | 299 ++++++++++++++++++++ app/images/images.qrc | 12 + app/main.cpp | 83 ++++++ app/radio.qrc | 5 + 18 files changed, 1502 insertions(+) create mode 100644 app/PresetDataObject.cpp create mode 100644 app/PresetDataObject.h create mode 100644 app/Radio.qml create mode 100644 app/app.pri create mode 100644 app/app.pro create mode 100644 app/config.tests/libhomescreen/libhomescreen.cpp create mode 100644 app/config.tests/libhomescreen/libhomescreen.pro create mode 100644 app/images/AGL_MediaPlayer_BackArrow.svg create mode 100644 app/images/AGL_MediaPlayer_ForwardArrow.svg create mode 100644 app/images/AGL_MediaPlayer_Player_Pause.svg create mode 100644 app/images/AGL_MediaPlayer_Player_Play.svg create mode 100644 app/images/FM_Icons_AM.svg create mode 100644 app/images/FM_Icons_FM.svg create mode 100644 app/images/HMI_Radio_Equalizer.svg create mode 100644 app/images/Radio_Active_Icon.svg create mode 100644 app/images/images.qrc create mode 100644 app/main.cpp create mode 100644 app/radio.qrc (limited to 'app') diff --git a/app/PresetDataObject.cpp b/app/PresetDataObject.cpp new file mode 100644 index 0000000..6e69626 --- /dev/null +++ b/app/PresetDataObject.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016 by Scott Murray + * + * 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 "PresetDataObject.h" + +PresetDataObject::PresetDataObject(QObject *parent) : QObject(parent) +{ +} + +PresetDataObject::PresetDataObject(const QString &title, const quint32 &frequency, const quint32 &band, QObject *parent) + : QObject(parent), m_title(title), m_frequency(frequency), m_band(band) +{ +} + +QString PresetDataObject::title() const +{ + return m_title; +} + +void PresetDataObject::setTitle(const QString &title) +{ + if (title != m_title) { + m_title = title; + emit titleChanged(); + } +} + +quint32 PresetDataObject::frequency() const +{ + return m_frequency; +} + +void PresetDataObject::setFrequency(const quint32 &frequency) { + if (frequency != m_frequency) { + m_frequency = frequency; + emit frequencyChanged(); + } +} + +quint32 PresetDataObject::band() const +{ + return m_band; +} + +void PresetDataObject::setBand(const quint32 &band) { + if (band != m_band) { + m_band = band; + emit bandChanged(); + } +} diff --git a/app/PresetDataObject.h b/app/PresetDataObject.h new file mode 100644 index 0000000..a43b853 --- /dev/null +++ b/app/PresetDataObject.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2016 by Scott Murray + * + * 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 PRESETDATAOBJECT_H +#define PRESETDATAOBJECT_H + +#include + +class PresetDataObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) + Q_PROPERTY(quint32 frequency READ frequency WRITE setFrequency NOTIFY frequencyChanged) + Q_PROPERTY(quint32 band READ band WRITE setBand NOTIFY bandChanged) + +public: + PresetDataObject(QObject *parent = Q_NULLPTR); + PresetDataObject(const QString &title, const quint32 &frequency, const quint32 &band, QObject *parent = Q_NULLPTR); + + QString title() const; + + void setTitle(const QString &title); + + quint32 frequency() const; + + void setFrequency(const quint32 &frequency); + + quint32 band() const; + + void setBand(const quint32 &band); + +signals: + void titleChanged(); + void frequencyChanged(); + void bandChanged(); + +private: + QString m_title; + quint32 m_frequency; + quint32 m_band; +}; + +#endif // PRESETDATAOBJECT_H diff --git a/app/Radio.qml b/app/Radio.qml new file mode 100644 index 0000000..8bcd56e --- /dev/null +++ b/app/Radio.qml @@ -0,0 +1,230 @@ +/* + * 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.6 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.0 +import QtMultimedia 5.5 +import AGL.Demo.Controls 1.0 + +ApplicationWindow { + id: root + + Radio { + id: radio + property string title + onBandChanged: frequency = minimumFrequency + onStationFound: title = stationId + onFrequencyChanged: { + title = '' + slider.value = frequency + } + + function freq2str(freq) { + if (freq > 5000000) { + return '%1 MHz'.arg((freq / 1000000).toFixed(1)) + } else { + return '%1 kHz'.arg((freq / 1000).toFixed(0)) + } + } + } + + ColumnLayout { + anchors.fill: parent + Item { + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: 3 + clip: true + Image { + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + fillMode: Image.PreserveAspectFit + source: './images/HMI_Radio_Equalizer.svg' + } + Item { + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + height :307 + Rectangle { + anchors.fill: parent + color: 'black' + opacity: 0.75 + } + + ColumnLayout { + anchors.fill: parent + anchors.margins: root.width * 0.02 + Item { + Layout.fillWidth: true + Layout.fillHeight: true + Row { + spacing: 20 + Image { + source: './images/FM_Icons_FM.svg' + } +// ToggleButton { +// offImage: './images/FM_Icons_FM.svg' +// onImage: './images/FM_Icons_AM.svg' +// onCheckedChanged: { +// radio.band = checked ? Radio.AM : Radio.FM +// radio.frequency = radio.minimumFrequency +// } +// } + } + ColumnLayout { + anchors.fill: parent + Label { + id: label + Layout.alignment: Layout.Center + text: radio.freq2str(radio.frequency) + horizontalAlignment: Label.AlignHCenter + verticalAlignment: Label.AlignVCenter + } + Label { + id: artist + Layout.alignment: Layout.Center + text: radio.title + horizontalAlignment: Label.AlignHCenter + verticalAlignment: Label.AlignVCenter + font.pixelSize: label.font.pixelSize * 0.6 + } + } + } + Slider { + id: slider + Layout.fillWidth: true + from: radio.minimumFrequency + to: radio.maximumFrequency + stepSize: radio.frequencyStep + snapMode: Slider.SnapOnRelease + onValueChanged: radio.frequency = value + Label { + anchors.left: parent.left + anchors.bottom: parent.top + font.pixelSize: 32 + text: radio.freq2str(radio.minimumFrequency) + } + Label { + anchors.right: parent.right + anchors.bottom: parent.top + font.pixelSize: 32 + text: radio.freq2str(radio.maximumFrequency) + } + } + RowLayout { + Layout.fillHeight: true + Item { Layout.fillWidth: true } + ImageButton { + offImage: './images/AGL_MediaPlayer_BackArrow.svg' + Timer { + running: parent.pressed + triggeredOnStart: true + interval: 100 + repeat: true + onTriggered: radio.tuneDown() + } + } + ImageButton { + id: play + offImage: './images/AGL_MediaPlayer_Player_Play.svg' + onClicked: radio.start() + states: [ + State { + when: radio.state === Radio.ActiveState + PropertyChanges { + target: play + offImage: './images/AGL_MediaPlayer_Player_Pause.svg' + onClicked: radio.stop() + } + } + ] + } + ImageButton { + offImage: './images/AGL_MediaPlayer_ForwardArrow.svg' + Timer { + running: parent.pressed + triggeredOnStart: true + interval: 100 + repeat: true + onTriggered: radio.tuneUp() + } + } + + Item { Layout.fillWidth: true } + } + } + } + } + Item { + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: 2 + ListView { + anchors.fill: parent + anchors.leftMargin: 50 + anchors.rightMargin: 50 + clip: true + header: Label { text: 'PRESETS'; opacity: 0.5 } + model: presetModel + + delegate: MouseArea { + width: ListView.view.width + height: ListView.view.height / 4 + + onClicked: { + radio.band = model.modelData.band + radio.frequency = model.modelData.frequency + radio.title = model.modelData.title + } + + RowLayout { + anchors.fill: parent + Image { + source: './images/Radio_Active_Icon.svg' + } + ColumnLayout { + Layout.fillWidth: true + Label { + Layout.fillWidth: true + text: model.title + } + Label { + Layout.fillWidth: true + text: radio.freq2str(model.frequency) + color: '#59FF7F' + font.pixelSize: 32 + } + } + Image { + source: { + switch (model.modelData.band) { + case Radio.FM: + return './images/FM_Icons_FM.svg' + case Radio.AM: + return './images/FM_Icons_AM.svg' + } + return null + } + } + } + } + } + } + } +} diff --git a/app/app.pri b/app/app.pri new file mode 100644 index 0000000..014646f --- /dev/null +++ b/app/app.pri @@ -0,0 +1,12 @@ +TEMPLATE = app + +load(configure) +qtCompileTest(libhomescreen) + +config_libhomescreen { + CONFIG += link_pkgconfig + PKGCONFIG += homescreen + DEFINES += HAVE_LIBHOMESCREEN +} + +DESTDIR = $${OUT_PWD}/../package/root/bin diff --git a/app/app.pro b/app/app.pro new file mode 100644 index 0000000..e0a927e --- /dev/null +++ b/app/app.pro @@ -0,0 +1,11 @@ +TARGET = radio +QT = quickcontrols2 + +HEADERS = PresetDataObject.h +SOURCES = main.cpp PresetDataObject.cpp + +RESOURCES += \ + radio.qrc \ + images/images.qrc + +include(app.pri) diff --git a/app/config.tests/libhomescreen/libhomescreen.cpp b/app/config.tests/libhomescreen/libhomescreen.cpp new file mode 100644 index 0000000..d698b05 --- /dev/null +++ b/app/config.tests/libhomescreen/libhomescreen.cpp @@ -0,0 +1,8 @@ +#include + +int main(int argc,char **argv) +{ + LibHomeScreen libHomeScreen; + return 0; +} + diff --git a/app/config.tests/libhomescreen/libhomescreen.pro b/app/config.tests/libhomescreen/libhomescreen.pro new file mode 100644 index 0000000..eb4e8f3 --- /dev/null +++ b/app/config.tests/libhomescreen/libhomescreen.pro @@ -0,0 +1,5 @@ +SOURCES = libhomescreen.cpp + +CONFIG -= qt +CONFIG += link_pkgconfig +PKGCONFIG += homescreen diff --git a/app/images/AGL_MediaPlayer_BackArrow.svg b/app/images/AGL_MediaPlayer_BackArrow.svg new file mode 100644 index 0000000..c49b519 --- /dev/null +++ b/app/images/AGL_MediaPlayer_BackArrow.svg @@ -0,0 +1,56 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/app/images/AGL_MediaPlayer_ForwardArrow.svg b/app/images/AGL_MediaPlayer_ForwardArrow.svg new file mode 100644 index 0000000..56576ac --- /dev/null +++ b/app/images/AGL_MediaPlayer_ForwardArrow.svg @@ -0,0 +1,56 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/app/images/AGL_MediaPlayer_Player_Pause.svg b/app/images/AGL_MediaPlayer_Player_Pause.svg new file mode 100644 index 0000000..ee55213 --- /dev/null +++ b/app/images/AGL_MediaPlayer_Player_Pause.svg @@ -0,0 +1,67 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/app/images/AGL_MediaPlayer_Player_Play.svg b/app/images/AGL_MediaPlayer_Player_Play.svg new file mode 100644 index 0000000..c296f8a --- /dev/null +++ b/app/images/AGL_MediaPlayer_Player_Play.svg @@ -0,0 +1,67 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/app/images/FM_Icons_AM.svg b/app/images/FM_Icons_AM.svg new file mode 100644 index 0000000..ea6e5e1 --- /dev/null +++ b/app/images/FM_Icons_AM.svg @@ -0,0 +1,71 @@ + + + +image/svg+xmlFM +AM | + \ No newline at end of file diff --git a/app/images/FM_Icons_FM.svg b/app/images/FM_Icons_FM.svg new file mode 100644 index 0000000..0f3ae59 --- /dev/null +++ b/app/images/FM_Icons_FM.svg @@ -0,0 +1,65 @@ + + + +image/svg+xmlFM +AM | + \ No newline at end of file diff --git a/app/images/HMI_Radio_Equalizer.svg b/app/images/HMI_Radio_Equalizer.svg new file mode 100644 index 0000000..6959144 --- /dev/null +++ b/app/images/HMI_Radio_Equalizer.svg @@ -0,0 +1,335 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/app/images/Radio_Active_Icon.svg b/app/images/Radio_Active_Icon.svg new file mode 100644 index 0000000..383f2cd --- /dev/null +++ b/app/images/Radio_Active_Icon.svg @@ -0,0 +1,299 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/app/images/images.qrc b/app/images/images.qrc new file mode 100644 index 0000000..9161221 --- /dev/null +++ b/app/images/images.qrc @@ -0,0 +1,12 @@ + + + AGL_MediaPlayer_BackArrow.svg + AGL_MediaPlayer_ForwardArrow.svg + AGL_MediaPlayer_Player_Pause.svg + AGL_MediaPlayer_Player_Play.svg + FM_Icons_AM.svg + FM_Icons_FM.svg + HMI_Radio_Equalizer.svg + Radio_Active_Icon.svg + + diff --git a/app/main.cpp b/app/main.cpp new file mode 100644 index 0000000..9d2785e --- /dev/null +++ b/app/main.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2016 The Qt Company Ltd. + * Copyright (C) 2016 Scott Murray + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include "PresetDataObject.h" + + +#ifdef HAVE_LIBHOMESCREEN +#include +#endif + +int main(int argc, char *argv[]) +{ +#ifdef HAVE_LIBHOMESCREEN + LibHomeScreen libHomeScreen; + + if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) { + qWarning() << "renderAppToAreaAllowed is denied"; + return -1; + } +#endif + + QGuiApplication app(argc, argv); + + QQuickStyle::setStyle("AGL"); + + // Read presets from configuration file + // + // If HOME is set, use $HOME/app-data/radio/presets.conf, else fall back + // to the QSettings default locations with organization "AGL" and a + // file name of radio-presets.conf. See: + // + // http://doc.qt.io/qt-5/qsettings.html#platform-specific-notes + // + // for details on the locations and their order of priority. + // + QSettings *pSettings = NULL; + char *p = getenv("HOME"); + if(p) { + QString confPath = p; + confPath.append("/app-data/radio/presets.conf"); + pSettings = new QSettings(confPath, QSettings::NativeFormat); + } else { + pSettings = new QSettings("AGL", "radio-presets"); + } + QList presetDataList; + int size = pSettings->beginReadArray("fmPresets"); + for (int i = 0; i < size; ++i) { + pSettings->setArrayIndex(i); + presetDataList.append(new PresetDataObject(pSettings->value("title").toString(), + pSettings->value("frequency").toInt(), + QRadioTuner::FM)); + } + pSettings->endArray(); + + QQmlApplicationEngine engine; + QQmlContext *context = engine.rootContext(); + context->setContextProperty("presetModel", QVariant::fromValue(presetDataList)); + engine.load(QUrl(QStringLiteral("qrc:/Radio.qml"))); + + return app.exec(); +} diff --git a/app/radio.qrc b/app/radio.qrc new file mode 100644 index 0000000..347894c --- /dev/null +++ b/app/radio.qrc @@ -0,0 +1,5 @@ + + + Radio.qml + + -- cgit 1.2.3-korg