Browse Source

WIP: Play/Pause button doesn't keep it's state when the page is changed

Signed-off-by: Blagovest Petrov <blagovest@petrovs.info>
qt6
Blagovest Petrov 2 years ago
parent
commit
ea2294ccc4
  1. 1
      CMakeLists.txt
  2. 15
      fetchshowid.cpp
  3. 20
      fetchshowid.h
  4. 1
      main.cpp
  5. 5
      tangratray.cpp
  6. 1
      ui/AudioPlayer.qml
  7. 31
      ui/CurrentShow.qml
  8. 18
      ui/MediaButton.qml
  9. 10
      ui/PgLive.qml
  10. 12
      ui/main.qml

1
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}
)

15
fetchshowid.cpp

@ -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")));
}

20
fetchshowid.h

@ -1,20 +0,0 @@
#ifndef FETCHSHOWID_H
#define FETCHSHOWID_H
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QObject>
#include <QDebug>
#include <QString>
class FetchShowID : public QObject
{
public:
FetchShowID();
void Fetch();
private:
QNetworkAccessManager* n_manager;
};
#endif // FETCHSHOWID_H

1
main.cpp

@ -3,6 +3,7 @@
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "tangratray.h"
#include <QSystemTrayIcon>
int main(int argc, char *argv[])
{

5
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()

1
ui/AudioPlayer.qml

@ -4,4 +4,5 @@ import QtMultimedia
MediaPlayer {
audioOutput: AudioOutput {}
source: "http://stream-bg-01.radiotangra.com:8000/Tangra-high"
}

31
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()
}
}

18
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: {

10
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

12
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 }
}
}
}

Loading…
Cancel
Save