From ea2294ccc453715bc9d295d3799840de3151355c Mon Sep 17 00:00:00 2001 From: Blagovest Petrov Date: Sun, 23 Apr 2023 13:43:05 +0300 Subject: [PATCH] WIP: Play/Pause button doesn't keep it's state when the page is changed Signed-off-by: Blagovest Petrov --- CMakeLists.txt | 1 + fetchshowid.cpp | 15 --------------- fetchshowid.h | 20 -------------------- main.cpp | 1 + tangratray.cpp | 5 +++-- ui/AudioPlayer.qml | 1 + ui/CurrentShow.qml | 31 +++++++++++++++++++++++++++++++ ui/MediaButton.qml | 18 +++++++++++++++++- ui/PgLive.qml | 10 +++++++--- ui/main.qml | 12 +++++++++++- 10 files changed, 72 insertions(+), 42 deletions(-) delete mode 100644 fetchshowid.cpp delete mode 100644 fetchshowid.h create mode 100644 ui/CurrentShow.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index fa11680..d5d4977 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,7 @@ qt_add_qml_module(apptangraplay ui/PgLive.qml ui/PgNews.qml ui/NewsDelegate.qml + ui/CurrentShow.qml RESOURCES ${QML_ASSETS} ) diff --git a/fetchshowid.cpp b/fetchshowid.cpp deleted file mode 100644 index 9eaaf28..0000000 --- a/fetchshowid.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "fetchshowid.h" - -FetchShowID::FetchShowID() -{ - n_manager = new QNetworkAccessManager; - - connect(n_manager, SIGNAL(finished(QNetworkReply*)), - this, SLOT(replyFinished(QNetworkReply*))); - -} - - -void FetchShowID::Fetch() { - n_manager->get(QNetworkRequest(QUrl("http://app.radiotangra.com/TMR_monitor_songs"))); -} diff --git a/fetchshowid.h b/fetchshowid.h deleted file mode 100644 index d71a18f..0000000 --- a/fetchshowid.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef FETCHSHOWID_H -#define FETCHSHOWID_H -#include -#include -#include -#include -#include - - -class FetchShowID : public QObject -{ -public: - FetchShowID(); - void Fetch(); - -private: - QNetworkAccessManager* n_manager; -}; - -#endif // FETCHSHOWID_H diff --git a/main.cpp b/main.cpp index e29116d..ebfd18b 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,7 @@ #include #include #include "tangratray.h" +#include int main(int argc, char *argv[]) { diff --git a/tangratray.cpp b/tangratray.cpp index 52de6c3..ee7d4ab 100644 --- a/tangratray.cpp +++ b/tangratray.cpp @@ -16,7 +16,7 @@ TangraTray::TangraTray(QObject *parent) : QObject(parent) trayIcon = new QSystemTrayIcon(); trayIcon->setContextMenu(trayIconMenu); - setTrayIcon(":Resources/tangra.ico"); + setTrayIcon(":/bpetrov.tangraplay/imports/tangra.ico"); trayIcon->show(); @@ -37,8 +37,9 @@ void TangraTray::iconActivated(QSystemTrayIcon::ActivationReason reason) void TangraTray::setTrayIcon(QString image) { - QIcon icon = QIcon(image), tr("Icon"); + QIcon icon = QIcon(image); trayIcon->setIcon(icon); + trayIcon->show(); } void TangraTray::hideIconTray() diff --git a/ui/AudioPlayer.qml b/ui/AudioPlayer.qml index 84b318f..94b2496 100644 --- a/ui/AudioPlayer.qml +++ b/ui/AudioPlayer.qml @@ -4,4 +4,5 @@ import QtMultimedia MediaPlayer { audioOutput: AudioOutput {} source: "http://stream-bg-01.radiotangra.com:8000/Tangra-high" + } diff --git a/ui/CurrentShow.qml b/ui/CurrentShow.qml new file mode 100644 index 0000000..c0bc2fe --- /dev/null +++ b/ui/CurrentShow.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 + +Item { + property string theShow: "" + + function getShow(url) { + let request = new XMLHttpRequest() + + request.onreadystatechange = function () { + if (request.readyState === XMLHttpRequest.DONE) { +// let content = request.response.slice(0, request.response.indexOf("\n")); + let response = { + status : request.status, + headers : request.getAllResponseHeaders(), + content : request.response + }; + }; + theShow = request.responseText.toString().slice(0, request.response.indexOf("\n")); + } + + request.open("GET", "http://app.radiotangra.com/TMR_monitor_songs") + request.send() + } + + Timer { + interval: 30000 + running: true + repeat: true + onTriggered: getShow() + } +} diff --git a/ui/MediaButton.qml b/ui/MediaButton.qml index cb9f204..7daab6e 100644 --- a/ui/MediaButton.qml +++ b/ui/MediaButton.qml @@ -7,15 +7,31 @@ Image { y: 64 property int animationDuration: 250 fillMode: Image.PreserveAspectFit - source: isClicked ? "qrc:/bpetrov.tangraplay/imports/TangraPlay/Assets/buuf-pause.png" : "qrc:/bpetrov.tangraplay/imports/TangraPlay/Assets/buuf-play.png" + source: "qrc:/bpetrov.tangraplay/imports/TangraPlay/Assets/buuf-play.png" property bool isClicked: false + function changeIconState() { + if ( thePlayer.playbackState === 1) { + buttonIcon.source = "qrc:/bpetrov.tangraplay/imports/TangraPlay/Assets/buuf-pause.png" + } + else { + buttonIcon.source = "qrc:/bpetrov.tangraplay/imports/TangraPlay/Assets/buuf-play.png" + } + } + function runAnimation() { glow.visible = true animation1.start() animation2.start() } + Connections { + target: mainStack + function activating() { + buttonIcon.changeIconState() + } + } + MouseArea { anchors.fill: parent onClicked: { diff --git a/ui/PgLive.qml b/ui/PgLive.qml index 43694d3..8217c31 100644 --- a/ui/PgLive.qml +++ b/ui/PgLive.qml @@ -5,6 +5,8 @@ import QtMultimedia 5.15 Item { +// property alias playPauseChangeState: playPause.changeIconState() + Image { id: logo x: 190 @@ -57,9 +59,11 @@ Item { onClicked: { playPause.runAnimation() mediaControl() - playPause.isClicked = !playPause.isClicked +// playPause.isClicked = !playPause.isClicked + playPause.changeIconState() } } + } Text { @@ -89,7 +93,7 @@ Item { id: text1 x: 156 y: 17 - text: qsTr("Предаване в ефир:") + text: qsTr("Предаване в ефир: ") + currentShow.theShow color: "#f9c620" font.family: mainfont.name font.pixelSize: 15 @@ -99,7 +103,7 @@ Item { id: text2 x: 156 y: 60 - text: qsTr("В момента звучи:") + text: qsTr("В момента звучи: Unknown") color: "#f9c620" font.family: mainfont.name font.pixelSize: 15 diff --git a/ui/main.qml b/ui/main.qml index af7f23a..0e23e7a 100644 --- a/ui/main.qml +++ b/ui/main.qml @@ -40,6 +40,13 @@ ApplicationWindow { id: thePlayer } + CurrentShow { + id: currentShow + Component.onCompleted: { + currentShow.getShow(); + } + } + function mediaControl() { if (thePlayer.playbackState != MediaPlayer.PlayingState) { thePlayer.play(); @@ -67,13 +74,16 @@ ApplicationWindow { Component { id: stackLive - PgLive { id: pgLive } + PgLive { + id: pgLive + } } Component { id: stackNews PgNews { id: pgNews } } + } }