Allow to reset devicePixelRatio
Setting devicePixelRatio to 0 re-reads it and resets it to its default value.
This commit is contained in:
parent
979dc0c25f
commit
e346c751ec
@ -32,13 +32,10 @@
|
||||
|
||||
Units::Units (QObject *parent)
|
||||
: QObject(parent),
|
||||
m_gridUnit(-1)
|
||||
m_gridUnit(-1),
|
||||
m_devicePixelRatio(-1)
|
||||
{
|
||||
//Usual "default" is 96 dpi
|
||||
//that magic ratio follows the definition of "device independent pixel" by Microsoft
|
||||
m_dpi = QApplication::desktop()->physicalDpiX();
|
||||
m_devicePixelRatio = (qreal)m_dpi / (qreal)96;
|
||||
|
||||
setDevicePixelRatio(0);
|
||||
updateSpacing();
|
||||
|
||||
m_iconSizes = new QQmlPropertyMap(this);
|
||||
@ -80,15 +77,21 @@ QQmlPropertyMap *Units::iconSizes() const
|
||||
|
||||
qreal Units::devicePixelRatio() const
|
||||
{
|
||||
|
||||
return m_devicePixelRatio;
|
||||
}
|
||||
|
||||
void Units::setDevicePixelRatio(const qreal scale)
|
||||
{
|
||||
if (m_devicePixelRatio != scale) {
|
||||
m_devicePixelRatio = scale;
|
||||
qDebug() << "Setting dpi scale to " << scale;
|
||||
if (scale <= 0) {
|
||||
//Usual "default" is 96 dpi
|
||||
//that magic ratio follows the definition of "device independent pixel" by Microsoft
|
||||
m_dpi = QApplication::desktop()->physicalDpiX();
|
||||
m_devicePixelRatio = (qreal)m_dpi / (qreal)96;
|
||||
} else {
|
||||
m_devicePixelRatio = scale;
|
||||
}
|
||||
qDebug() << "Setting dpi scale to " << scale;
|
||||
emit devicePixelRatioChanged();
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,9 @@ class Units : public QObject
|
||||
Q_PROPERTY(int smallSpacing READ smallSpacing NOTIFY spacingChanged)
|
||||
Q_PROPERTY(int largeSpacing READ largeSpacing NOTIFY spacingChanged)
|
||||
|
||||
/**
|
||||
* The ratio between physical and device-independent pixels.
|
||||
*/
|
||||
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged)
|
||||
|
||||
public:
|
||||
@ -74,7 +77,19 @@ public:
|
||||
|
||||
qreal gridUnit() const;
|
||||
|
||||
void setDevicePixelRatio(const qreal scale);
|
||||
|
||||
/**
|
||||
* Overrides the devicePixelRatio
|
||||
*
|
||||
* Set the device pixel ratio to a custom value.
|
||||
*
|
||||
* @arg ratio, 0 resets to detected value
|
||||
*/
|
||||
void setDevicePixelRatio(const qreal ratio);
|
||||
|
||||
/**
|
||||
* @return The ratio between physical and device-independent pixels.
|
||||
*/
|
||||
qreal devicePixelRatio() const;
|
||||
|
||||
QQmlPropertyMap *iconSizes() const;
|
||||
|
Loading…
Reference in New Issue
Block a user