4
0
mirror of https://github.com/QuasarApp/SoundBand.git synced 2025-05-07 12:39:33 +00:00

fix curreng sing id

This commit is contained in:
Andrei Yankovich 2018-03-09 23:38:17 +03:00
parent 1148537a36
commit f7ea3f5209
9 changed files with 95 additions and 38 deletions

@ -13,6 +13,7 @@ Item{
readonly property real textmargin: Utils.dp(Screen.pixelDensity, 8)
readonly property real textSize: Utils.dp(Screen.pixelDensity, 10)
readonly property real buttonHeight: Utils.dp(Screen.pixelDensity, 24)
readonly property int curentSongId: currentPlayListModel.curentSongId;
signal cyrentsongChanged(int id, string name)
@ -20,10 +21,12 @@ Item{
}
function onItemClick(id, name) {
syncEngine.play(id);
cyrentsongChanged(id, name);
onCurentSongIdChanged: {
cyrentsongChanged(curentSongId, currentPlayListModel.curentSongName());
}
function onItemClick(id) {
syncEngine.play(id);
}
ListView {
@ -42,7 +45,7 @@ Item{
id: item
Rectangle {
color: Qt.rgba(0,0,0,0)
color: (curentSongId === songId)? Utils.primaryColor(): Utils.baseColor();
id: rectangle;
anchors.fill: item
@ -50,7 +53,7 @@ Item{
id: playButton
text: qsTr("Play")
onClicked: {
onItemClick(songId, songName);
onItemClick(songId);
}

@ -71,7 +71,7 @@ Item {
text: qsTr("<<")
anchors.left: parent.left
onCanceled: {
onClicked: {
syncEngine.prev();
}
}
@ -83,9 +83,8 @@ Item {
anchors.left: prev.right
onClicked: {
curentPlayList.playSelected();
// syncEngine.pause(playState);
// playState = !playState;
syncEngine.pause(playState);
playState = !playState;
}
}
@ -96,7 +95,7 @@ Item {
text: qsTr(">>")
anchors.right: parent.right
onCanceled: {
onClicked: {
syncEngine.next();
}
}

@ -3,11 +3,11 @@ function dp(pixelDensity,x) {
}
function baseColor() {
return "#f26e35"
return "#303030"
}
function primaryColor() {
return "#d04828"
return "#acacac"
}
function textColor() {

@ -11,10 +11,14 @@ CurentPlayListModel::CurentPlayListModel(QObject *parent) :
}
void CurentPlayListModel::setSource(SyncEngine *engine){
if(syncEngine)
disconnect(syncEngine, SIGNAL(curentPlayListCountChanged()) ,this, SLOT(onPlayListChanged()));
if(syncEngine){
disconnect(syncEngine, SIGNAL(curentPlayListCountChanged()) , this, SLOT(onPlayListChanged()));
disconnect(syncEngine, SIGNAL(curentSongChanged()), this, SIGNAL(curentSongIdChanged()));
}
syncEngine = engine;
connect(syncEngine, SIGNAL(curentPlayListCountChanged()),this ,SLOT(onPlayListChanged()));
connect(syncEngine, SIGNAL(curentPlayListCountChanged()), this ,SLOT(onPlayListChanged()));
connect(syncEngine, SIGNAL(curentSongChanged()), this ,SIGNAL(curentSongIdChanged()));
}
QHash<int, QByteArray> CurentPlayListModel::roleNames()const{
@ -80,3 +84,7 @@ QVariant CurentPlayListModel::data(const QModelIndex &index, int role) const
int CurentPlayListModel::curentSongId(){
return syncEngine->curentSongId();
}
QString CurentPlayListModel::curentSongName(){
return syncEngine->curentSongName();
}

@ -84,6 +84,12 @@ public slots:
* @return id of curent song
*/
int curentSongId();
/**
* @brief curentSongName
* @return name of curent song
*/
QString curentSongName();
};
#endif // CURENTPLAYLISTMODEL_H

@ -10,6 +10,7 @@ SyncEngine::SyncEngine()
connect(sync, SIGNAL(networkStateChange()), this, SIGNAL(serversCountChanged()));
connect(sync, SIGNAL(curentPlayListChanged()), this, SIGNAL(curentPlayListCountChanged()));
connect(sync, SIGNAL(seekChanged(qint64)), this, SLOT(seekChanged(qint64)));
connect(sync, SIGNAL(curentSongChanged()), this, SIGNAL(curentSongChanged()));
}
@ -17,12 +18,22 @@ void SyncEngine::seekChanged(qint64){
emit posChanged();
}
int SyncEngine::curentSongIndex()const{
return sync->getCurentSongIndex();
QString SyncEngine::curentSongName()const{
auto song = sync->getCurentSong();
if(!song)
return tr("none");
return song->name;
}
int SyncEngine::curentSongId()const{
return sync->getCurentSong()->id;
auto song = sync->getCurentSong();
if(!song)
return -1;
return song->id;
}
bool SyncEngine::selectPlayList(const QString &list){
@ -94,19 +105,11 @@ bool SyncEngine::pause(bool state){
}
bool SyncEngine::next(){
_lastError = tr("This option not supported.");
emit error();
return false;
return sync->next();
}
bool SyncEngine::prev(){
_lastError = tr("This option not supported.");
emit error();
return false;
return sync->prev();
}
bool SyncEngine::listen(int index){

@ -61,10 +61,10 @@ public:
public slots:
/**
* @brief curentSongIndex
* @return index of curent cong in selected playlist.
* @brief curentSongName
* @return Name of curent cong in selected playlist.
*/
int curentSongIndex()const;
QString curentSongName()const;
/**
* @brief curentSong
@ -233,12 +233,6 @@ public slots:
signals:
/**
* @brief curentSongChanged
* This signal can be emitted when curent Music changed
*/
void curentSongChanged();
/**
* @brief error
* This signal can be emitted when error has been detected
@ -281,6 +275,12 @@ signals:
*/
void curentPlayListCountChanged();
/**
* @brief curentSongChanged
* emited when changed a playing song
*/
void curentSongChanged();
};
#endif // SYNCENGINE_H

@ -102,6 +102,7 @@ bool Sync::play(const Song &song, bool fbroadcast){
player->syncBegin();
}
emit curentSongChanged();
return true;
}
@ -459,7 +460,7 @@ int Sync::getCurentSongIndex()const{
}
const SongHeader* Sync::getCurentSong() const{
if(curentSongIndex < 0){
if(curentSongIndex < 0 || curentSongIndex >= playList.size()){
return nullptr;
}
return &playList[curentSongIndex];
@ -491,6 +492,24 @@ bool Sync::updatePlayList(const QString &_playList){
}
bool Sync::next(){
if(playList.isEmpty())
return false;
curentSongIndex = (curentSongIndex + 1) % playList.size();
return play(playList[curentSongIndex]);
}
bool Sync::prev(){
if(playList.isEmpty())
return false;
--curentSongIndex;
if(curentSongIndex < 0)
curentSongIndex = playList.size() - 1;
return play(playList[curentSongIndex]);
}
Sync::~Sync(){
delete node;
delete player;

@ -54,6 +54,7 @@ private:
* @return true if everything's done
*/
bool createPackage(Type type , package& pac);
private slots:
/**
@ -238,6 +239,18 @@ public:
*/
bool updatePlayList(const QString& _playList);
/**
* @brief next
* @return true if all done;
*/
bool next();
/**
* @brief prev
* @return true if all done;
*/
bool prev();
Sync(const QString &address = DEFAULT_ADRESS, int port = DEFAULT_PORT, const QString& datadir = DATABASE_NAME);
~Sync();
@ -268,6 +281,12 @@ signals:
*/
void selectedNewPlatList();
/**
* @brief curentSongChanged
* emited when changed a playing song
*/
void curentSongChanged();
};
}