Drop QApplication usages in units.cpp

Drop dependency to QtWidgets from this file. We can start assuming that it
might not be that functional in some platforms.
Use QGuiApplication counterparts, based mostly on QScreen, which could make
it more powerful in the future.

REVIEW: 117161
This commit is contained in:
Aleix Pol 2014-03-30 23:05:51 +02:00
parent 37179fb7a0
commit 018bd82aca

View File

@ -152,21 +152,22 @@ qreal Units::devicePixelRatio() const
void Units::updateDisplayAspectRatio() void Units::updateDisplayAspectRatio()
{ {
QWidget *screen = QApplication::desktop()->screen(); QRect geometry = QGuiApplication::primaryScreen()->virtualGeometry();
m_displayAspectRatio = screen->width() / (qreal)screen->height(); m_displayAspectRatio = geometry.width() / geometry.height();
emit displayAspectRatioChanged(); emit displayAspectRatioChanged();
} }
void Units::updateDevicePixelRatio() void Units::updateDevicePixelRatio()
{ {
// Going through QDesktopWidget seems to be the most reliable way no
// to get the DPI, and thus devicePixelRatio
// Using QGuiApplication::devicePixelRatio() gives too coarse values, // Using QGuiApplication::devicePixelRatio() gives too coarse values,
// i.e. it directly jumps from 1.0 to 2.0. We want tighter control on // 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. // sizing, so we compute the exact ratio and use that.
qreal dpi = QApplication::desktop()->physicalDpiX(); // TODO: make it possible to adapt to the dpi for the current screen dpi
// instead of assuming that all of them use the same dpi which applies for
// X11 but not for other systems.
qreal dpi = QGuiApplication::primaryScreen()->physicalDotsPerInchX();
// Usual "default" is 96 dpi // Usual "default" is 96 dpi
// that magic ratio follows the definition of "device independent pixel" by Microsoft // that magic ratio follows the definition of "device independent pixel" by Microsoft
m_devicePixelRatio = (qreal)dpi / (qreal)96; m_devicePixelRatio = (qreal)dpi / (qreal)96;
@ -181,7 +182,7 @@ int Units::gridUnit() const
void Units::themeChanged() void Units::themeChanged()
{ {
const int gridUnit = QFontMetrics(QApplication::font()).boundingRect("M").height(); const int gridUnit = QFontMetrics(QGuiApplication::font()).boundingRect("M").height();
if (gridUnit != m_gridUnit) { if (gridUnit != m_gridUnit) {
m_gridUnit = gridUnit; m_gridUnit = gridUnit;
emit gridUnitChanged(); emit gridUnitChanged();
@ -200,7 +201,7 @@ int Units::largeSpacing() const
void Units::updateSpacing() void Units::updateSpacing()
{ {
const int _s = QFontMetrics(QApplication::font()).boundingRect("M").size().height(); const int _s = QFontMetrics(QGuiApplication::font()).boundingRect("M").size().height();
if (_s != m_largeSpacing) { if (_s != m_largeSpacing) {
m_smallSpacing = qMax(2, (int)(_s / 8)); // 1/8 of msize.height, at least 2 m_smallSpacing = qMax(2, (int)(_s / 8)); // 1/8 of msize.height, at least 2
m_largeSpacing = _s; // msize.height m_largeSpacing = _s; // msize.height