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
|
width: 60
|
||||||
imageSource: "qrc:/icon_previous"
|
imageSource: "qrc:/icon_previous"
|
||||||
|
|
||||||
// visible: model.pHasPrevious
|
enabled: musicModel.pHasPrevious
|
||||||
|
|
||||||
onClicked:{
|
onClicked:{
|
||||||
musicModel.playPrevious();
|
musicModel.playPrevious();
|
||||||
|
|
@ -69,14 +69,14 @@ Item{
|
||||||
id: playPause
|
id: playPause
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
width: 80
|
width: 80
|
||||||
imageSource: "qrc:/icon_play"
|
imageSource: musicModel.pIsPlaying ? "qrc:/icon_pause" : "qrc:/icon_play"
|
||||||
|
|
||||||
onClicked:{
|
onClicked:{
|
||||||
musicModel.playPause();
|
musicModel.playPause();
|
||||||
if(imageSource == "qrc:/icon_play")
|
/* if(imageSource == "qrc:/icon_play")
|
||||||
imageSource = "qrc:/icon_pause"
|
imageSource = "qrc:/icon_pause"
|
||||||
else
|
else
|
||||||
imageSource = "qrc:/icon_play"
|
imageSource = "qrc:/icon_play"*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RoundButton{
|
RoundButton{
|
||||||
|
|
@ -86,9 +86,11 @@ Item{
|
||||||
width: 60
|
width: 60
|
||||||
imageSource: "qrc:/icon_stop"
|
imageSource: "qrc:/icon_stop"
|
||||||
|
|
||||||
|
enabled: musicModel.pIsPlaying
|
||||||
|
|
||||||
onClicked:{
|
onClicked:{
|
||||||
musicModel.stopMusic();
|
musicModel.stopMusic();
|
||||||
playPause.imageSource = "qrc:/icon_play"
|
//playPause.imageSource = "qrc:/icon_play"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RoundButton{
|
RoundButton{
|
||||||
|
|
@ -98,7 +100,7 @@ Item{
|
||||||
width: 60
|
width: 60
|
||||||
imageSource: "qrc:/icon_next"
|
imageSource: "qrc:/icon_next"
|
||||||
|
|
||||||
// visible: model.pHasNext
|
enabled: musicModel.pHasNext
|
||||||
|
|
||||||
onClicked:{
|
onClicked:{
|
||||||
musicModel.playNext();
|
musicModel.playNext();
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,15 @@ Rectangle {
|
||||||
height: width
|
height: width
|
||||||
source: "qrc:/icon_back"
|
source: "qrc:/icon_back"
|
||||||
}
|
}
|
||||||
|
Rectangle{
|
||||||
|
id: overlay
|
||||||
|
z: 1
|
||||||
|
visible: !container.enabled
|
||||||
|
anchors.centerIn: parent
|
||||||
|
width: 30
|
||||||
|
height: width
|
||||||
|
color: "#99ffffff"
|
||||||
|
}
|
||||||
|
|
||||||
MouseArea{
|
MouseArea{
|
||||||
id: controlObject
|
id: controlObject
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ MusicController::MusicController(QObject *parent) : QObject(parent)
|
||||||
connect(mModel, &MusicModel::navigateTo, [this](NavigationItemModel*){
|
connect(mModel, &MusicModel::navigateTo, [this](NavigationItemModel*){
|
||||||
if(mModel->isPlaying()) mModel->playPause();
|
if(mModel->isPlaying()) mModel->playPause();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(mPlayer, SIGNAL(nextItemSet(VlcMedia*)), mModel, SLOT(onNextMediaSet(VlcMedia*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
MusicController::~MusicController()
|
MusicController::~MusicController()
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@ void MusicModel::init(NavigationItemModel *item)
|
||||||
mCurrentItem = item;
|
mCurrentItem = item;
|
||||||
emit currentItemChanged();
|
emit currentItemChanged();
|
||||||
|
|
||||||
|
mHasNext = false;
|
||||||
|
mHasPrevious = false;
|
||||||
|
emit hasNextChanged();
|
||||||
|
emit hasPrevious();
|
||||||
|
|
||||||
while(mMedia->count() > 0){
|
while(mMedia->count() > 0){
|
||||||
mMedia->removeMedia(0);
|
mMedia->removeMedia(0);
|
||||||
}
|
}
|
||||||
|
|
@ -46,6 +51,7 @@ void MusicModel::navigateBack()
|
||||||
void MusicModel::playPause()
|
void MusicModel::playPause()
|
||||||
{
|
{
|
||||||
mIsPlaying = !mIsPlaying;
|
mIsPlaying = !mIsPlaying;
|
||||||
|
emit isPlayingChanged();
|
||||||
if(mIsPlaying)
|
if(mIsPlaying)
|
||||||
emit play();
|
emit play();
|
||||||
else
|
else
|
||||||
|
|
@ -56,6 +62,11 @@ void MusicModel::stopMusic()
|
||||||
{
|
{
|
||||||
if(mIsPlaying){
|
if(mIsPlaying){
|
||||||
mIsPlaying = false;
|
mIsPlaying = false;
|
||||||
|
mHasNext = false;
|
||||||
|
mHasPrevious = false;
|
||||||
|
emit hasNextChanged();
|
||||||
|
emit hasPreviousChanged();
|
||||||
|
emit isPlayingChanged();
|
||||||
emit stop();
|
emit stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -63,11 +74,19 @@ void MusicModel::stopMusic()
|
||||||
void MusicModel::playNext()
|
void MusicModel::playNext()
|
||||||
{
|
{
|
||||||
emit next();
|
emit next();
|
||||||
|
if(!mIsPlaying){
|
||||||
|
mIsPlaying = true;
|
||||||
|
emit isPlayingChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MusicModel::playPrevious()
|
void MusicModel::playPrevious()
|
||||||
{
|
{
|
||||||
emit previous();
|
emit previous();
|
||||||
|
if(!mIsPlaying){
|
||||||
|
mIsPlaying = true;
|
||||||
|
emit isPlayingChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NavigationItemModel *MusicModel::getCurrentItem()
|
NavigationItemModel *MusicModel::getCurrentItem()
|
||||||
|
|
@ -84,3 +103,27 @@ bool MusicModel::isPlaying()
|
||||||
{
|
{
|
||||||
return mIsPlaying;
|
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_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QObject* pCurrentItem READ getCurrentItem NOTIFY currentItemChanged)
|
Q_PROPERTY(QObject* pCurrentItem READ getCurrentItem NOTIFY currentItemChanged)
|
||||||
//Q_PROPERTY(QObject* pHasNext READ hasNext NOTIFY hasNextChanged)
|
Q_PROPERTY(bool pHasNext READ hasNext NOTIFY hasNextChanged)
|
||||||
//Q_PROPERTY(QObject* pHasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
|
Q_PROPERTY(bool pHasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
|
||||||
|
Q_PROPERTY(bool pIsPlaying READ isPlaying NOTIFY isPlayingChanged)
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void navigateTo(NavigationItemModel *item);
|
void navigateTo(NavigationItemModel *item);
|
||||||
|
|
@ -22,6 +23,9 @@ signals:
|
||||||
void stop();
|
void stop();
|
||||||
void previous();
|
void previous();
|
||||||
void next();
|
void next();
|
||||||
|
void hasPreviousChanged();
|
||||||
|
void hasNextChanged();
|
||||||
|
void isPlayingChanged();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MusicModel(VlcInstance* instance, QObject *parent = Q_NULLPTR);
|
MusicModel(VlcInstance* instance, QObject *parent = Q_NULLPTR);
|
||||||
|
|
@ -40,9 +44,16 @@ public:
|
||||||
VlcMediaList *getMedia();
|
VlcMediaList *getMedia();
|
||||||
|
|
||||||
bool isPlaying();
|
bool isPlaying();
|
||||||
|
bool hasNext();
|
||||||
|
bool hasPrevious();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onNextMediaSet(VlcMedia* media);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mIsPlaying = false;
|
bool mIsPlaying = false;
|
||||||
|
bool mHasNext = false;
|
||||||
|
bool mHasPrevious = false;
|
||||||
NavigationItemModel* mCurrentItem = Q_NULLPTR;
|
NavigationItemModel* mCurrentItem = Q_NULLPTR;
|
||||||
VlcMediaList* mMedia = Q_NULLPTR;
|
VlcMediaList* mMedia = Q_NULLPTR;
|
||||||
VlcInstance* mVlc;
|
VlcInstance* mVlc;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue