Remove unneeded API

- dpi(QQI*) and printScreenInfo(QQI*) goes away, they're mainly useful for
  testing.
- setDevicePixelRatio goes private
- clarify DPI computation
This commit is contained in:
Sebastian Kügler 2014-01-28 01:15:38 +01:00
parent b7fcea471c
commit 2a217dff0a
4 changed files with 18 additions and 68 deletions

View File

@ -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 {

View File

@ -80,6 +80,7 @@ Item {
PlasmaComponents.Slider {
id: dprSlider
visible: false
anchors {
bottom: parent.bottom
bottomMargin: units.largeSpacing/2

View File

@ -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;

View File

@ -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