Make setDevicePixelRatio(qreal) a simple slot

This commit is contained in:
Sebastian Kügler 2014-01-28 13:49:23 +01:00
parent 831357d98f
commit 6dfb4f240b
2 changed files with 14 additions and 29 deletions

View File

@ -36,7 +36,7 @@ Units::Units (QObject *parent)
m_devicePixelRatio(-1) m_devicePixelRatio(-1)
{ {
m_iconSizes = new QQmlPropertyMap(this); m_iconSizes = new QQmlPropertyMap(this);
setDevicePixelRatio(0); updateDevicePixelRatio();
updateSpacing(); updateSpacing();
//iconLoaderSettingsChanged(); //iconLoaderSettingsChanged();
@ -113,26 +113,19 @@ qreal Units::devicePixelRatio() const
return m_devicePixelRatio; return m_devicePixelRatio;
} }
void Units::setDevicePixelRatio(const qreal scale) void Units::updateDevicePixelRatio()
{ {
if (m_devicePixelRatio != scale) { // Going through QDesktopWidget seems to be the most reliable way no
if (scale <= 0) { // to get the DPI, and thus devicePixelRatio
// Going through QDesktopWidget seems to be the most reliable way no // Using QGuiApplication::devicePixelRatio() gives too coarse values,
// to get the DPI, and thus devicePixelRatio // i.e. it directly jumps from 1.0 to 2.0. We want tighter control on
// Using QGuiApplication::devicePixelRatio() gives too coarse values, // sizing, so we compute the exact ratio and use that.
// i.e. it directly jumps from 1.0 to 2.0. We want tighter control on qreal dpi = QApplication::desktop()->physicalDpiX();
// sizing, so we compute the exact ratio and use that. // Usual "default" is 96 dpi
qreal dpi = QApplication::desktop()->physicalDpiX(); // that magic ratio follows the definition of "device independent pixel" by Microsoft
// Usual "default" is 96 dpi m_devicePixelRatio = (qreal)dpi / (qreal)96;
// that magic ratio follows the definition of "device independent pixel" by Microsoft iconLoaderSettingsChanged();
m_devicePixelRatio = (qreal)dpi / (qreal)96; emit devicePixelRatioChanged();
} else {
m_devicePixelRatio = scale;
}
qDebug() << "XX Setting dpi scale to " << scale;
iconLoaderSettingsChanged();
emit devicePixelRatioChanged();
}
} }
int Units::gridUnit() const int Units::gridUnit() const

View File

@ -127,15 +127,7 @@ private Q_SLOTS:
void iconLoaderSettingsChanged(); void iconLoaderSettingsChanged();
private: private:
/** void updateDevicePixelRatio();
* Overrides the devicePixelRatio
*
* Set the device pixel ratio to a custom value.
*
* @arg ratio, 0 resets to detected value
*/
void setDevicePixelRatio(const qreal ratio);
void updateSpacing(); void updateSpacing();
/** /**
* @return The dpi-adjusted size for a given icon size * @return The dpi-adjusted size for a given icon size