From 2a217dff0adf04c971ef634c4934bf4c62846cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Tue, 28 Jan 2014 01:15:38 +0100 Subject: [PATCH] Remove unneeded API - dpi(QQI*) and printScreenInfo(QQI*) goes away, they're mainly useful for testing. - setDevicePixelRatio goes private - clarify DPI computation --- .../testtheme/contents/ui/UnitsPage.qml | 5 +- .../testtheme/contents/ui/testtheme.qml | 1 + src/declarativeimports/core/units.cpp | 52 ++----------------- src/declarativeimports/core/units.h | 28 ++++------ 4 files changed, 18 insertions(+), 68 deletions(-) diff --git a/examples/applets/testtheme/contents/ui/UnitsPage.qml b/examples/applets/testtheme/contents/ui/UnitsPage.qml index 29d85e80a..74aba62c6 100644 --- a/examples/applets/testtheme/contents/ui/UnitsPage.qml +++ b/examples/applets/testtheme/contents/ui/UnitsPage.qml @@ -52,9 +52,8 @@ Item { width: cwidth/2 onClicked: { print("DPI Button onClicked"); - units.printScreenInfo(dpilabel); - var d = units.dpi(dpilabel); - dpilabel.text = "\t" + d + var d = units.devicePixelRatio * 96; + dpilabel.text = "\t" + d; } } PlasmaComponents.Label { diff --git a/examples/applets/testtheme/contents/ui/testtheme.qml b/examples/applets/testtheme/contents/ui/testtheme.qml index 6cf138f9b..2fcaa02c1 100644 --- a/examples/applets/testtheme/contents/ui/testtheme.qml +++ b/examples/applets/testtheme/contents/ui/testtheme.qml @@ -80,6 +80,7 @@ Item { PlasmaComponents.Slider { id: dprSlider + visible: false anchors { bottom: parent.bottom bottomMargin: units.largeSpacing/2 diff --git a/src/declarativeimports/core/units.cpp b/src/declarativeimports/core/units.cpp index ea3836621..34c93f4e7 100644 --- a/src/declarativeimports/core/units.cpp +++ b/src/declarativeimports/core/units.cpp @@ -119,12 +119,13 @@ void Units::setDevicePixelRatio(const qreal scale) if (scale <= 0) { // Going through QDesktopWidget seems to be the most reliable way no // to get the DPI, and thus devicePixelRatio - // Using QGuiApplication::devicePixelRatio() gives unexpected values, - // i.e. it assumes DPI to be 100 on a 180 DPI screen. - m_dpi = QApplication::desktop()->physicalDpiX(); + // Using QGuiApplication::devicePixelRatio() gives too coarse values, + // i.e. it directly jumps from 1.0 to 2.0. We want tighter control on + // sizing, so we compute the exact ratio and use that. + qreal dpi = QApplication::desktop()->physicalDpiX(); // Usual "default" is 96 dpi // that magic ratio follows the definition of "device independent pixel" by Microsoft - m_devicePixelRatio = (qreal)m_dpi / (qreal)96; + m_devicePixelRatio = (qreal)dpi / (qreal)96; } else { m_devicePixelRatio = scale; } @@ -149,49 +150,6 @@ void Units::themeChanged() } } -qreal Units::dpi(QQuickItem* item) -{ - int _dpi = 96; - if (item) { - QScreen* screen = item->window()->screen(); - if (screen) { - _dpi = screen->physicalDotsPerInch(); - } - } - return _dpi; -} - -void Units::printScreenInfo(QQuickItem* item) -{ - int _dpi = dpi(item); - qDebug() << " ----- printScreenInfo() ---- "; - if (item) { - QScreen* screen = item->window()->screen(); - if (screen) { - qDebug() << "screen geo: " << screen->availableGeometry(); - _dpi = screen->physicalDotsPerInch(); - qDebug() << " refreshRate : " << screen->refreshRate(); - qDebug() << " devicePixelRatio: " << screen->devicePixelRatio(); - qDebug() << " qApp->devicePR : " << qApp->devicePixelRatio(); - qDebug() << " depth : " << screen->depth(); - qDebug() << " dpi X: " << screen->physicalDotsPerInchX(); - qDebug() << " dpi Y: " << screen->physicalDotsPerInchY(); - qDebug() << " ->> dpi: " << _dpi; - } - } - qDebug() << "FontMetrics: " << QApplication::font().pointSize() << QFontMetrics(QApplication::font()).boundingRect("M"); - qDebug() << " MRect" << QFontMetrics(QApplication::font()).boundingRect("M").size(); - qDebug() << " gridUnit: " << QFontMetrics(QApplication::font()).boundingRect("M").size().height(); - - - qDebug() << " Small " << KIconLoader::SizeSmall << " -> " << devicePixelIconSize(KIconLoader::SizeSmall); - qDebug() << " SMedi " << KIconLoader::SizeSmallMedium << " -> " << devicePixelIconSize(KIconLoader::SizeSmallMedium); - qDebug() << " Mediu " << KIconLoader::SizeMedium << " -> " << devicePixelIconSize(KIconLoader::SizeMedium); - qDebug() << " Large " << KIconLoader::SizeLarge << " -> " << devicePixelIconSize(KIconLoader::SizeLarge); - qDebug() << " Huge " << KIconLoader::SizeHuge << " -> " << devicePixelIconSize(KIconLoader::SizeHuge); - qDebug() << " Enorm " << KIconLoader::SizeEnormous << " -> " << devicePixelIconSize(KIconLoader::SizeEnormous); -} - int Units::smallSpacing() const { return m_smallSpacing; diff --git a/src/declarativeimports/core/units.h b/src/declarativeimports/core/units.h index c7ecf22a3..8fc1b7e17 100644 --- a/src/declarativeimports/core/units.h +++ b/src/declarativeimports/core/units.h @@ -81,7 +81,7 @@ class Units : public QObject * use theme.mSize(theme.defaultFont), units.smallSpacing and units.largeSpacing. * The devicePixelRatio follows the definition of "device independent pixel" by Microsoft. */ - Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged) + Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged) public: Units(QObject *parent = 0); @@ -94,16 +94,6 @@ public: */ int gridUnit() const; - - /** - * 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. */ @@ -126,13 +116,6 @@ public: */ int largeSpacing() const; - /** - * @returns the dpi value for the item's screen - */ - Q_INVOKABLE qreal dpi(QQuickItem *item); - - Q_INVOKABLE void printScreenInfo(QQuickItem *item); - Q_SIGNALS: void devicePixelRatioChanged(); void gridUnitChanged(); @@ -144,6 +127,15 @@ private Q_SLOTS: void iconLoaderSettingsChanged(); private: + /** + * 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(); /** * @return The dpi-adjusted size for a given icon size