disable previous and next button
if there is no corresponding media; set play/pause symbol via model property instead of via qml.
This commit is contained in:
parent
a29e8d7a64
commit
6eabd3cb75
5 changed files with 75 additions and 8 deletions
|
|
@ -23,6 +23,11 @@ void MusicModel::init(NavigationItemModel *item)
|
|||
mCurrentItem = item;
|
||||
emit currentItemChanged();
|
||||
|
||||
mHasNext = false;
|
||||
mHasPrevious = false;
|
||||
emit hasNextChanged();
|
||||
emit hasPrevious();
|
||||
|
||||
while(mMedia->count() > 0){
|
||||
mMedia->removeMedia(0);
|
||||
}
|
||||
|
|
@ -46,6 +51,7 @@ void MusicModel::navigateBack()
|
|||
void MusicModel::playPause()
|
||||
{
|
||||
mIsPlaying = !mIsPlaying;
|
||||
emit isPlayingChanged();
|
||||
if(mIsPlaying)
|
||||
emit play();
|
||||
else
|
||||
|
|
@ -56,6 +62,11 @@ void MusicModel::stopMusic()
|
|||
{
|
||||
if(mIsPlaying){
|
||||
mIsPlaying = false;
|
||||
mHasNext = false;
|
||||
mHasPrevious = false;
|
||||
emit hasNextChanged();
|
||||
emit hasPreviousChanged();
|
||||
emit isPlayingChanged();
|
||||
emit stop();
|
||||
}
|
||||
}
|
||||
|
|
@ -63,11 +74,19 @@ void MusicModel::stopMusic()
|
|||
void MusicModel::playNext()
|
||||
{
|
||||
emit next();
|
||||
if(!mIsPlaying){
|
||||
mIsPlaying = true;
|
||||
emit isPlayingChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void MusicModel::playPrevious()
|
||||
{
|
||||
emit previous();
|
||||
if(!mIsPlaying){
|
||||
mIsPlaying = true;
|
||||
emit isPlayingChanged();
|
||||
}
|
||||
}
|
||||
|
||||
NavigationItemModel *MusicModel::getCurrentItem()
|
||||
|
|
@ -84,3 +103,27 @@ bool MusicModel::isPlaying()
|
|||
{
|
||||
return mIsPlaying;
|
||||
}
|
||||
|
||||
bool MusicModel::hasNext()
|
||||
{
|
||||
return mHasNext;
|
||||
}
|
||||
|
||||
bool MusicModel::hasPrevious()
|
||||
{
|
||||
return mHasPrevious;
|
||||
}
|
||||
|
||||
void MusicModel::onNextMediaSet(VlcMedia *media)
|
||||
{
|
||||
mHasNext = true;
|
||||
mHasPrevious = true;
|
||||
if(mMedia->at(0) == media){
|
||||
mHasPrevious = false;
|
||||
}
|
||||
if(mMedia->at(mMedia->count()-1) == media){
|
||||
mHasNext = false;
|
||||
}
|
||||
emit hasPreviousChanged();
|
||||
emit hasNextChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ class MusicModel : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QObject* pCurrentItem READ getCurrentItem NOTIFY currentItemChanged)
|
||||
//Q_PROPERTY(QObject* pHasNext READ hasNext NOTIFY hasNextChanged)
|
||||
//Q_PROPERTY(QObject* pHasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
|
||||
Q_PROPERTY(bool pHasNext READ hasNext NOTIFY hasNextChanged)
|
||||
Q_PROPERTY(bool pHasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
|
||||
Q_PROPERTY(bool pIsPlaying READ isPlaying NOTIFY isPlayingChanged)
|
||||
|
||||
signals:
|
||||
void navigateTo(NavigationItemModel *item);
|
||||
|
|
@ -22,6 +23,9 @@ signals:
|
|||
void stop();
|
||||
void previous();
|
||||
void next();
|
||||
void hasPreviousChanged();
|
||||
void hasNextChanged();
|
||||
void isPlayingChanged();
|
||||
|
||||
public:
|
||||
MusicModel(VlcInstance* instance, QObject *parent = Q_NULLPTR);
|
||||
|
|
@ -40,9 +44,16 @@ public:
|
|||
VlcMediaList *getMedia();
|
||||
|
||||
bool isPlaying();
|
||||
bool hasNext();
|
||||
bool hasPrevious();
|
||||
|
||||
public slots:
|
||||
void onNextMediaSet(VlcMedia* media);
|
||||
|
||||
private:
|
||||
bool mIsPlaying = false;
|
||||
bool mHasNext = false;
|
||||
bool mHasPrevious = false;
|
||||
NavigationItemModel* mCurrentItem = Q_NULLPTR;
|
||||
VlcMediaList* mMedia = Q_NULLPTR;
|
||||
VlcInstance* mVlc;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue