- 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
90 lines
2.9 KiB
C++
90 lines
2.9 KiB
C++
#include "StyleHandling.h"
|
|
#include <QGuiApplication>
|
|
#include <QScreen>
|
|
#include <QDebug>
|
|
|
|
StyleHandling::StyleHandling(QObject *parent)
|
|
: QObject{parent}, mStyleSizes(new QQmlPropertyMap(this)),
|
|
mMargins(new QQmlPropertyMap(this)), mSpacings(new QQmlPropertyMap(this)), mPaddings(new QQmlPropertyMap(this))
|
|
{
|
|
// nothing
|
|
}
|
|
|
|
void StyleHandling::calculateAndSetRatio()
|
|
{
|
|
qreal refHeight = 480;
|
|
qreal refWidth = 800;
|
|
// Scales to fullscreen. No rescaling when changing window size
|
|
QRect rect = QGuiApplication::primaryScreen()->geometry();
|
|
qreal height = qMin(rect.width(),rect.height());
|
|
qreal width = qMax(rect.width(), rect.height());
|
|
|
|
mRatio = qMin(height/refHeight, width/refWidth);
|
|
qDebug() << "mRation=" << mRatio<< "sizes="<<width<<", "<< height<<"\n";
|
|
}
|
|
|
|
void StyleHandling::initStyleSizes()
|
|
{
|
|
scaleAndInsert(mStyleSizes, "roundButtonDefaultSize", 65);
|
|
scaleAndInsert(mStyleSizes, "roundButtonBorderWidth", 2);
|
|
scaleAndInsert(mStyleSizes, "smallPlayerButtonSize", 60);
|
|
scaleAndInsert(mStyleSizes, "largePlayerButtonSize", 80);
|
|
|
|
scaleAndInsert(mStyleSizes, "scrollHandleWidth", 16);
|
|
scaleAndInsert(mStyleSizes, "scrollHandleHeight", 8);
|
|
scaleAndInsert(mStyleSizes, "scrollHandleBorderWidth", 1);
|
|
|
|
int progressBackgroundDefaultHeight = 10;
|
|
scaleAndInsert(mStyleSizes, "progressBackgroundDefaultHeight", progressBackgroundDefaultHeight);
|
|
scaleAndInsert(mStyleSizes, "progressBackgroundRadius", progressBackgroundDefaultHeight/2);
|
|
scaleAndInsert(mStyleSizes, "progressBarDefaultHeight", 8);
|
|
scaleAndInsert(mStyleSizes, "progressBackgroundBorderWidth", 1);
|
|
|
|
scaleAndInsert(mStyleSizes, "navigationListHeight", 210);
|
|
scaleAndInsert(mStyleSizes, "navigationDelegateDefaultSize", 150);
|
|
|
|
}
|
|
|
|
void StyleHandling::initSpacings()
|
|
{
|
|
scaleAndInsert(mSpacings, "defaultSpacing", 20);
|
|
scaleAndInsert(mSpacings, "smallSpacing", 10);
|
|
scaleAndInsert(mSpacings, "tinySpacing", 5);
|
|
}
|
|
|
|
void StyleHandling::initMargins()
|
|
{
|
|
scaleAndInsert(mMargins, "defaultMargin", 20);
|
|
scaleAndInsert(mMargins, "smallMargin", 10);
|
|
scaleAndInsert(mMargins, "tinyMargin", 5);
|
|
scaleAndInsert(mMargins, "scrollHandleMargins", 1);
|
|
}
|
|
|
|
void StyleHandling::initPaddings()
|
|
{
|
|
scaleAndInsert(mPaddings, "defaultPadding", 5);
|
|
}
|
|
|
|
void StyleHandling::scaleAndInsert(QQmlPropertyMap *map, const QString &key, int value)
|
|
{
|
|
map->insert(key, applyRatio(value));
|
|
}
|
|
|
|
int StyleHandling::applyRatio(int size) const
|
|
{
|
|
return size*mRatio;
|
|
}
|
|
|
|
void StyleHandling::init(QQmlContext *context)
|
|
{
|
|
calculateAndSetRatio();
|
|
initStyleSizes();
|
|
initMargins();
|
|
initSpacings();
|
|
initPaddings();
|
|
|
|
context->setContextProperty("StyleSizes", mStyleSizes);
|
|
context->setContextProperty("StyleSpacings", mSpacings);
|
|
context->setContextProperty("StyleMargins", mMargins);
|
|
context->setContextProperty("StylePaddings", mPaddings);
|
|
}
|