added config
This commit is contained in:
parent
893a2990af
commit
f02f439790
7 changed files with 168 additions and 17 deletions
|
|
@ -1,10 +1,30 @@
|
|||
#include "UiStateModel.h"
|
||||
#include <iostream>
|
||||
|
||||
UiStateModel::UiStateModel(QObject *parent) : QObject(parent)
|
||||
{
|
||||
initProfiles();
|
||||
showNavigation();
|
||||
}
|
||||
|
||||
void UiStateModel::setProfile(UiStateModel::EProfile profile)
|
||||
{
|
||||
mProfile = profile;
|
||||
emit profileChanged();
|
||||
}
|
||||
|
||||
bool UiStateModel::isShowQuitAppButton() const
|
||||
{
|
||||
const auto & profileInfo = mProfileInfoMap[mProfile];
|
||||
return profileInfo.isShowQuitAppButton;
|
||||
}
|
||||
|
||||
bool UiStateModel::isShowVolumeControls() const
|
||||
{
|
||||
const auto & profileInfo = mProfileInfoMap[mProfile];
|
||||
return profileInfo.isShowVolumeControls;
|
||||
}
|
||||
|
||||
QUrl UiStateModel::getSource() const
|
||||
{
|
||||
return mSource;
|
||||
|
|
@ -19,3 +39,32 @@ void UiStateModel::showNavigation(){
|
|||
mSource = QUrl("Navigation.qml");
|
||||
emit sourceChanged();
|
||||
}
|
||||
|
||||
void UiStateModel::initProfiles()
|
||||
{
|
||||
// Profile_RasPiTouch
|
||||
ProfileInfo rasPiTouchProfile;
|
||||
rasPiTouchProfile.profileType = Profile_RasPiTouch;
|
||||
rasPiTouchProfile.isShowQuitAppButton = false;
|
||||
rasPiTouchProfile.isShowVolumeControls = false;
|
||||
|
||||
mProfileInfoMap.insert(rasPiTouchProfile.profileType, rasPiTouchProfile);
|
||||
|
||||
// Profile_Desktop
|
||||
ProfileInfo desktopProfile;
|
||||
desktopProfile.profileType = Profile_Desktop;
|
||||
desktopProfile.isShowQuitAppButton = true;
|
||||
desktopProfile.isShowVolumeControls = true;
|
||||
|
||||
mProfileInfoMap.insert(desktopProfile.profileType, desktopProfile);
|
||||
}
|
||||
|
||||
UiStateModel::EProfile UiStateModel::getProfileFromString(const QString &profileString)
|
||||
{
|
||||
if(profileString == "Desktop"){
|
||||
return Profile_Desktop;
|
||||
} else if(profileString != "RasPiTouch"){
|
||||
std::cout << "WARNING: Unknown profile\t" << profileString.toStdString() << std::endl;
|
||||
}
|
||||
return Profile_RasPiTouch;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QHash>
|
||||
|
||||
/**
|
||||
* @brief Handles state of UI by providing the qml source.
|
||||
|
|
@ -15,9 +16,12 @@ class UiStateModel : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QUrl pSource READ getSource NOTIFY sourceChanged)
|
||||
Q_PROPERTY(bool pShowQuitAppButton READ isShowQuitAppButton NOTIFY profileChanged)
|
||||
Q_PROPERTY(bool pShowVolumeControls READ isShowVolumeControls NOTIFY profileChanged)
|
||||
|
||||
signals:
|
||||
void sourceChanged();
|
||||
void profileChanged();
|
||||
|
||||
public:
|
||||
/**
|
||||
|
|
@ -37,15 +41,51 @@ public:
|
|||
*/
|
||||
Profile_Desktop
|
||||
};
|
||||
|
||||
explicit UiStateModel(QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* @brief setProfile
|
||||
* @param profileString String identifying profile as read from config.
|
||||
*
|
||||
* Known profile strings are "RasPiTouch" and "Desktop".
|
||||
*/
|
||||
void setProfile(const QString& profileString){ setProfile(getProfileFromString(profileString)); }
|
||||
void setProfile(EProfile profile);
|
||||
|
||||
bool isShowQuitAppButton() const;
|
||||
bool isShowVolumeControls() const;
|
||||
|
||||
QUrl getSource() const;
|
||||
|
||||
void showMusicPlayer();
|
||||
void showNavigation();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Container defining ui state inforamtion for a certain profile
|
||||
*/
|
||||
struct ProfileInfo{
|
||||
EProfile profileType = Profile_RasPiTouch;
|
||||
bool isShowQuitAppButton = false;
|
||||
bool isShowVolumeControls = false;
|
||||
};
|
||||
/**
|
||||
* @brief Map containing ProfileInfo for each profile
|
||||
*/
|
||||
QHash<EProfile, ProfileInfo> mProfileInfoMap;
|
||||
/**
|
||||
* @brief Init ProfileInfo for all known profiles and init mProfileInfoMap
|
||||
*/
|
||||
void initProfiles();
|
||||
/**
|
||||
* @brief Transform given profile string to enum valie
|
||||
* @param profileString String identifying profile
|
||||
* @return Matching profile. If given string does not match a known profile, Profile_RasPiTouch is used as default.
|
||||
*/
|
||||
static EProfile getProfileFromString(const QString& profileString);
|
||||
QUrl mSource;
|
||||
EProfile mProfile = Profile_RasPiTouch;
|
||||
};
|
||||
|
||||
#endif // UISTATEMODEL_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue