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
|
|
@ -59,7 +59,7 @@ Item{
|
|||
width: 60
|
||||
imageSource: "qrc:/icon_previous"
|
||||
|
||||
// visible: model.pHasPrevious
|
||||
enabled: musicModel.pHasPrevious
|
||||
|
||||
onClicked:{
|
||||
musicModel.playPrevious();
|
||||
|
|
@ -69,14 +69,14 @@ Item{
|
|||
id: playPause
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 80
|
||||
imageSource: "qrc:/icon_play"
|
||||
imageSource: musicModel.pIsPlaying ? "qrc:/icon_pause" : "qrc:/icon_play"
|
||||
|
||||
onClicked:{
|
||||
musicModel.playPause();
|
||||
if(imageSource == "qrc:/icon_play")
|
||||
/* if(imageSource == "qrc:/icon_play")
|
||||
imageSource = "qrc:/icon_pause"
|
||||
else
|
||||
imageSource = "qrc:/icon_play"
|
||||
imageSource = "qrc:/icon_play"*/
|
||||
}
|
||||
}
|
||||
RoundButton{
|
||||
|
|
@ -86,9 +86,11 @@ Item{
|
|||
width: 60
|
||||
imageSource: "qrc:/icon_stop"
|
||||
|
||||
enabled: musicModel.pIsPlaying
|
||||
|
||||
onClicked:{
|
||||
musicModel.stopMusic();
|
||||
playPause.imageSource = "qrc:/icon_play"
|
||||
//playPause.imageSource = "qrc:/icon_play"
|
||||
}
|
||||
}
|
||||
RoundButton{
|
||||
|
|
@ -98,7 +100,7 @@ Item{
|
|||
width: 60
|
||||
imageSource: "qrc:/icon_next"
|
||||
|
||||
// visible: model.pHasNext
|
||||
enabled: musicModel.pHasNext
|
||||
|
||||
onClicked:{
|
||||
musicModel.playNext();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,15 @@ Rectangle {
|
|||
height: width
|
||||
source: "qrc:/icon_back"
|
||||
}
|
||||
Rectangle{
|
||||
id: overlay
|
||||
z: 1
|
||||
visible: !container.enabled
|
||||
anchors.centerIn: parent
|
||||
width: 30
|
||||
height: width
|
||||
color: "#99ffffff"
|
||||
}
|
||||
|
||||
MouseArea{
|
||||
id: controlObject
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ MusicController::MusicController(QObject *parent) : QObject(parent)
|
|||
connect(mModel, &MusicModel::navigateTo, [this](NavigationItemModel*){
|
||||
if(mModel->isPlaying()) mModel->playPause();
|
||||
});
|
||||
|
||||
connect(mPlayer, SIGNAL(nextItemSet(VlcMedia*)), mModel, SLOT(onNextMediaSet(VlcMedia*)));
|
||||
}
|
||||
|
||||
MusicController::~MusicController()
|
||||
|
|
|
|||
|
|
@ -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