Add dpi function from theme

printScreenInfo() has the debugging prints for now, removes random crap
from the shell output.
This commit is contained in:
Sebastian Kügler 2014-01-22 01:36:30 +01:00
parent b89902c3e7
commit d51711edc6
2 changed files with 47 additions and 3 deletions

View File

@ -23,6 +23,9 @@
#include <QDebug>
#include <QDesktopWidget>
#include <QtGlobal>
#include <QQuickItem>
#include <QQuickWindow>
#include <QScreen>
#include <cmath>
#include <KIconLoader>
@ -113,14 +116,47 @@ qreal Units::gu(qreal value) const
void Units::themeChanged()
{
const int gridUnit = QFontMetrics(QApplication::font()).boundingRect("M").height();
qDebug() << "FontMetrics: " << QApplication::font().pixelSize() << QFontMetrics(QApplication::font()).boundingRect("M");
qDebug() << " MRect" << QFontMetrics(QApplication::font()).boundingRect("M").size();
qDebug() << " like spacing" << QFontMetrics(QApplication::font()).boundingRect("M").size().height();
if (gridUnit != m_gridUnit) {
m_gridUnit = gridUnit;
emit gridUnitChanged();
}
}
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() << " 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();
}
#include "units.moc"

View File

@ -25,6 +25,8 @@
#include <Plasma/Theme>
class QQuickItem;
class Units : public QObject
{
Q_OBJECT
@ -68,6 +70,12 @@ public:
*/
Q_INVOKABLE qreal gu(qreal value) 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 dpiScaleChanged();