Make LenaPi usable on Android devices
- Add app icon - prevend android device from shutting down cpu while playing music - fix scaling bug - fix energy saver for RasPi by reconnecting to music player - minor refactorings and renaming
This commit is contained in:
parent
851b83a53a
commit
1f12d93300
19 changed files with 499 additions and 48 deletions
81
LenaPi/controllers/StyleHandling.h
Normal file
81
LenaPi/controllers/StyleHandling.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#ifndef STYLEHANDLING_H
|
||||
#define STYLEHANDLING_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlContext>
|
||||
#include <QQmlPropertyMap>
|
||||
|
||||
/**
|
||||
* @brief Contains all style sizes, margins and paddings used throughout the application
|
||||
*
|
||||
* Based on a reference screen size, maps for scaled margins, paddings and spacings are created and
|
||||
* registered in the QML context. The values stored in the maps can then be used from QML.
|
||||
* Map names: StyleSizes, StylePaddings, StyleSpacings, StyleMargins
|
||||
*
|
||||
* Always use values from these maps in QML! Never use magic numbers! They will NOT scale when
|
||||
* the application is run on a different screen.
|
||||
*
|
||||
* See https://doc.qt.io/qt-5/scalability.html
|
||||
*
|
||||
* @todo scale fonts as well?
|
||||
* @todo use dpi for scaling as app is very small on Android?
|
||||
*/
|
||||
class StyleHandling : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StyleHandling(QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Calculates ratio, initializes all maps and registers them in QML context
|
||||
* @param context Context to register Maps in
|
||||
*/
|
||||
void init(QQmlContext* context);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Calculates ratio from reference screen size and size of the current primary screen and inits member mRatio
|
||||
*/
|
||||
void calculateAndSetRatio();
|
||||
/**
|
||||
* @brief Initializes map containing all sizes (e.g., button or delegate sizes)
|
||||
*/
|
||||
void initStyleSizes();
|
||||
/**
|
||||
* @brief Initializes map containing all spacings
|
||||
*/
|
||||
void initSpacings();
|
||||
/**
|
||||
* @brief Initializes map containing all margins
|
||||
*/
|
||||
void initMargins();
|
||||
/**
|
||||
* @brief Initializes map containing all paddings
|
||||
*/
|
||||
void initPaddings();
|
||||
/**
|
||||
* @brief Scales the value with calculated ratio and inserts it into the given map under the given key
|
||||
* @param map Map to insert key-value pair into
|
||||
* @param key Key used in the map. This is the name used to retrieve the value in QML
|
||||
* @param value Unscaled value
|
||||
* @see mRatio
|
||||
*
|
||||
* In QML the value with the key "defaulSpacing" in the Map "StyleSpacings" is accessed by StyleSpacings.defaultSpacing
|
||||
*/
|
||||
void scaleAndInsert(QQmlPropertyMap* map, const QString& key, int value);
|
||||
/**
|
||||
* @brief Applys ratio to given size
|
||||
* @param size Size to be scaled
|
||||
* @return scaled size
|
||||
* @see mRatio
|
||||
*/
|
||||
int applyRatio(int size) const;
|
||||
|
||||
qreal mRatio = 1.0;
|
||||
QQmlPropertyMap* mStyleSizes = nullptr;
|
||||
QQmlPropertyMap* mMargins = nullptr;
|
||||
QQmlPropertyMap* mSpacings = nullptr;
|
||||
QQmlPropertyMap* mPaddings = nullptr;
|
||||
};
|
||||
|
||||
#endif // STYLEHANDLING_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue