finished navigation including music player and navigate back
functionality
This commit is contained in:
parent
d6cb29ae7b
commit
6f5c9138a8
12 changed files with 213 additions and 11 deletions
|
|
@ -6,7 +6,10 @@ CONFIG += c++11
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
models/NavigationListModel.cpp \
|
models/NavigationListModel.cpp \
|
||||||
models/NavigationItemModel.cpp \
|
models/NavigationItemModel.cpp \
|
||||||
controllers/NavigationController.cpp
|
controllers/NavigationController.cpp \
|
||||||
|
models/UiStateModel.cpp \
|
||||||
|
controllers/MusicController.cpp \
|
||||||
|
models/MusicModel.cpp
|
||||||
|
|
||||||
RESOURCES += qml.qrc \
|
RESOURCES += qml.qrc \
|
||||||
lenapi.qrc
|
lenapi.qrc
|
||||||
|
|
@ -36,4 +39,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
models/NavigationListModel.h \
|
models/NavigationListModel.h \
|
||||||
models/NavigationItemModel.h \
|
models/NavigationItemModel.h \
|
||||||
controllers/NavigationController.h
|
controllers/NavigationController.h \
|
||||||
|
models/UiStateModel.h \
|
||||||
|
controllers/MusicController.h \
|
||||||
|
models/MusicModel.h
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ Item{
|
||||||
id: backgroundImage
|
id: backgroundImage
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
source: "file:///home/ar/source/testLenaPi/benjamin/image.jpg"
|
source: musicModel.pCurrentItem.pImageSource
|
||||||
fillMode: Image.PreserveAspectCrop
|
fillMode: Image.PreserveAspectCrop
|
||||||
verticalAlignment: Image.AlignTop
|
verticalAlignment: Image.AlignTop
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,9 @@ Item{
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.margins: 20
|
anchors.margins: 20
|
||||||
|
onClicked: {
|
||||||
|
musicModel.navigateBack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
@ -34,6 +37,7 @@ Item{
|
||||||
imageSource: "qrc:/icon_play"
|
imageSource: "qrc:/icon_play"
|
||||||
|
|
||||||
onClicked:{
|
onClicked:{
|
||||||
|
musicModel.playPause();
|
||||||
if(imageSource == "qrc:/icon_play")
|
if(imageSource == "qrc:/icon_play")
|
||||||
imageSource = "qrc:/icon_pause"
|
imageSource = "qrc:/icon_pause"
|
||||||
else
|
else
|
||||||
|
|
|
||||||
26
LenaPi/controllers/MusicController.cpp
Normal file
26
LenaPi/controllers/MusicController.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
#include "MusicController.h"
|
||||||
|
|
||||||
|
#include <models/MusicModel.h>
|
||||||
|
|
||||||
|
MusicController::MusicController(QObject *parent) : QObject(parent),
|
||||||
|
mModel(new MusicModel(this))
|
||||||
|
{
|
||||||
|
connect(mModel, &MusicModel::navigateTo, this, &MusicController::navigateTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicController::initPlayer(NavigationItemModel *item)
|
||||||
|
{
|
||||||
|
mModel->init(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicController::setContext(QQmlContext *context)
|
||||||
|
{
|
||||||
|
mContext = context;
|
||||||
|
setContextProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicController::setContextProperties()
|
||||||
|
{
|
||||||
|
if(!mContext) return;
|
||||||
|
mContext->setContextProperty("musicModel", mModel);
|
||||||
|
}
|
||||||
32
LenaPi/controllers/MusicController.h
Normal file
32
LenaPi/controllers/MusicController.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef MUSICCONTROLLER_H
|
||||||
|
#define MUSICCONTROLLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QQmlContext>
|
||||||
|
#include <models/NavigationItemModel.h>
|
||||||
|
|
||||||
|
class MusicModel;
|
||||||
|
|
||||||
|
class MusicController : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void navigateTo(NavigationItemModel* item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
MusicController(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
void initPlayer(NavigationItemModel* item);
|
||||||
|
|
||||||
|
void setContext(QQmlContext* context);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setContextProperties();
|
||||||
|
|
||||||
|
QQmlContext* mContext;
|
||||||
|
|
||||||
|
MusicModel* mModel;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MUSICCONTROLLER_H
|
||||||
|
|
@ -3,15 +3,21 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "../models/NavigationItemModel.h"
|
#include <models/NavigationItemModel.h>
|
||||||
#include "../models/NavigationListModel.h"
|
#include <models/NavigationListModel.h>
|
||||||
|
#include <models/UiStateModel.h>
|
||||||
|
#include <controllers/MusicController.h>
|
||||||
|
|
||||||
///@todo impelement reaction to item's clicked signal; implement back navigation
|
|
||||||
NavigationController::NavigationController(QObject *parent) : QObject(parent),
|
NavigationController::NavigationController(QObject *parent) : QObject(parent),
|
||||||
mRootItem(new NavigationItemModel(this)),
|
mRootItem(new NavigationItemModel(this)),
|
||||||
mNavList(new NavigationListModel(this))
|
mNavList(new NavigationListModel(this)),
|
||||||
|
mUiState(new UiStateModel(this)),
|
||||||
|
mMusicController(new MusicController(this))
|
||||||
{
|
{
|
||||||
|
connect(mMusicController, &MusicController::navigateTo, [this](NavigationItemModel* item) {
|
||||||
|
mUiState->showNavigation();
|
||||||
|
mNavList->navigateTo(item);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationController::init(const QString &rootPath)
|
void NavigationController::init(const QString &rootPath)
|
||||||
|
|
@ -29,11 +35,14 @@ void NavigationController::setContext(QQmlContext *context)
|
||||||
{
|
{
|
||||||
mContext = context;
|
mContext = context;
|
||||||
setContextProperties();
|
setContextProperties();
|
||||||
|
mMusicController->setContext(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationController::setContextProperties()
|
void NavigationController::setContextProperties()
|
||||||
{
|
{
|
||||||
|
if(!mContext) return;
|
||||||
mContext->setContextProperty("navigationList", mNavList);
|
mContext->setContextProperty("navigationList", mNavList);
|
||||||
|
mContext->setContextProperty("uiStateModel", mUiState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationController::add(const QString &path, NavigationItemModel *parentItem)
|
void NavigationController::add(const QString &path, NavigationItemModel *parentItem)
|
||||||
|
|
@ -63,5 +72,8 @@ void NavigationController::onNavigationRequest()
|
||||||
|
|
||||||
if(item->hasChildren())
|
if(item->hasChildren())
|
||||||
mNavList->setModelItems(item->getChildren());
|
mNavList->setModelItems(item->getChildren());
|
||||||
///@todo else {mMusicController->initPlayer(item); mUiStateModel->showMusicPlayer();}
|
else {
|
||||||
|
mMusicController->initPlayer(item);
|
||||||
|
mUiState->showMusicPlayer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
class NavigationItemModel;
|
class NavigationItemModel;
|
||||||
class NavigationListModel;
|
class NavigationListModel;
|
||||||
|
class UiStateModel;
|
||||||
|
class MusicController;
|
||||||
|
|
||||||
class NavigationController : public QObject
|
class NavigationController : public QObject
|
||||||
{
|
{
|
||||||
|
|
@ -23,6 +25,10 @@ private:
|
||||||
|
|
||||||
NavigationItemModel* mRootItem;
|
NavigationItemModel* mRootItem;
|
||||||
NavigationListModel* mNavList;
|
NavigationListModel* mNavList;
|
||||||
|
|
||||||
|
UiStateModel* mUiState;
|
||||||
|
MusicController* mMusicController;
|
||||||
|
|
||||||
QString mRootPath = ".";
|
QString mRootPath = ".";
|
||||||
|
|
||||||
QQmlContext* mContext = Q_NULLPTR;
|
QQmlContext* mContext = Q_NULLPTR;
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,7 @@ Window {
|
||||||
|
|
||||||
Loader{
|
Loader{
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
//source: "MusicPlayer.qml"
|
source: uiStateModel.pSource
|
||||||
source: "Navigation.qml"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
LenaPi/models/MusicModel.cpp
Normal file
32
LenaPi/models/MusicModel.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#include "MusicModel.h"
|
||||||
|
|
||||||
|
MusicModel::MusicModel(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicModel::init(NavigationItemModel *item)
|
||||||
|
{
|
||||||
|
mCurrentItem = item;
|
||||||
|
emit currentItemChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicModel::navigateBack()
|
||||||
|
{
|
||||||
|
emit navigateTo(mCurrentItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicModel::playPause()
|
||||||
|
{
|
||||||
|
mIsPlaying = !mIsPlaying;
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigationItemModel *MusicModel::getCurrentItem()
|
||||||
|
{
|
||||||
|
return mCurrentItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MusicModel::isPlaying()
|
||||||
|
{
|
||||||
|
return mIsPlaying;
|
||||||
|
}
|
||||||
35
LenaPi/models/MusicModel.h
Normal file
35
LenaPi/models/MusicModel.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef MUSICMODEL_H
|
||||||
|
#define MUSICMODEL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <models/NavigationItemModel.h>
|
||||||
|
|
||||||
|
class MusicModel : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QObject* pCurrentItem READ getCurrentItem NOTIFY currentItemChanged)
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void navigateTo(NavigationItemModel *item);
|
||||||
|
void currentItemChanged();
|
||||||
|
|
||||||
|
public:
|
||||||
|
MusicModel(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
void init(NavigationItemModel* item);
|
||||||
|
|
||||||
|
Q_INVOKABLE void navigateBack();
|
||||||
|
Q_INVOKABLE void playPause();
|
||||||
|
|
||||||
|
NavigationItemModel *getCurrentItem();
|
||||||
|
|
||||||
|
bool isPlaying();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool mIsPlaying = false;
|
||||||
|
NavigationItemModel* mCurrentItem = Q_NULLPTR;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MUSICMODEL_H
|
||||||
|
|
@ -7,6 +7,7 @@ NavigationItemModel::NavigationItemModel(QObject *parent) : QObject(parent),
|
||||||
mImageSource("qrc:/default_image"),
|
mImageSource("qrc:/default_image"),
|
||||||
mParentItem(qobject_cast<NavigationItemModel*>(parent))
|
mParentItem(qobject_cast<NavigationItemModel*>(parent))
|
||||||
{
|
{
|
||||||
|
qRegisterMetaType<NavigationItemModel*>("NavigationItemModel*");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NavigationItemModel::getImageSource() const
|
QString NavigationItemModel::getImageSource() const
|
||||||
|
|
|
||||||
21
LenaPi/models/UiStateModel.cpp
Normal file
21
LenaPi/models/UiStateModel.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include "UiStateModel.h"
|
||||||
|
|
||||||
|
UiStateModel::UiStateModel(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
showNavigation();
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl UiStateModel::getSource() const
|
||||||
|
{
|
||||||
|
return mSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UiStateModel::showMusicPlayer(){
|
||||||
|
mSource = QUrl("MusicPlayer.qml");
|
||||||
|
emit sourceChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UiStateModel::showNavigation(){
|
||||||
|
mSource = QUrl("Navigation.qml");
|
||||||
|
emit sourceChanged();
|
||||||
|
}
|
||||||
28
LenaPi/models/UiStateModel.h
Normal file
28
LenaPi/models/UiStateModel.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef UISTATEMODEL_H
|
||||||
|
#define UISTATEMODEL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
class UiStateModel : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QUrl pSource READ getSource NOTIFY sourceChanged)
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sourceChanged();
|
||||||
|
|
||||||
|
public:
|
||||||
|
UiStateModel(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
QUrl getSource() const;
|
||||||
|
|
||||||
|
void showMusicPlayer();
|
||||||
|
void showNavigation();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUrl mSource;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UISTATEMODEL_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue