diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-08-28 07:33:51 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-08-28 07:33:51 +0200 |
commit | b2054433516f7161906d45de0971bbc032576ded (patch) | |
tree | 41622e555a036fa86ac9a585a016e148eaa7f40c /src/gui | |
parent | c1e4c7d7639b84c0220e3a2ddd455d03c0910893 (diff) | |
parent | ebec918722a283410624af6df38345b9dfc0b8f8 (diff) |
Merge remote-tracking branch 'origin/5.14' into dev
Change-Id: Icb486cf8f31ec85d940b2179e8d023fbbc7fd3fa
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 44 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qhighdpiscaling.cpp | 335 | ||||
-rw-r--r-- | src/gui/kernel/qhighdpiscaling_p.h | 23 | ||||
-rw-r--r-- | src/gui/kernel/qplatformscreen.cpp | 22 | ||||
-rw-r--r-- | src/gui/kernel/qplatformscreen.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qscreen.cpp | 13 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface.cpp | 4 | ||||
-rw-r--r-- | src/gui/rhi/qrhi.cpp | 105 | ||||
-rw-r--r-- | src/gui/rhi/qrhid3d11.cpp | 9 | ||||
-rw-r--r-- | src/gui/rhi/qrhigles2.cpp | 9 | ||||
-rw-r--r-- | src/gui/rhi/qrhinull.cpp | 9 | ||||
-rw-r--r-- | src/gui/rhi/qrhiprofiler.cpp | 9 | ||||
-rw-r--r-- | src/gui/rhi/qrhivulkan.cpp | 12 | ||||
-rw-r--r-- | src/gui/rhi/qshader.cpp | 12 | ||||
-rw-r--r-- | src/gui/rhi/qshaderdescription.cpp | 18 | ||||
-rw-r--r-- | src/gui/text/qfontmetrics.cpp | 19 | ||||
-rw-r--r-- | src/gui/text/qfontmetrics.h | 4 | ||||
-rw-r--r-- | src/gui/text/qtextdocumentfragment.cpp | 2 |
20 files changed, 534 insertions, 122 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 426f2aeece..ddd6726299 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -146,6 +146,8 @@ QString QGuiApplicationPrivate::styleOverride; Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive; +Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = + Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor; bool QGuiApplicationPrivate::highDpiScalingUpdated = false; QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow; @@ -687,6 +689,8 @@ QGuiApplication::~QGuiApplication() QGuiApplicationPrivate::lastCursorPosition = {qInf(), qInf()}; QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow = nullptr; QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive; + QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = + Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor; QGuiApplicationPrivate::highDpiScalingUpdated = false; QGuiApplicationPrivate::currentDragWindow = nullptr; QGuiApplicationPrivate::tabletDevicePoints.clear(); @@ -3491,6 +3495,46 @@ Qt::ApplicationState QGuiApplication::applicationState() } /*! + \since 5.14 + + Sets the high-DPI scale factor rounding policy for the application. The + policy decides how non-integer scale factors (such as Windows 150%) are + handled, for applications that have AA_EnableHighDpiScaling enabled. + + The two principal options are whether fractional scale factors should + be rounded to an integer or not. Keeping the scale factor as-is will + make the user interface size match the OS setting exactly, but may cause + painting errors, for example with the Windows style. + + If rounding is wanted, then which type of rounding should be decided + next. Mathematically correct rounding is supported but may not give + the best visual results: Consider if you want to render 1.5x as 1x + ("small UI") or as 2x ("large UI"). See the Qt::HighDpiScaleFactorRoundingPolicy + enum for a complete list of all options. + + This function must be called before creating the application object, + and can be overridden by setting the QT_SCALE_FACTOR_ROUNDING_POLICY + environment variable. The QGuiApplication::highDpiScaleFactorRoundingPolicy() + accessor will reflect the environment, if set. + + The default value is Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor. +*/ +void QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy) +{ + QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = policy; +} + +/*! + \since 5.14 + + Returns the high-DPI scale factor rounding policy. +*/ +Qt::HighDpiScaleFactorRoundingPolicy QGuiApplication::highDpiScaleFactorRoundingPolicy() +{ + return QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy; +} + +/*! \since 5.2 \fn void QGuiApplication::applicationStateChanged(Qt::ApplicationState state) diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index 5ea72fa0f6..fc74c5299a 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -156,6 +156,9 @@ public: static Qt::ApplicationState applicationState(); + static void setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy); + static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy(); + static int exec(); bool notify(QObject *, QEvent *) override; diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index afca7579ea..e28607bad6 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -223,6 +223,7 @@ public: static QWindow *currentMouseWindow; static QWindow *currentMousePressWindow; static Qt::ApplicationState applicationState; + static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy; static bool highDpiScalingUpdated; static QPointer<QWindow> currentDragWindow; diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 64f1397771..c031885d5d 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -46,6 +46,9 @@ #include <private/qguiapplication_p.h> #include <QtCore/qdebug.h> +#include <QtCore/qmetaobject.h> + +#include <algorithm> QT_BEGIN_NAMESPACE @@ -53,9 +56,29 @@ Q_LOGGING_CATEGORY(lcScaling, "qt.scaling"); #ifndef QT_NO_HIGHDPISCALING static const char legacyDevicePixelEnvVar[] = "QT_DEVICE_PIXEL_RATIO"; +static const char legacyAutoScreenEnvVar[] = "QT_AUTO_SCREEN_SCALE_FACTOR"; + +static const char enableHighDpiScalingEnvVar[] = "QT_ENABLE_HIGHDPI_SCALING"; static const char scaleFactorEnvVar[] = "QT_SCALE_FACTOR"; -static const char autoScreenEnvVar[] = "QT_AUTO_SCREEN_SCALE_FACTOR"; static const char screenFactorsEnvVar[] = "QT_SCREEN_SCALE_FACTORS"; +static const char scaleFactorRoundingPolicyEnvVar[] = "QT_SCALE_FACTOR_ROUNDING_POLICY"; +static const char dpiAdjustmentPolicyEnvVar[] = "QT_DPI_ADJUSTMENT_POLICY"; +static const char usePhysicalDpiEnvVar[] = "QT_USE_PHYSICAL_DPI"; + +// Per-screen scale factors for named screens set with QT_SCREEN_SCALE_FACTORS +// are stored here. Use a global hash to keep the factor across screen +// disconnect/connect cycles where the screen object may be deleted. +typedef QHash<QString, qreal> QScreenScaleFactorHash; +Q_GLOBAL_STATIC(QScreenScaleFactorHash, qNamedScreenScaleFactors); + +// Reads and interprets the given environment variable as a bool, +// returns the default value if not set. +static bool qEnvironmentVariableAsBool(const char *name, bool defaultValue) +{ + bool ok = false; + int value = qEnvironmentVariableIntValue(name, &ok); + return ok ? value > 0 : defaultValue; +} static inline qreal initialGlobalScaleFactor() { @@ -69,17 +92,24 @@ static inline qreal initialGlobalScaleFactor() result = f; } } else { + // Check for deprecated environment variables. if (qEnvironmentVariableIsSet(legacyDevicePixelEnvVar)) { qWarning("Warning: %s is deprecated. Instead use:\n" " %s to enable platform plugin controlled per-screen factors.\n" - " %s to set per-screen factors.\n" + " %s to set per-screen DPI.\n" " %s to set the application global scale factor.", - legacyDevicePixelEnvVar, autoScreenEnvVar, screenFactorsEnvVar, scaleFactorEnvVar); + legacyDevicePixelEnvVar, legacyAutoScreenEnvVar, screenFactorsEnvVar, scaleFactorEnvVar); int dpr = qEnvironmentVariableIntValue(legacyDevicePixelEnvVar); if (dpr > 0) result = dpr; } + + if (qEnvironmentVariableIsSet(legacyAutoScreenEnvVar)) { + qWarning("Warning: %s is deprecated. Instead use:\n" + " %s to enable platform plugin controlled per-screen factors.", + legacyAutoScreenEnvVar, enableHighDpiScalingEnvVar); + } } return result; } @@ -226,7 +256,6 @@ bool QHighDpiScaling::m_usePixelDensity = false; // use scale factor from platfo bool QHighDpiScaling::m_pixelDensityScalingActive = false; // pixel density scale factor > 1 bool QHighDpiScaling::m_globalScalingActive = false; // global scale factor is active bool QHighDpiScaling::m_screenFactorSet = false; // QHighDpiScaling::setScreenFactor has been used -QDpi QHighDpiScaling::m_logicalDpi = QDpi(-1,-1); // The scaled logical DPI of the primary screen /* Initializes the QHighDpiScaling global variables. Called before the @@ -238,16 +267,214 @@ static inline bool usePixelDensity() // Determine if we should set a scale factor based on the pixel density // reported by the platform plugin. There are several enablers and several // disablers. A single disable may veto all other enablers. + + // First, check of there is an explicit disable. if (QCoreApplication::testAttribute(Qt::AA_DisableHighDpiScaling)) return false; bool screenEnvValueOk; - const int screenEnvValue = qEnvironmentVariableIntValue(autoScreenEnvVar, &screenEnvValueOk); + const int screenEnvValue = qEnvironmentVariableIntValue(legacyAutoScreenEnvVar, &screenEnvValueOk); if (screenEnvValueOk && screenEnvValue < 1) return false; + bool enableEnvValueOk; + const int enableEnvValue = qEnvironmentVariableIntValue(enableHighDpiScalingEnvVar, &enableEnvValueOk); + if (enableEnvValueOk && enableEnvValue < 1) + return false; + + // Then return if there was an enable. return QCoreApplication::testAttribute(Qt::AA_EnableHighDpiScaling) || (screenEnvValueOk && screenEnvValue > 0) - || (qEnvironmentVariableIsSet(legacyDevicePixelEnvVar) && - qgetenv(legacyDevicePixelEnvVar).compare("auto", Qt::CaseInsensitive) == 0); + || (enableEnvValueOk && enableEnvValue > 0) + || (qEnvironmentVariableIsSet(legacyDevicePixelEnvVar) && qgetenv(legacyDevicePixelEnvVar).toLower() == "auto"); +} + +qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen) +{ + // Determine if physical DPI should be used + static const bool usePhysicalDpi = qEnvironmentVariableAsBool(usePhysicalDpiEnvVar, false); + + // Calculate scale factor beased on platform screen DPI values + qreal factor; + QDpi platformBaseDpi = screen->logicalBaseDpi(); + if (usePhysicalDpi) { + qreal platformPhysicalDpi = screen->screen()->physicalDotsPerInch(); + factor = qreal(platformPhysicalDpi) / qreal(platformBaseDpi.first); + } else { + const QDpi platformLogicalDpi = QPlatformScreen::overrideDpi(screen->logicalDpi()); + factor = qreal(platformLogicalDpi.first) / qreal(platformBaseDpi.first); + } + + return factor; +} + +template <class EnumType> +struct EnumLookup +{ + const char *name; + EnumType value; +}; + +template <class EnumType> +static bool operator==(const EnumLookup<EnumType> &e1, const EnumLookup<EnumType> &e2) +{ + return qstricmp(e1.name, e2.name) == 0; +} + +template <class EnumType> +static QByteArray joinEnumValues(const EnumLookup<EnumType> *i1, const EnumLookup<EnumType> *i2) +{ + QByteArray result; + for (; i1 < i2; ++i1) { + if (!result.isEmpty()) + result += QByteArrayLiteral(", "); + result += i1->name; + } + return result; +} + +using ScaleFactorRoundingPolicyLookup = EnumLookup<Qt::HighDpiScaleFactorRoundingPolicy>; + +static const ScaleFactorRoundingPolicyLookup scaleFactorRoundingPolicyLookup[] = +{ + {"Round", Qt::HighDpiScaleFactorRoundingPolicy::Round}, + {"Ceil", Qt::HighDpiScaleFactorRoundingPolicy::Ceil}, + {"Floor", Qt::HighDpiScaleFactorRoundingPolicy::Floor}, + {"RoundPreferFloor", Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor}, + {"PassThrough", Qt::HighDpiScaleFactorRoundingPolicy::PassThrough} +}; + +static Qt::HighDpiScaleFactorRoundingPolicy + lookupScaleFactorRoundingPolicy(const QByteArray &v) +{ + auto end = std::end(scaleFactorRoundingPolicyLookup); + auto it = std::find(std::begin(scaleFactorRoundingPolicyLookup), end, + ScaleFactorRoundingPolicyLookup{v.constData(), Qt::HighDpiScaleFactorRoundingPolicy::Unset}); + return it != end ? it->value : Qt::HighDpiScaleFactorRoundingPolicy::Unset; +} + +using DpiAdjustmentPolicyLookup = EnumLookup<QHighDpiScaling::DpiAdjustmentPolicy>; + +static const DpiAdjustmentPolicyLookup dpiAdjustmentPolicyLookup[] = +{ + {"AdjustDpi", QHighDpiScaling::DpiAdjustmentPolicy::Enabled}, + {"DontAdjustDpi", QHighDpiScaling::DpiAdjustmentPolicy::Disabled}, + {"AdjustUpOnly", QHighDpiScaling::DpiAdjustmentPolicy::UpOnly} +}; + +static QHighDpiScaling::DpiAdjustmentPolicy + lookupDpiAdjustmentPolicy(const QByteArray &v) +{ + auto end = std::end(dpiAdjustmentPolicyLookup); + auto it = std::find(std::begin(dpiAdjustmentPolicyLookup), end, + DpiAdjustmentPolicyLookup{v.constData(), QHighDpiScaling::DpiAdjustmentPolicy::Unset}); + return it != end ? it->value : QHighDpiScaling::DpiAdjustmentPolicy::Unset; +} + +qreal QHighDpiScaling::roundScaleFactor(qreal rawFactor) +{ + // Apply scale factor rounding policy. Using mathematically correct rounding + // may not give the most desirable visual results, especially for + // critical fractions like .5. In general, rounding down results in visual + // sizes that are smaller than the ideal size, and opposite for rounding up. + // Rounding down is then preferable since "small UI" is a more acceptable + // high-DPI experience than "large UI". + static auto scaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::Unset; + + // Determine rounding policy + if (scaleFactorRoundingPolicy == Qt::HighDpiScaleFactorRoundingPolicy::Unset) { + // Check environment + if (qEnvironmentVariableIsSet(scaleFactorRoundingPolicyEnvVar)) { + QByteArray policyText = qgetenv(scaleFactorRoundingPolicyEnvVar); + auto policyEnumValue = lookupScaleFactorRoundingPolicy(policyText); + if (policyEnumValue != Qt::HighDpiScaleFactorRoundingPolicy::Unset) { + scaleFactorRoundingPolicy = policyEnumValue; + } else { + auto values = joinEnumValues(std::begin(scaleFactorRoundingPolicyLookup), + std::end(scaleFactorRoundingPolicyLookup)); + qWarning("Unknown scale factor rounding policy: %s. Supported values are: %s.", + policyText.constData(), values.constData()); + } + } + + // Check application object if no environment value was set. + if (scaleFactorRoundingPolicy == Qt::HighDpiScaleFactorRoundingPolicy::Unset) { + scaleFactorRoundingPolicy = QGuiApplication::highDpiScaleFactorRoundingPolicy(); + } else { + // Make application setting reflect environment + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(scaleFactorRoundingPolicy); + } + } + + // Apply rounding policy. + qreal roundedFactor = rawFactor; + switch (scaleFactorRoundingPolicy) { + case Qt::HighDpiScaleFactorRoundingPolicy::Round: + roundedFactor = qRound(rawFactor); + break; + case Qt::HighDpiScaleFactorRoundingPolicy::Ceil: + roundedFactor = qCeil(rawFactor); + break; + case Qt::HighDpiScaleFactorRoundingPolicy::Floor: + roundedFactor = qFloor(rawFactor); + break; + case Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor: + // Round up for .75 and higher. This favors "small UI" over "large UI". + roundedFactor = rawFactor - qFloor(rawFactor) < 0.75 + ? qFloor(rawFactor) : qCeil(rawFactor); + break; + case Qt::HighDpiScaleFactorRoundingPolicy::PassThrough: + case Qt::HighDpiScaleFactorRoundingPolicy::Unset: + break; + } + + // Don't round down to to zero; clamp the minimum (rounded) factor to 1. + // This is not a common case but can happen if a display reports a very + // low DPI. + if (scaleFactorRoundingPolicy != Qt::HighDpiScaleFactorRoundingPolicy::PassThrough) + roundedFactor = qMax(roundedFactor, qreal(1)); + + return roundedFactor; +} + +QDpi QHighDpiScaling::effectiveLogicalDpi(const QPlatformScreen *screen, qreal rawFactor, qreal roundedFactor) +{ + // Apply DPI adjustment policy, if needed. If enabled this will change the + // reported logical DPI to account for the difference between the rounded + // scale factor and the actual scale factor. The effect is that text size + // will be correct for the screen dpi, but may be (slightly) out of sync + // with the rest of the UI. The amount of out-of-synch-ness depends on how + // well user code handles a non-standard DPI values, but since the + // adjustment is small (typically +/- 48 max) this might be OK. + static auto dpiAdjustmentPolicy = DpiAdjustmentPolicy::Unset; + + // Determine adjustment policy. + if (dpiAdjustmentPolicy == DpiAdjustmentPolicy::Unset) { + if (qEnvironmentVariableIsSet(dpiAdjustmentPolicyEnvVar)) { + QByteArray policyText = qgetenv(dpiAdjustmentPolicyEnvVar); + auto policyEnumValue = lookupDpiAdjustmentPolicy(policyText); + if (policyEnumValue != DpiAdjustmentPolicy::Unset) { + dpiAdjustmentPolicy = policyEnumValue; + } else { + auto values = joinEnumValues(std::begin(dpiAdjustmentPolicyLookup), + std::end(dpiAdjustmentPolicyLookup)); + qWarning("Unknown DPI adjustment policy: %s. Supported values are: %s.", + policyText.constData(), values.constData()); + } + } + if (dpiAdjustmentPolicy == DpiAdjustmentPolicy::Unset) + dpiAdjustmentPolicy = DpiAdjustmentPolicy::UpOnly; + } + + // Apply adjustment policy. + const QDpi baseDpi = screen->logicalBaseDpi(); + const qreal dpiAdjustmentFactor = rawFactor / roundedFactor; + + // Return the base DPI for cases where there is no adjustment + if (dpiAdjustmentPolicy == DpiAdjustmentPolicy::Disabled) + return baseDpi; + if (dpiAdjustmentPolicy == DpiAdjustmentPolicy::UpOnly && dpiAdjustmentFactor < 1) + return baseDpi; + + return QDpi(baseDpi.first * dpiAdjustmentFactor, baseDpi.second * dpiAdjustmentFactor); } void QHighDpiScaling::initHighDpiScaling() @@ -260,8 +487,6 @@ void QHighDpiScaling::initHighDpiScaling() m_pixelDensityScalingActive = false; //set in updateHighDpiScaling below - // we update m_active in updateHighDpiScaling, but while we create the - // screens, we have to assume that m_usePixelDensity implies scaling m_active = m_globalScalingActive || m_usePixelDensity; } @@ -283,20 +508,19 @@ void QHighDpiScaling::updateHighDpiScaling() int i = 0; const auto specs = qgetenv(screenFactorsEnvVar).split(';'); for (const QByteArray &spec : specs) { - QScreen *screen = 0; int equalsPos = spec.lastIndexOf('='); - double factor = 0; + qreal factor = 0; if (equalsPos > 0) { // support "name=factor" QByteArray name = spec.mid(0, equalsPos); QByteArray f = spec.mid(equalsPos + 1); bool ok; factor = f.toDouble(&ok); - if (ok) { + if (ok && factor > 0 ) { const auto screens = QGuiApplication::screens(); for (QScreen *s : screens) { if (s->name() == QString::fromLocal8Bit(name)) { - screen = s; + setScreenFactor(s, factor); break; } } @@ -305,23 +529,15 @@ void QHighDpiScaling::updateHighDpiScaling() // listing screens in order bool ok; factor = spec.toDouble(&ok); - if (ok && i < QGuiApplication::screens().count()) - screen = QGuiApplication::screens().at(i); + if (ok && factor > 0 && i < QGuiApplication::screens().count()) { + QScreen *screen = QGuiApplication::screens().at(i); + setScreenFactor(screen, factor); + } } - if (screen) - setScreenFactor(screen, factor); ++i; } } - m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive; - - QScreen *primaryScreen = QGuiApplication::primaryScreen(); - if (!primaryScreen) - return; - QPlatformScreen *platformScreen = primaryScreen->handle(); - qreal sf = screenSubfactor(platformScreen); - QDpi primaryDpi = platformScreen->logicalDpi(); - m_logicalDpi = QDpi(primaryDpi.first / sf, primaryDpi.second / sf); + m_active = m_globalScalingActive || m_usePixelDensity; } /* @@ -353,7 +569,14 @@ void QHighDpiScaling::setScreenFactor(QScreen *screen, qreal factor) m_screenFactorSet = true; m_active = true; } - screen->setProperty(scaleFactorProperty, QVariant(factor)); + + // Prefer associating the factor with screen name over the object + // since the screen object may be deleted on screen disconnects. + const QString name = screen->name(); + if (name.isEmpty()) + screen->setProperty(scaleFactorProperty, QVariant(factor)); + else + qNamedScreenScaleFactors()->insert(name, factor); // hack to force re-evaluation of screen geometry if (screen->handle()) @@ -421,35 +644,47 @@ QPoint QHighDpiScaling::mapPositionFromGlobal(const QPoint &pos, const QPoint &w qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen) { qreal factor = qreal(1.0); - if (screen) { - if (m_usePixelDensity) { - qreal pixelDensity = screen->pixelDensity(); - - // Pixel density reported by the screen is sometimes not precise enough, - // so recalculate it: divide px (physical pixels) by dp (device-independent pixels) - // for both width and height, and then use the average if it is different from - // the one initially reported by the screen - QRect screenGeometry = screen->geometry(); - qreal wFactor = qreal(screenGeometry.width()) / qRound(screenGeometry.width() / pixelDensity); - qreal hFactor = qreal(screenGeometry.height()) / qRound(screenGeometry.height() / pixelDensity); - qreal averageDensity = (wFactor + hFactor) / 2; - if (!qFuzzyCompare(pixelDensity, averageDensity)) - pixelDensity = averageDensity; - - factor *= pixelDensity; - } - if (m_screenFactorSet) { - QVariant screenFactor = screen->screen()->property(scaleFactorProperty); - if (screenFactor.isValid()) - factor *= screenFactor.toReal(); + if (!screen) + return factor; + + // Unlike the other code where factors are combined by multiplication, + // factors from QT_SCREEN_SCALE_FACTORS takes precedence over the factor + // computed from platform plugin DPI. The rationale is that the user is + // setting the factor to override erroneous DPI values. + bool screenPropertyUsed = false; + if (m_screenFactorSet) { + // Check if there is a factor set on the screen object or associated + // with the screen name. These are mutually exclusive, so checking + // order is not significant. + QVariant byIndex = screen->screen()->property(scaleFactorProperty); + auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name()); + if (byIndex.isValid()) { + screenPropertyUsed = true; + factor = byIndex.toReal(); + } else if (byNameIt != qNamedScreenScaleFactors()->cend()) { + screenPropertyUsed = true; + factor = *byNameIt; } } + + if (!screenPropertyUsed && m_usePixelDensity) + factor = roundScaleFactor(rawScaleFactor(screen)); + return factor; } -QDpi QHighDpiScaling::logicalDpi() +QDpi QHighDpiScaling::logicalDpi(const QScreen *screen) { - return m_logicalDpi; + // (Note: m_active test is performed at call site.) + if (!screen || !screen->handle()) + return QDpi(96, 96); + + if (!m_usePixelDensity) + return QPlatformScreen::overrideDpi(screen->handle()->logicalDpi()); + + const qreal scaleFactor = rawScaleFactor(screen->handle()); + const qreal roundedScaleFactor = roundScaleFactor(scaleFactor); + return effectiveLogicalDpi(screen->handle(), scaleFactor, roundedScaleFactor); } QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QPlatformScreen *platformScreen, QPoint *nativePosition) diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index 674b737808..f58944a7d2 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -72,11 +72,27 @@ typedef QPair<qreal, qreal> QDpi; #ifndef QT_NO_HIGHDPISCALING class Q_GUI_EXPORT QHighDpiScaling { + Q_GADGET public: + enum class DpiAdjustmentPolicy { + Unset, + Enabled, + Disabled, + UpOnly + }; + Q_ENUM(DpiAdjustmentPolicy) + + QHighDpiScaling() = delete; + ~QHighDpiScaling() = delete; + QHighDpiScaling(const QHighDpiScaling &) = delete; + QHighDpiScaling &operator=(const QHighDpiScaling &) = delete; + QHighDpiScaling(QHighDpiScaling &&) = delete; + QHighDpiScaling &operator=(QHighDpiScaling &&) = delete; + static void initHighDpiScaling(); static void updateHighDpiScaling(); static void setGlobalFactor(qreal factor); - static void setScreenFactor(QScreen *window, qreal factor); + static void setScreenFactor(QScreen *screen, qreal factor); static bool isActive() { return m_active; } @@ -98,9 +114,12 @@ public: static QPoint mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen); static QPoint mapPositionToGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window); static QPoint mapPositionFromGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window); - static QDpi logicalDpi(); + static QDpi logicalDpi(const QScreen *screen); private: + static qreal rawScaleFactor(const QPlatformScreen *screen); + static qreal roundScaleFactor(qreal rawFactor); + static QDpi effectiveLogicalDpi(const QPlatformScreen *screen, qreal rawFactor, qreal roundedFactor); static qreal screenSubfactor(const QPlatformScreen *screen); static qreal m_factor; diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp index 9c5876550a..f3213bf5ea 100644 --- a/src/gui/kernel/qplatformscreen.cpp +++ b/src/gui/kernel/qplatformscreen.cpp @@ -193,6 +193,28 @@ QDpi QPlatformScreen::logicalDpi() const 25.4 * s.height() / ps.height()); } +// Helper function for accessing the platform screen logical dpi +// which accounts for QT_FONT_DPI. +QPair<qreal, qreal> QPlatformScreen::overrideDpi(const QPair<qreal, qreal> &in) +{ + static const int overrideDpi = qEnvironmentVariableIntValue("QT_FONT_DPI"); + return overrideDpi > 0 ? QDpi(overrideDpi, overrideDpi) : in; +} + +/*! + Reimplement to return the base logical DPI for the platform. This + DPI value should correspond to a standard-DPI (1x) display. The + default implementation returns 96. + + QtGui will use this value (together with logicalDpi) to compute + the scale factor when high-DPI scaling is enabled: + factor = logicalDPI / baseDPI +*/ +QDpi QPlatformScreen::logicalBaseDpi() const +{ + return QDpi(96, 96); +} + /*! Reimplement this function in subclass to return the device pixel ratio for the screen. This is the ratio between physical pixels and the diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h index b9ecc80320..d7378aed51 100644 --- a/src/gui/kernel/qplatformscreen.h +++ b/src/gui/kernel/qplatformscreen.h @@ -115,6 +115,7 @@ public: virtual QSizeF physicalSize() const; virtual QDpi logicalDpi() const; + virtual QDpi logicalBaseDpi() const; virtual qreal devicePixelRatio() const; virtual qreal pixelDensity() const; @@ -160,6 +161,8 @@ public: // The platform screen's geometry in device independent coordinates QRect deviceIndependentGeometry() const; + static QDpi overrideDpi(const QDpi &in); + protected: void resizeMaximizedWindows(); diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index c79f597414..7adf3db1b8 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -84,8 +84,11 @@ void QScreenPrivate::setPlatformScreen(QPlatformScreen *screen) platformScreen->d_func()->screen = q; orientation = platformScreen->orientation(); geometry = platformScreen->deviceIndependentGeometry(); - availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(), QHighDpiScaling::factor(platformScreen), geometry.topLeft()); - logicalDpi = platformScreen->logicalDpi(); + availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(), + QHighDpiScaling::factor(platformScreen), geometry.topLeft()); + + logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi()); + refreshRate = platformScreen->refreshRate(); // safeguard ourselves against buggy platform behavior... if (refreshRate < 1.0) @@ -285,7 +288,7 @@ qreal QScreen::logicalDotsPerInchX() const { Q_D(const QScreen); if (QHighDpiScaling::isActive()) - return QHighDpiScaling::logicalDpi().first; + return QHighDpiScaling::logicalDpi(this).first; return d->logicalDpi.first; } @@ -301,7 +304,7 @@ qreal QScreen::logicalDotsPerInchY() const { Q_D(const QScreen); if (QHighDpiScaling::isActive()) - return QHighDpiScaling::logicalDpi().second; + return QHighDpiScaling::logicalDpi(this).second; return d->logicalDpi.second; } @@ -320,7 +323,7 @@ qreal QScreen::logicalDotsPerInchY() const qreal QScreen::logicalDotsPerInch() const { Q_D(const QScreen); - QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi() : d->logicalDpi; + QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi(this) : d->logicalDpi; return (dpi.first + dpi.second) * qreal(0.5); } diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 4b8cb3646a..40a298226a 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -857,8 +857,8 @@ void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen, const Q void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY) { - QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e = - new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen, dpiX, dpiY); // ### tja + const QDpi effectiveDpi = QPlatformScreen::overrideDpi(QDpi{dpiX, dpiY}); + auto e = new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen, effectiveDpi.first, effectiveDpi.second); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index a24bdde04f..1076b21c1e 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -59,7 +59,8 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general") /*! \class QRhi - \inmodule QtRhi + \internal + \inmodule QtGui \brief Accelerated 2D/3D graphics API abstraction. @@ -604,7 +605,8 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general") /*! \class QRhiInitParams - \inmodule QtRhi + \internal + \inmodule QtGui \brief Base class for backend-specific initialization parameters. Contains fields that are relevant to all backends. @@ -612,7 +614,8 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general") /*! \class QRhiDepthStencilClearValue - \inmodule QtRhi + \internal + \inmodule QtGui \brief Specifies clear values for a depth or stencil buffer. */ @@ -679,7 +682,8 @@ QDebug operator<<(QDebug dbg, const QRhiDepthStencilClearValue &v) /*! \class QRhiViewport - \inmodule QtRhi + \internal + \inmodule QtGui \brief Specifies a viewport rectangle. Used with QRhiCommandBuffer::setViewport(). @@ -778,7 +782,8 @@ QDebug operator<<(QDebug dbg, const QRhiViewport &v) /*! \class QRhiScissor - \inmodule QtRhi + \internal + \inmodule QtGui \brief Specifies a scissor rectangle. Used with QRhiCommandBuffer::setScissor(). Setting a scissor rectangle is @@ -857,7 +862,8 @@ QDebug operator<<(QDebug dbg, const QRhiScissor &s) /*! \class QRhiVertexInputBinding - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes a vertex input binding. Specifies the stride (in bytes, must be a multiple of 4), the @@ -987,7 +993,8 @@ QDebug operator<<(QDebug dbg, const QRhiVertexInputBinding &b) /*! \class QRhiVertexInputAttribute - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes a single vertex input element. The members specify the binding number, location, format, and offset for a @@ -1140,7 +1147,8 @@ QDebug operator<<(QDebug dbg, const QRhiVertexInputAttribute &a) /*! \class QRhiVertexInputLayout - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes the layout of vertex inputs consumed by a vertex shader. The vertex input layout is defined by the collections of @@ -1199,7 +1207,8 @@ QDebug operator<<(QDebug dbg, const QRhiVertexInputLayout &v) /*! \class QRhiShaderStage - \inmodule QtRhi + \internal + \inmodule QtGui \brief Specifies the type and the shader code for a shader stage in the pipeline. */ @@ -1283,7 +1292,8 @@ QDebug operator<<(QDebug dbg, const QRhiShaderStage &s) /*! \class QRhiColorAttachment - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes the a single color attachment of a render target. A color attachment is either a QRhiTexture or a QRhiRenderBuffer. The @@ -1341,7 +1351,8 @@ QRhiColorAttachment::QRhiColorAttachment(QRhiRenderBuffer *renderBuffer) /*! \class QRhiTextureRenderTargetDescription - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes the color and depth or depth/stencil attachments of a render target. A texture render target has zero or more textures as color attachments, @@ -1396,7 +1407,8 @@ QRhiTextureRenderTargetDescription::QRhiTextureRenderTargetDescription(const QRh /*! \class QRhiTextureSubresourceUploadDescription - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes the source for one mip level in a layer in a texture upload operation. The source content is specified either as a QImage or as a raw blob. The @@ -1476,7 +1488,8 @@ QRhiTextureSubresourceUploadDescription::QRhiTextureSubresourceUploadDescription /*! \class QRhiTextureUploadEntry - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes one layer (face for cubemaps) in a texture upload operation. */ @@ -1504,7 +1517,8 @@ QRhiTextureUploadEntry::QRhiTextureUploadEntry(int layer, int level, /*! \class QRhiTextureUploadDescription - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes a texture upload operation. Used with QRhiResourceUpdateBatch::uploadTexture(). That function has two @@ -1609,7 +1623,8 @@ void QRhiTextureUploadDescription::append(const QRhiTextureUploadEntry &entry) /*! \class QRhiTextureCopyDescription - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes a texture-to-texture copy operation. An empty pixelSize() indicates that the entire subresource is to be copied. @@ -1632,7 +1647,8 @@ void QRhiTextureUploadDescription::append(const QRhiTextureUploadEntry &entry) /*! \class QRhiReadbackDescription - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes a readback (reading back texture contents from possibly GPU-only memory) operation. The source of the readback operation is either a QRhiTexture or the @@ -1678,7 +1694,8 @@ QRhiReadbackDescription::QRhiReadbackDescription(QRhiTexture *texture) /*! \class QRhiReadbackResult - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes the results of a potentially asynchronous readback operation. When \l completed is set, the function is invoked when the \l data is @@ -1688,13 +1705,15 @@ QRhiReadbackDescription::QRhiReadbackDescription(QRhiTexture *texture) /*! \class QRhiNativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Base class for classes exposing backend-specific collections of native resource objects. */ /*! \class QRhiResource - \inmodule QtRhi + \internal + \inmodule QtGui \brief Base class for classes encapsulating native resource objects. */ @@ -1813,7 +1832,8 @@ quint64 QRhiResource::globalResourceId() const /*! \class QRhiBuffer - \inmodule QtRhi + \internal + \inmodule QtGui \brief Vertex, index, or uniform (constant) buffer resource. */ @@ -1914,7 +1934,8 @@ QRhiResource::Type QRhiBuffer::resourceType() const /*! \class QRhiRenderBuffer - \inmodule QtRhi + \internal + \inmodule QtGui \brief Renderbuffer resource. Renderbuffers cannot be sampled or read but have some benefits over @@ -1990,7 +2011,8 @@ QRhiResource::Type QRhiRenderBuffer::resourceType() const /*! \class QRhiTexture - \inmodule QtRhi + \internal + \inmodule QtGui \brief Texture resource. */ @@ -2158,7 +2180,8 @@ bool QRhiTexture::buildFrom(const QRhiNativeHandles *src) /*! \class QRhiSampler - \inmodule QtRhi + \internal + \inmodule QtGui \brief Sampler resource. */ @@ -2220,7 +2243,8 @@ QRhiResource::Type QRhiSampler::resourceType() const /*! \class QRhiRenderPassDescriptor - \inmodule QtRhi + \internal + \inmodule QtGui \brief Render pass resource. */ @@ -2242,7 +2266,8 @@ QRhiResource::Type QRhiRenderPassDescriptor::resourceType() const /*! \class QRhiRenderTarget - \inmodule QtRhi + \internal + \inmodule QtGui \brief Represents an onscreen (swapchain) or offscreen (texture) render target. */ @@ -2279,7 +2304,8 @@ QRhiResource::Type QRhiRenderTarget::resourceType() const /*! \class QRhiTextureRenderTarget - \inmodule QtRhi + \internal + \inmodule QtGui \brief Texture render target resource. A texture render target allows rendering into one or more textures, @@ -2396,7 +2422,8 @@ QRhiResource::Type QRhiTextureRenderTarget::resourceType() const /*! \class QRhiShaderResourceBindings - \inmodule QtRhi + \internal + \inmodule QtGui \brief Encapsulates resources for making buffer, texture, sampler resources visible to shaders. A QRhiShaderResourceBindings is a collection of QRhiShaderResourceBinding @@ -2513,7 +2540,8 @@ bool QRhiShaderResourceBindings::isLayoutCompatible(const QRhiShaderResourceBind /*! \class QRhiShaderResourceBinding - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes the shader resource for a single binding point. A QRhiShaderResourceBinding cannot be constructed directly. Instead, use @@ -3038,7 +3066,8 @@ QDebug operator<<(QDebug dbg, const QRhiShaderResourceBindings &srb) /*! \class QRhiGraphicsPipeline - \inmodule QtRhi + \internal + \inmodule QtGui \brief Graphics pipeline state resource. \note Setting the shader resource bindings is mandatory. The referenced @@ -3193,7 +3222,8 @@ QDebug operator<<(QDebug dbg, const QRhiShaderResourceBindings &srb) /*! \class QRhiGraphicsPipeline::TargetBlend - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes the blend state for one color attachment. Defaults to color write enabled, blending disabled. The blend values are @@ -3203,7 +3233,8 @@ QDebug operator<<(QDebug dbg, const QRhiShaderResourceBindings &srb) /*! \class QRhiGraphicsPipeline::StencilOpState - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes the stencil operation state. */ @@ -3258,7 +3289,8 @@ QRhiResource::Type QRhiGraphicsPipeline::resourceType() const /*! \class QRhiSwapChain - \inmodule QtRhi + \internal + \inmodule QtGui \brief Swapchain resource. A swapchain enables presenting rendering results to a surface. A swapchain @@ -3520,7 +3552,8 @@ QRhiResource::Type QRhiSwapChain::resourceType() const /*! \class QRhiComputePipeline - \inmodule QtRhi + \internal + \inmodule QtGui \brief Compute pipeline state resource. \note Setting the shader resource bindings is mandatory. The referenced @@ -3548,7 +3581,8 @@ QRhiComputePipeline::QRhiComputePipeline(QRhiImplementation *rhi) /*! \class QRhiCommandBuffer - \inmodule QtRhi + \internal + \inmodule QtGui \brief Command buffer resource. Not creatable by applications at the moment. The only ways to obtain a @@ -4008,7 +4042,8 @@ void QRhi::runCleanup() /*! \class QRhiResourceUpdateBatch - \inmodule QtRhi + \internal + \inmodule QtGui \brief Records upload and copy type of operations. With QRhi it is no longer possible to perform copy type of operations at diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index ddcc5179d2..9b411c5021 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -58,7 +58,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiD3D11InitParams - \inmodule QtRhi + \internal + \inmodule QtGui \brief Direct3D 11 specific initialization parameters. A D3D11-based QRhi needs no special parameters for initialization. If @@ -97,7 +98,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiD3D11NativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Holds the D3D device and device context used by the QRhi. \note The class uses \c{void *} as the type since including the COM-based @@ -107,7 +109,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiD3D11TextureNativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Holds the D3D texture object that is backing a QRhiTexture instance. \note The class uses \c{void *} as the type since including the COM-based diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 4ad68d6cd0..26e7fa2759 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -58,7 +58,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiGles2InitParams - \inmodule QtRhi + \internal + \inmodule QtGui \brief OpenGL specific initialization parameters. An OpenGL-based QRhi needs an already created QOffscreenSurface at minimum. @@ -130,13 +131,15 @@ QT_BEGIN_NAMESPACE /*! \class QRhiGles2NativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Holds the OpenGL context used by the QRhi. */ /*! \class QRhiGles2TextureNativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Holds the OpenGL texture object that is backing a QRhiTexture instance. */ diff --git a/src/gui/rhi/qrhinull.cpp b/src/gui/rhi/qrhinull.cpp index 1314e53893..048dce0dde 100644 --- a/src/gui/rhi/qrhinull.cpp +++ b/src/gui/rhi/qrhinull.cpp @@ -41,7 +41,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiNullInitParams - \inmodule QtRhi + \internal + \inmodule QtGui \brief Null backend specific initialization parameters. A Null QRhi needs no special parameters for initialization. @@ -60,13 +61,15 @@ QT_BEGIN_NAMESPACE /*! \class QRhiNullNativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Empty. */ /*! \class QRhiNullTextureNativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Empty. */ diff --git a/src/gui/rhi/qrhiprofiler.cpp b/src/gui/rhi/qrhiprofiler.cpp index 15e3007d49..e74e446a1c 100644 --- a/src/gui/rhi/qrhiprofiler.cpp +++ b/src/gui/rhi/qrhiprofiler.cpp @@ -41,7 +41,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiProfiler - \inmodule QtRhi + \internal + \inmodule QtGui \brief Collects resource and timing information from an active QRhi. @@ -142,7 +143,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiProfiler::CpuTime - \inmodule QtRhi + \internal + \inmodule QtGui \brief Contains CPU-side frame timings. Once sufficient number of frames have been rendered, the minimum, maximum, @@ -155,7 +157,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiProfiler::GpuTime - \inmodule QtRhi + \internal + \inmodule QtGui \brief Contains GPU-side frame timings. Once sufficient number of frames have been rendered, the minimum, maximum, diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 61a1595a50..321fd92f88 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -62,7 +62,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiVulkanInitParams - \inmodule QtRhi + \internal + \inmodule QtGui \brief Vulkan specific initialization parameters. A Vulkan-based QRhi needs at minimum a valid QVulkanInstance. It is up to @@ -146,7 +147,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiVulkanNativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Collects device, queue, and other Vulkan objects that are used by the QRhi. \note Ownership of the Vulkan objects is never transferred. @@ -154,7 +156,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiVulkanTextureNativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Holds the Vulkan image object that is backing a QRhiTexture. Importing and exporting Vulkan image objects that back a QRhiTexture when @@ -168,7 +171,8 @@ QT_BEGIN_NAMESPACE /*! \class QRhiVulkanCommandBufferNativeHandles - \inmodule QtRhi + \internal + \inmodule QtGui \brief Holds the Vulkan command buffer object that is backing a QRhiCommandBuffer. \note The Vulkan command buffer object is only guaranteed to be valid, and diff --git a/src/gui/rhi/qshader.cpp b/src/gui/rhi/qshader.cpp index 9098180f69..72ce53c87a 100644 --- a/src/gui/rhi/qshader.cpp +++ b/src/gui/rhi/qshader.cpp @@ -42,7 +42,8 @@ QT_BEGIN_NAMESPACE /*! \class QShader - \inmodule QtRhi + \internal + \inmodule QtGui \brief Contains multiple versions of a shader translated to multiple shading languages, together with reflection metadata. @@ -134,7 +135,8 @@ QT_BEGIN_NAMESPACE /*! \class QShaderVersion - \inmodule QtRhi + \internal + \inmodule QtGui \brief Specifies the shading language version. @@ -171,7 +173,8 @@ QT_BEGIN_NAMESPACE /*! \class QShaderKey - \inmodule QtRhi + \internal + \inmodule QtGui \brief Specifies the shading language, the version with flags, and the variant. @@ -202,7 +205,8 @@ QT_BEGIN_NAMESPACE /*! \class QShaderCode - \inmodule QtRhi + \internal + \inmodule QtGui \brief Contains source or binary code for a shader and additional metadata. diff --git a/src/gui/rhi/qshaderdescription.cpp b/src/gui/rhi/qshaderdescription.cpp index 77aceaddba..c38a83c497 100644 --- a/src/gui/rhi/qshaderdescription.cpp +++ b/src/gui/rhi/qshaderdescription.cpp @@ -43,7 +43,8 @@ QT_BEGIN_NAMESPACE /*! \class QShaderDescription - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes the interface of a shader. @@ -231,21 +232,24 @@ QT_BEGIN_NAMESPACE /*! \class QShaderDescription::InOutVariable - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes an input or output variable in the shader. */ /*! \class QShaderDescription::BlockVariable - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes a member of a uniform or push constant block. */ /*! \class QShaderDescription::UniformBlock - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes a uniform block. @@ -257,14 +261,16 @@ QT_BEGIN_NAMESPACE /*! \class QShaderDescription::PushConstantBlock - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes a push constant block. */ /*! \class QShaderDescription::StorageBlock - \inmodule QtRhi + \internal + \inmodule QtGui \brief Describes a shader storage block. */ diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index 7096bba160..d3e4f11e8c 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -1034,8 +1034,15 @@ int QFontMetrics::lineWidth() const return qRound(engine->lineThickness()); } +/*! + \since 5.14 - + Returns the font DPI. +*/ +qreal QFontMetrics::fontDpi() const +{ + return d->dpi; +} /***************************************************************************** QFontMetricsF member functions @@ -1909,4 +1916,14 @@ qreal QFontMetricsF::lineWidth() const return engine->lineThickness().toReal(); } +/*! + \since 5.14 + + Returns the font DPI. +*/ +qreal QFontMetricsF::fontDpi() const +{ + return d->dpi; +} + QT_END_NAMESPACE diff --git a/src/gui/text/qfontmetrics.h b/src/gui/text/qfontmetrics.h index 02ff335e68..e92a1514a1 100644 --- a/src/gui/text/qfontmetrics.h +++ b/src/gui/text/qfontmetrics.h @@ -135,6 +135,8 @@ public: int strikeOutPos() const; int lineWidth() const; + qreal fontDpi() const; + bool operator==(const QFontMetrics &other) const; inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); } @@ -216,6 +218,8 @@ public: qreal strikeOutPos() const; qreal lineWidth() const; + qreal fontDpi() const; + bool operator==(const QFontMetricsF &other) const; inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); } diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index 778493d4bc..723e5c907c 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -610,7 +610,7 @@ bool QTextHtmlImporter::appendNodeText() || ch == QChar::ParagraphSeparator) { if (!textToInsert.isEmpty()) { - if (wsm == QTextHtmlParserNode::WhiteSpacePreLine && textToInsert.at(textToInsert.length() - 1) == QChar(' ')) + if (wsm == QTextHtmlParserNode::WhiteSpacePreLine && textToInsert.at(textToInsert.length() - 1) == QLatin1Char(' ')) textToInsert = textToInsert.chopped(1); cursor.insertText(textToInsert, format); textToInsert.clear(); |