2018-03-28 15:10:51 +02:00
|
|
|
/*!
|
|
|
|
* \copyright Copyright (c) 2015-2018 Governikus GmbH & Co. KG, Germany
|
|
|
|
*/
|
|
|
|
|
2017-07-03 09:30:10 +02:00
|
|
|
#include "DpiCalculator.h"
|
|
|
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_LOGGING_CATEGORY(qml)
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
|
|
|
|
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
|
|
|
|
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
|
|
|
|
|
|
|
|
// screen height is orientation dependent
|
|
|
|
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
|
|
|
|
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
|
2017-12-20 14:54:05 +01:00
|
|
|
#define SCREEN_MAX_LENGTH (qMax(SCREEN_WIDTH, SCREEN_HEIGHT))
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
#define IS_IPHONE_4 (IS_IPHONE && SCREEN_MAX_LENGTH == 480.0 && IS_RETINA)
|
|
|
|
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
|
|
|
|
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
|
|
|
|
#define IS_IPHONE_6PLUS (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
|
|
|
|
|
|
|
|
|
|
|
|
qreal DpiCalculator::getDpi()
|
|
|
|
{
|
|
|
|
qreal dpi;
|
|
|
|
qreal renderFactor = [UIScreen mainScreen].scale;
|
|
|
|
|
|
|
|
if (IS_IPHONE_4 || IS_IPHONE_5 || IS_IPHONE_6)
|
|
|
|
{
|
|
|
|
dpi = 326.0;
|
|
|
|
}
|
|
|
|
else if (IS_IPHONE_6PLUS)
|
|
|
|
{
|
|
|
|
dpi = 401.0;
|
|
|
|
renderFactor /= 1.15; // the iPhone 6 plus is downsampled
|
|
|
|
}
|
|
|
|
else if (IS_IPAD)
|
|
|
|
{
|
|
|
|
dpi = 264.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCCritical(qml) << "Unknown iOS device, cannot determine dpi";
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For some reason on iOS the unit is interpreted per point, not per pixel.
|
|
|
|
* Therefore we adapt it to points per inch by dividing by the render factor.
|
|
|
|
* See: http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
|
|
|
|
*/
|
|
|
|
dpi /= renderFactor;
|
|
|
|
|
|
|
|
qCInfo(qml) << "Determined dpi" << dpi;
|
|
|
|
return dpi;
|
|
|
|
}
|