Commit af6f5fdc authored by eekkelund's avatar eekkelund

[Scaling] Recalculate scaling ratio based on reference device, N9. Recalculate...

[Scaling] Recalculate scaling ratio based on reference device, N9. Recalculate font scaling ratio and adjust fontSizes according to that
parent 21e4efa0
......@@ -11,35 +11,34 @@ Sizing::Sizing(QObject *parent) : QObject(parent)
m_dp_factor = 1;
m_densitie = mdpi;
qreal refHeight = 854.; //N9
qreal refWidth = 480.; //N9
qreal refDpi = 251; //N9
m_p_height = qgetenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT").toInt();
m_p_width = qgetenv("QT_QPA_EGLFS_PHYSICAL_WIDTH").toInt();
QScreen *screen = QGuiApplication::primaryScreen();
m_height = screen->size().height();
m_width = screen->size().width();
m_dpi = screen->physicalDotsPerInch();
m_height = qMax(screen->size().width(), screen->size().height());
m_width = qMin(screen->size().width(), screen->size().height());
int largerSide;
m_dpi = screen->physicalDotsPerInch();
m_scaleRatio = qMin(m_height/refHeight, m_width/refWidth);
m_fontRatio = floor(m_scaleRatio*10) /10; //qMin(m_height*refDpi/(m_dpi*refHeight), m_width*refDpi/(m_dpi*refWidth))*10)/10;
qDebug() << "Height: " << m_height << "Width: " << m_width;
qDebug() << "Scale ratio: " << m_scaleRatio << " Font: " << m_fontRatio;
if(m_height > m_width) {
largerSide = m_width;
} else {
largerSide = m_height;
}
if(largerSide > 2160){
if(m_width >= 2160){
//>2160
m_launcher_icon_size = 256;
}else if (largerSide > 1080){
//1081-2160
}else if (m_width >= 1080){
//1080-2159
m_launcher_icon_size = 128;
}else if(largerSide > 720){
//721-1080
}else if(m_width >= 720){
//720-1079
m_launcher_icon_size = 108;
}else {
//>720
......@@ -130,6 +129,11 @@ float Sizing::dp(float value)
return value*m_dp_factor;
}
float Sizing::ratio(float value)
{
return floor(value*m_scaleRatio);
}
void Sizing::setMmScaleFactor(float value)
{
......@@ -152,3 +156,15 @@ void Sizing::setDpScaleFactor(float value)
m_dp_factor = value;
}
}
void Sizing::setScaleRatio(qreal scaleRatio)
{
if(scaleRatio != 0)
m_scaleRatio = scaleRatio;
}
void Sizing::setFontRatio(qreal fontRatio)
{
if(fontRatio !=0 )
m_fontRatio = fontRatio;
}
......@@ -31,6 +31,9 @@ public:
float getMmScaleFactor(){return m_mm_factor;}
float getDpScaleFactor(){return m_dp_factor;}
qreal getScaleRatio(){return m_scaleRatio;}
qreal getFontRatio(){return m_fontRatio;}
int getLauncherIconSize(){return m_launcher_icon_size;}
......@@ -38,10 +41,15 @@ public:
Q_INVOKABLE float mm(float value);
Q_INVOKABLE float dp(float value);
Q_INVOKABLE float ratio(float value);
Q_INVOKABLE void setMmScaleFactor(float value);
Q_INVOKABLE void setDpScaleFactor(float value);
Q_INVOKABLE void setScaleRatio(qreal scaleRatio);
void setFontRatio(qreal fontRatio);
private:
bool m_valid;
......@@ -50,6 +58,8 @@ private:
int m_width;
int m_height;
qreal m_scaleRatio;
qreal m_fontRatio;
int m_launcher_icon_size;
......
......@@ -11,30 +11,33 @@ Theme::Theme(QObject *parent) : QObject(parent)
Sizing *size = new Sizing;
m_dp = size->getDpScaleFactor();
m_iconSizeLauncher = size->getLauncherIconSize();
m_scaleRatio = size->getScaleRatio();
m_fontRatio = size->getFontRatio();
//Load defaults
m_itemWidthLarge = 320*m_dp;
m_itemWidthMedium = 240*m_dp;
m_itemWidthSmall = 120*m_dp;
m_itemWidthExtraSmall = 72*m_dp;
m_itemWidthLarge = floor(320*m_scaleRatio);
m_itemWidthMedium = floor(240*m_scaleRatio);
m_itemWidthSmall = floor(120*m_scaleRatio);
m_itemWidthExtraSmall = floor(72*m_scaleRatio);
m_itemHeightHuge = 80*m_dp;
m_itemHeightExtraLarge = 75*m_dp;
m_itemHeightLarge = 63*m_dp;
m_itemHeightMedium = 50*m_dp;
m_itemHeightSmall = 40*m_dp;
m_itemHeightExtraSmall = 32*m_dp;
m_itemHeightHuge = floor(80*m_scaleRatio);
m_itemHeightExtraLarge = floor(75*m_scaleRatio);
m_itemHeightLarge = floor(63*m_scaleRatio);
m_itemHeightMedium = floor(50*m_scaleRatio);
m_itemHeightSmall = floor(40*m_scaleRatio);
m_itemHeightExtraSmall = floor(32*m_scaleRatio);
m_itemSpacingHuge = 40*m_dp;
m_itemSpacingLarge = 20*m_dp;
m_itemSpacingMedium = 15*m_dp;
m_itemSpacingSmall = 10*m_dp;
m_itemSpacingExtraSmall = 8*m_dp;
m_itemSpacingHuge = floor(40*m_scaleRatio);
m_itemSpacingLarge = floor(20*m_scaleRatio);
m_itemSpacingMedium = floor(15*m_scaleRatio);
m_itemSpacingSmall = floor(10*m_scaleRatio);
m_itemSpacingExtraSmall = floor(8*m_scaleRatio);
m_fontSizeExtraLarge = 50*m_dp;
m_fontSizeLarge = 40*m_dp;
m_fontSizeMedium = 32*m_dp;
m_fontSizeSmall = 26*m_dp;
m_fontSizeTiny = 18*m_dp;
m_fontSizeExtraLarge = floor(44*m_fontRatio);
m_fontSizeLarge = floor(35*m_fontRatio);
m_fontSizeMedium = floor(28*m_fontRatio);
m_fontSizeSmall = floor(24*m_fontRatio);
m_fontSizeTiny = floor(16*m_fontRatio);
m_fontWeightLarge = 63*m_dp;
m_fontWeightMedium = 25*m_dp;
m_fontFamily = "/usr/share/fonts/google-opensans/OpenSans-Regular.ttf";
......@@ -77,146 +80,146 @@ bool Theme::loadTheme(QString fileName)
}
if(theme.value("itemWidthLarge").toString().toFloat() != 0 &&
theme.value("itemWidthLarge").toString().toFloat() != m_itemWidthLarge)
floor(theme.value("itemWidthLarge").toString().toFloat()) != m_itemWidthLarge)
{
m_itemWidthLarge = theme.value("itemWidthLarge").toString().toFloat()*m_dp;
m_itemWidthLarge = floor(theme.value("itemWidthLarge").toString().toFloat()*m_scaleRatio);
emit itemWidthLargeChanged();
updated = true;
}
if(theme.value("itemWidthMedium").toString().toFloat() != 0 &&
theme.value("itemWidthMedium").toString().toFloat() != m_itemWidthMedium)
floor(theme.value("itemWidthMedium").toString().toFloat()) != m_itemWidthMedium)
{
m_itemWidthMedium = theme.value("itemWidthMedium").toString().toFloat()*m_dp;
m_itemWidthMedium = floor(theme.value("itemWidthMedium").toString().toFloat()*m_scaleRatio);
emit itemWidthMediumChanged();
updated = true;
}
if(theme.value("itemWidthSmall").toString().toFloat() != 0 &&
theme.value("itemWidthSmall").toString().toFloat() != m_itemWidthSmall)
floor(theme.value("itemWidthSmall").toString().toFloat()) != m_itemWidthSmall)
{
m_itemWidthSmall = theme.value("itemWidthSmall").toString().toFloat()*m_dp;
m_itemWidthSmall = floor(theme.value("itemWidthSmall").toString().toFloat()*m_scaleRatio);
emit itemWidthSmallChanged();
updated = true;
}
if(theme.value("itemWidthExtraSmall").toString().toFloat() != 0 &&
theme.value("itemWidthExtraSmall").toString().toFloat() != m_itemWidthExtraSmall)
floor(theme.value("itemWidthExtraSmall").toString().toFloat()) != m_itemWidthExtraSmall)
{
m_itemWidthExtraSmall = theme.value("itemWidthExtraSmall").toString().toFloat()*m_dp;
m_itemWidthExtraSmall = floor(theme.value("itemWidthExtraSmall").toString().toFloat()*m_scaleRatio);
emit itemWidthExtraSmallChanged();
updated = true;
}
if(theme.value("itemHeightHuge").toString().toFloat() != 0 &&
theme.value("itemHeightHuge").toString().toFloat() != m_itemHeightHuge)
floor(theme.value("itemHeightHuge").toString().toFloat()) != m_itemHeightHuge)
{
m_itemHeightHuge = theme.value("itemHeightHuge").toString().toFloat()*m_dp;
m_itemHeightHuge = floor(theme.value("itemHeightHuge").toString().toFloat()*m_scaleRatio);
emit itemHeightHugeChanged();
updated = true;
}
if(theme.value("itemHeightExtraLarge").toString().toFloat() != 0 &&
theme.value("itemHeightExtraLarge").toString().toFloat() != m_itemHeightExtraLarge)
floor(theme.value("itemHeightExtraLarge").toString().toFloat()) != m_itemHeightExtraLarge)
{
m_itemHeightExtraLarge = theme.value("itemHeightExtraLarge").toString().toFloat()*m_dp;
m_itemHeightExtraLarge = floor(theme.value("itemHeightExtraLarge").toString().toFloat()*m_scaleRatio);
emit itemHeightExtraLargeChanged();
updated = true;
}
if(theme.value("itemHeightLarge").toString().toFloat() != 0 &&
theme.value("itemHeightLarge").toString().toFloat() != m_itemHeightLarge)
floor(theme.value("itemHeightLarge").toString().toFloat()) != m_itemHeightLarge)
{
m_itemHeightLarge = theme.value("itemHeightLarge").toString().toFloat()*m_dp;
m_itemHeightLarge = floor(theme.value("itemHeightLarge").toString().toFloat()*m_scaleRatio);
emit itemHeightLargeChanged();
updated = true;
}
if(theme.value("itemHeightMedium").toString().toFloat() != 0 &&
theme.value("itemHeightMedium").toString().toFloat() != m_itemHeightMedium)
floor(theme.value("itemHeightMedium").toString().toFloat()) != m_itemHeightMedium)
{
m_itemHeightMedium = theme.value("itemHeightMedium").toString().toFloat()*m_dp;
m_itemHeightMedium = floor(theme.value("itemHeightMedium").toString().toFloat()*m_scaleRatio);
emit itemHeightMediumChanged();
updated = true;
}
if(theme.value("itemHeightSmall").toString().toFloat() != 0 &&
theme.value("itemHeightSmall").toString().toFloat() != m_itemHeightSmall)
floor(theme.value("itemHeightSmall").toString().toFloat()) != m_itemHeightSmall)
{
m_itemHeightSmall = theme.value("itemHeightSmall").toString().toFloat()*m_dp;
m_itemHeightSmall = floor(theme.value("itemHeightSmall").toString().toFloat()*m_scaleRatio);
emit itemHeightSmallChanged();
updated = true;
}
if(theme.value("itemHeightExtraSmall").toString().toFloat() != 0 &&
theme.value("itemHeightExtraSmall").toString().toFloat() != m_itemHeightExtraSmall)
floor(theme.value("itemHeightExtraSmall").toString().toFloat()) != m_itemHeightExtraSmall)
{
m_itemHeightExtraSmall = theme.value("itemHeightExtraSmall").toString().toFloat()*m_dp;
m_itemHeightExtraSmall = floor(theme.value("itemHeightExtraSmall").toString().toFloat()*m_scaleRatio);
emit itemHeightExtraSmallChanged();
updated = true;
}
if(theme.value("itemSpacingHuge").toString().toFloat() != 0 &&
theme.value("itemSpacingHuge").toString().toFloat() != m_itemSpacingHuge)
floor(theme.value("itemSpacingHuge").toString().toFloat()) != m_itemSpacingHuge)
{
m_itemSpacingHuge = theme.value("itemSpacingHuge").toString().toFloat()*m_dp;
m_itemSpacingHuge = floor(theme.value("itemSpacingHuge").toString().toFloat()*m_scaleRatio);
emit itemSpacingHugeChanged();
updated = true;
}
if(theme.value("itemSpacingLarge").toString().toFloat() != 0 &&
theme.value("itemSpacingLarge").toString().toFloat() != m_itemSpacingLarge)
floor(theme.value("itemSpacingLarge").toString().toFloat()) != m_itemSpacingLarge)
{
m_itemSpacingLarge = theme.value("itemSpacingLarge").toString().toFloat()*m_dp;
m_itemSpacingLarge = floor(theme.value("itemSpacingLarge").toString().toFloat()*m_scaleRatio);
emit itemSpacingLargeChanged();
updated = true;
}
if(theme.value("itemSpacingMedium").toString().toFloat() != 0 &&
theme.value("itemSpacingMedium").toString().toFloat() != m_itemSpacingMedium)
floor(theme.value("itemSpacingMedium").toString().toFloat()) != m_itemSpacingMedium)
{
m_itemSpacingMedium = theme.value("itemSpacingMedium").toString().toFloat()*m_dp;
m_itemSpacingMedium = floor(theme.value("itemSpacingMedium").toString().toFloat()*m_scaleRatio);
emit itemSpacingMediumChanged();
updated = true;
}
if(theme.value("itemSpacingSmall").toString().toFloat() != 0 &&
theme.value("itemSpacingSmall").toString().toFloat() != m_itemSpacingSmall)
floor(theme.value("itemSpacingSmall").toString().toFloat()) != m_itemSpacingSmall)
{
m_itemSpacingSmall = theme.value("itemSpacingSmall").toString().toFloat()*m_dp;
m_itemSpacingSmall = floor(theme.value("itemSpacingSmall").toString().toFloat()*m_scaleRatio);
emit itemSpacingSmallChanged();
updated = true;
}
if(theme.value("itemSpacingExtraSmall").toString().toFloat() != 0 &&
theme.value("itemSpacingExtraSmall").toString().toFloat() != m_itemSpacingExtraSmall)
floor(theme.value("itemSpacingExtraSmall").toString().toFloat()) != m_itemSpacingExtraSmall)
{
m_itemSpacingExtraSmall = theme.value("itemSpacingExtraSmall").toString().toFloat()*m_dp;
m_itemSpacingExtraSmall = floor(theme.value("itemSpacingExtraSmall").toString().toFloat()*m_scaleRatio);
emit itemSpacingExtraSmallChanged();
updated = true;
}
if(theme.value("fontSizeExtraLarge").toInt() != 0 &&
theme.value("fontSizeExtraLarge").toInt() != m_fontSizeExtraLarge)
floor(theme.value("fontSizeExtraLarge").toInt()) != m_fontSizeExtraLarge)
{
m_fontSizeExtraLarge = theme.value("itemSpacingExtraSmall").toInt()*m_dp;
m_fontSizeExtraLarge = floor(theme.value("fontSizeExtraLarge").toInt()*m_fontRatio);
emit fontSizeExtraLargeChanged();
updated = true;
}
if(theme.value("fontSizeLarge").toInt() != 0 &&
theme.value("fontSizeLarge").toInt() != m_fontSizeLarge)
floor(theme.value("fontSizeLarge").toInt()) != m_fontSizeLarge)
{
m_fontSizeLarge = theme.value("fontSizeLarge").toInt()*m_dp;
m_fontSizeLarge = floor(theme.value("fontSizeLarge").toInt()*m_fontRatio);
emit fontSizeLargeChanged();
updated = true;
}
if(theme.value("fontSizeMedium").toInt() != 0 &&
theme.value("fontSizeMedium").toInt() != m_fontSizeMedium)
floor(theme.value("fontSizeMedium").toInt()) != m_fontSizeMedium)
{
m_fontSizeMedium = theme.value("fontSizeMedium").toInt()*m_dp;
m_fontSizeMedium = floor(theme.value("fontSizeMedium").toInt()*m_fontRatio);
emit fontSizeMediumChanged();
updated = true;
}
if(theme.value("fontSizeSmall").toInt() != 0 &&
theme.value("fontSizeSmall").toInt() != m_fontSizeSmall)
floor(theme.value("fontSizeSmall").toInt()) != m_fontSizeSmall)
{
m_fontSizeSmall = theme.value("fontSizeSmall").toInt()*m_dp;
m_fontSizeSmall = floor(theme.value("fontSizeSmall").toInt()*m_fontRatio);
emit fontSizeSmallChanged();
updated = true;
}
if(theme.value("fontSizeTiny").toInt() != 0 &&
theme.value("fontSizeTiny").toInt() != m_fontSizeTiny)
floor(theme.value("fontSizeTiny").toInt()) != m_fontSizeTiny)
{
m_fontSizeTiny = theme.value("fontSizeTiny").toInt()*m_dp;
m_fontSizeTiny = floor(theme.value("fontSizeTiny").toInt()*m_fontRatio);
emit fontSizeTinyChanged();
updated = true;
}
......
......@@ -147,11 +147,11 @@ private:
qreal m_itemSpacingSmall; //10
qreal m_itemSpacingExtraSmall; //8
int m_fontSizeExtraLarge; //50
int m_fontSizeLarge; //40
int m_fontSizeMedium; //32
int m_fontSizeSmall; //26
int m_fontSizeTiny; //18
int m_fontSizeExtraLarge; //44
int m_fontSizeLarge; //35
int m_fontSizeMedium; //28
int m_fontSizeSmall; //24
int m_fontSizeTiny; //16
int m_fontWeightLarge; //63
int m_fontWeightMedium; //25
QString m_fontFamily; //???
......@@ -164,6 +164,8 @@ private:
QString m_backgroundAccentColor; //#ffffff
qreal m_dp;
qreal m_scaleRatio;
qreal m_fontRatio;
};
#endif // THEME_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment