QML UI: better handling of device pixel ratio

In order to make sure we don't render the initial profiles with the
wrong scale on devices, we need to seed the device pixel ratio with the
device default and then update it once the window has been created.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-04-03 17:29:06 -07:00
parent e700ea9638
commit 01d091fbd5
3 changed files with 11 additions and 1 deletions

View file

@ -85,10 +85,10 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
m_updateSelectedDive(-1), m_updateSelectedDive(-1),
m_selectedDiveTimestamp(0), m_selectedDiveTimestamp(0),
m_credentialStatus(UNKNOWN), m_credentialStatus(UNKNOWN),
m_lastDevicePixelRatio(1.0),
alreadySaving(false) alreadySaving(false)
{ {
m_instance = this; m_instance = this;
m_lastDevicePixelRatio = qApp->devicePixelRatio();
connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged); connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged);
appendTextToLog(getUserAgent()); appendTextToLog(getUserAgent());
appendTextToLog(QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion())); appendTextToLog(QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion()));
@ -1412,6 +1412,14 @@ qreal QMLManager::lastDevicePixelRatio()
return m_lastDevicePixelRatio; return m_lastDevicePixelRatio;
} }
void QMLManager::setDevicePixelRatio(qreal dpr, QScreen *screen)
{
if (m_lastDevicePixelRatio != dpr) {
m_lastDevicePixelRatio = dpr;
emit sendScreenChanged(screen);
}
}
void QMLManager::screenChanged(QScreen *screen) void QMLManager::screenChanged(QScreen *screen)
{ {
m_lastDevicePixelRatio = screen->devicePixelRatio(); m_lastDevicePixelRatio = screen->devicePixelRatio();

View file

@ -154,6 +154,7 @@ public slots:
void refreshDiveList(); void refreshDiveList();
void screenChanged(QScreen *screen); void screenChanged(QScreen *screen);
qreal lastDevicePixelRatio(); qreal lastDevicePixelRatio();
void setDevicePixelRatio(qreal dpr, QScreen *screen);
void appendTextToLog(const QString &newText); void appendTextToLog(const QString &newText);
void quit(); void quit();
void hasLocationSourceChanged(); void hasLocationSourceChanged();

View file

@ -79,6 +79,7 @@ void run_ui()
QScreen *screen = qml_window->screen(); QScreen *screen = qml_window->screen();
QObject::connect(qml_window, &QQuickWindow::screenChanged, QMLManager::instance(), &QMLManager::screenChanged); QObject::connect(qml_window, &QQuickWindow::screenChanged, QMLManager::instance(), &QMLManager::screenChanged);
QMLManager *manager = QMLManager::instance(); QMLManager *manager = QMLManager::instance();
manager->setDevicePixelRatio(qml_window->devicePixelRatio(), qml_window->screen());
manager->dlSortModel = sortModel; manager->dlSortModel = sortModel;
manager->screenChanged(screen); manager->screenChanged(screen);
qDebug() << "qqwindow screen has ldpi/pdpi" << screen->logicalDotsPerInch() << screen->physicalDotsPerInch(); qDebug() << "qqwindow screen has ldpi/pdpi" << screen->logicalDotsPerInch() << screen->physicalDotsPerInch();