From d86192e5ba7911407881f5079c4486c1fb084dc6 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Sat, 26 Oct 2019 13:57:05 +0200 Subject: QFontDatabase: improve logging output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Log the style name, add more descriptions of what's being logged. Before: Adding font "Lucida Grande" 50 QFont::StyleNormal 0 aa true fixed false After: Adding font family "Lucida Grande" stylename "Regular" weight 50 style QFont::StyleNormal pixelSize 0 antialiased true fixed false Change-Id: I138f1b9f41dc41c528c830d81f8018fc16561631 Reviewed-by: Tor Arne Vestbø --- src/gui/text/qfontdatabase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index fe7dd80e44..67783e5b42 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -733,7 +733,8 @@ void qt_registerFont(const QString &familyName, const QString &stylename, const QSupportedWritingSystems &writingSystems, void *handle) { QFontDatabasePrivate *d = privateDb(); - qCDebug(lcFontDb) << "Adding font" << familyName << weight << style << pixelSize << "aa" << antialiased << "fixed" << fixedPitch; + qCDebug(lcFontDb) << "Adding font: familyName" << familyName << "stylename" << stylename << "weight" << weight + << "style" << style << "pixelSize" << pixelSize << "antialiased" << antialiased << "fixed" << fixedPitch; QtFontStyle::Key styleKey; styleKey.style = style; styleKey.weight = weight; -- cgit v1.2.3 From 0fb995492d377fde96b453680f3604f5991171c0 Mon Sep 17 00:00:00 2001 From: David Faure Date: Sun, 27 Oct 2019 09:33:54 +0100 Subject: QImageIOHandler: remove #if around virtual method name() It makes -DQT_DISABLE_DEPRECATED_BEFORE=0x050d00 (in an application) trigger a binary incompatible change and crash. Change-Id: I9b9783d134821697180dc3fd8f2f69a51ddb7ac6 Reviewed-by: Christian Ehrlicher Reviewed-by: Edward Welbourne --- src/gui/image/qimageiohandler.cpp | 4 +--- src/gui/image/qimageiohandler.h | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/image/qimageiohandler.cpp b/src/gui/image/qimageiohandler.cpp index 0e7b541cf2..a4f927a462 100644 --- a/src/gui/image/qimageiohandler.cpp +++ b/src/gui/image/qimageiohandler.cpp @@ -416,18 +416,16 @@ QByteArray QImageIOHandler::format() const \sa read(), QIODevice::peek() */ -#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete Use format() instead. */ -QByteArray QImageIOHandler::name() const +QByteArray QImageIOHandler::name() const // ### Qt6: remove { return format(); } -#endif /*! Writes the image \a image to the assigned device. Returns \c true on diff --git a/src/gui/image/qimageiohandler.h b/src/gui/image/qimageiohandler.h index c20b84afbb..a4acf9dfe0 100644 --- a/src/gui/image/qimageiohandler.h +++ b/src/gui/image/qimageiohandler.h @@ -69,10 +69,8 @@ public: void setFormat(const QByteArray &format) const; QByteArray format() const; -#if QT_DEPRECATED_SINCE(5, 13) QT_DEPRECATED_X("Use QImageIOHandler::format() instead") virtual QByteArray name() const; -#endif virtual bool canRead() const = 0; virtual bool read(QImage *image) = 0; -- cgit v1.2.3 From b1004c7d0a5d7abbacd687fd41a5b2683e62b27d Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 29 Oct 2019 09:44:50 +0100 Subject: If only family is set, prefer that in the families list after resolving If a font with only a family set is resolved with one that has been setup with setFamilies() then the family needs to be prepended to the families list after resolving. This is so that the font still prefers the one set as just a family with no famillies set. This also amends the QFontDialog test to account for this too. [ChangeLog][QtGui][Text] Resolving a font that just has a family set with families set will prepend the family to the families so that it is still the first preference for the font. Task-number: QTBUG-46322 Change-Id: Icc4005732f95b2b4c684e592b06b31e133270e44 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qfont.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 84c5be60b1..f5dbec3a3e 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -271,8 +271,13 @@ void QFontPrivate::resolve(uint mask, const QFontPrivate *other) if (! (mask & QFont::FamilyResolved)) request.family = other->request.family; - if (!(mask & QFont::FamiliesResolved)) + if (!(mask & QFont::FamiliesResolved)) { request.families = other->request.families; + // Prepend the family explicitly set so it will be given + // preference in this case + if (mask & QFont::FamilyResolved) + request.families.prepend(request.family); + } if (! (mask & QFont::StyleNameResolved)) request.styleName = other->request.styleName; -- cgit v1.2.3 From 524ab7b5357e66b935a42956ec365a511e62e5ed Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 4 Oct 2019 22:06:41 +0200 Subject: Avoid crashing when the end of an empty markdown list is detected The markdown parser generates empty lists in some cases when a character that can be used as a bullet is found on a line by itself. cbEnterBlock() and cbLeaveBlock() are called symmetrically in such cases. QStack::pop() on an empty stack triggers an assert, so push and pop need to be done symmetrically too. But it's difficult to actually create the list as soon as the MD_BLOCK_UL or MD_BLOCK_OL callback occurs, without breaking the case fixed in 7224d0e427d71e559b928c44634839b4791c1416 (and probably other cases). That's because QTextCursor::insertList() creates a list item at the same time as it creates the list itself, and also inherits block formatting from the previous block. We now insert empty lists with empty items whenever the need for that is detected though, and there's a failsafe to prevent popping in case something still goes wrong with that logic. We aren't strict about reproducing the original markdown when regenerating it via toMarkdown(), but it's getting closer. Fixes: QTBUG-78870 Change-Id: Ided194ce7aec2710c60dbac42761ee4169ed9b78 Reviewed-by: Edward Welbourne Reviewed-by: Robert Loehning --- src/gui/text/qtextmarkdownimporter.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/gui') diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp index 87ade1f973..c2ad1e5612 100644 --- a/src/gui/text/qtextmarkdownimporter.cpp +++ b/src/gui/text/qtextmarkdownimporter.cpp @@ -216,6 +216,10 @@ int QTextMarkdownImporter::cbEnterBlock(int blockType, void *det) qCDebug(lcMD) << "LI"; } break; case MD_BLOCK_UL: { + if (m_needsInsertList) // list nested in an empty list + m_listStack.push(m_cursor->insertList(m_listFormat)); + else + m_needsInsertList = true; MD_BLOCK_UL_DETAIL *detail = static_cast(det); m_listFormat = QTextListFormat(); m_listFormat.setIndent(m_listStack.count() + 1); @@ -230,17 +234,19 @@ int QTextMarkdownImporter::cbEnterBlock(int blockType, void *det) m_listFormat.setStyle(QTextListFormat::ListDisc); break; } - qCDebug(lcMD, "UL %c level %d", detail->mark, m_listStack.count()); - m_needsInsertList = true; + qCDebug(lcMD, "UL %c level %d", detail->mark, m_listStack.count() + 1); } break; case MD_BLOCK_OL: { + if (m_needsInsertList) // list nested in an empty list + m_listStack.push(m_cursor->insertList(m_listFormat)); + else + m_needsInsertList = true; MD_BLOCK_OL_DETAIL *detail = static_cast(det); m_listFormat = QTextListFormat(); m_listFormat.setIndent(m_listStack.count() + 1); m_listFormat.setNumberSuffix(QChar::fromLatin1(detail->mark_delimiter)); m_listFormat.setStyle(QTextListFormat::ListDecimal); - qCDebug(lcMD, "OL xx%d level %d", detail->mark_delimiter, m_listStack.count()); - m_needsInsertList = true; + qCDebug(lcMD, "OL xx%d level %d", detail->mark_delimiter, m_listStack.count() + 1); } break; case MD_BLOCK_TD: { MD_BLOCK_TD_DETAIL *detail = static_cast(det); @@ -306,8 +312,14 @@ int QTextMarkdownImporter::cbLeaveBlock(int blockType, void *detail) break; case MD_BLOCK_UL: case MD_BLOCK_OL: - qCDebug(lcMD, "list at level %d ended", m_listStack.count()); - m_listStack.pop(); + if (Q_UNLIKELY(m_needsInsertList)) + m_listStack.push(m_cursor->createList(m_listFormat)); + if (Q_UNLIKELY(m_listStack.isEmpty())) { + qCWarning(lcMD, "list ended unexpectedly"); + } else { + qCDebug(lcMD, "list at level %d ended", m_listStack.count()); + m_listStack.pop(); + } break; case MD_BLOCK_TR: { // https://github.com/mity/md4c/issues/29 -- cgit v1.2.3 From d1c6f7e5a2e0ee6c50bbf0668e44200bd8469a09 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 14 Oct 2019 17:59:16 +0200 Subject: QTextMarkdownWriter: preserve empty lists You can save a "skeletal" document with list items to fill in later, the same as you can do in HTML or ODF format. Reading them back via QTextDocument::fromMarkdown() isn't always perfect though. Fixes: QTBUG-79217 Change-Id: Iacdb3e6792250ebdead05f314c9e3d00546eeb9f Reviewed-by: Shawn Rutledge --- src/gui/text/qtextmarkdownwriter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp index 764c64aead..c9a63920c3 100644 --- a/src/gui/text/qtextmarkdownwriter.cpp +++ b/src/gui/text/qtextmarkdownwriter.cpp @@ -173,7 +173,8 @@ void QTextMarkdownWriter::writeFrame(const QTextFrame *frame) if (lastWasList) m_stream << Newline; } - int endingCol = writeBlock(block, !table, table && tableRow == 0, nextIsDifferent); + int endingCol = writeBlock(block, !table, table && tableRow == 0, + nextIsDifferent && !block.textList()); m_doubleNewlineWritten = false; if (table) { QTextTableCell cell = table->cellAt(block.position()); -- cgit v1.2.3 From ed20f3209804d865804f9eb14c3fcfb4b7941140 Mon Sep 17 00:00:00 2001 From: Vitaly Fanaskov Date: Fri, 25 Oct 2019 14:47:15 +0200 Subject: QHighDpiScaling: fix potential null pointer dereference It's not guaranteed that QPlatformScreen::screen should always return a valid pointer. Furthermore, you can run into this situation with, for example, two screens setup. Task-number: QTBUG-53022 Change-Id: Ic23bb2c30b1245f98a793a44cc5e0b39f9afac4b Reviewed-by: Friedemann Kleint --- src/gui/kernel/qhighdpiscaling.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 76548d5d86..704dcee633 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -657,7 +657,8 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen) // 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 qScreen = screen->screen(); + auto byIndex = qScreen ? qScreen->property(scaleFactorProperty) : QVariant(); auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name()); if (byIndex.isValid()) { screenPropertyUsed = true; -- cgit v1.2.3 From 52a3f1b00cca13767eefabf61742d2d802c56511 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 6 Nov 2019 10:04:54 +0100 Subject: Fix accuracy of ARGB32->A2RGB30 conversions It was converted over ARGB32PM, when it should have been directly converted to not lose accuracy, instead there was an unnecessary direct ARGB32->RGB30 conversion, which was converted to the necessary type. This also improves the selection of conversion over ARGB32PM or RGBA64PM for ARGB32 and RGBA8888 by using 32-bit conversion when alpha is not relevant. Change-Id: I5990d8a23b2909d3910d8c1213fa46477742b052 Reviewed-by: Eirik Aavitsland --- src/gui/image/qimage.cpp | 25 ++----------- src/gui/image/qimage_conversions.cpp | 69 +++++++++++++++++++++--------------- src/gui/image/qimage_p.h | 23 ++++++++++++ 3 files changed, 67 insertions(+), 50 deletions(-) (limited to 'src/gui') diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 2779b97fbd..d8ed0829af 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -2060,27 +2060,6 @@ QImage::Format QImage::format() const \sa {Image Formats} */ -static bool highColorPrecision(QImage::Format format) -{ - // Formats with higher color precision than ARGB32_Premultiplied. - switch (format) { - case QImage::Format_ARGB32: - case QImage::Format_RGBA8888: - case QImage::Format_BGR30: - case QImage::Format_RGB30: - case QImage::Format_A2BGR30_Premultiplied: - case QImage::Format_A2RGB30_Premultiplied: - case QImage::Format_RGBX64: - case QImage::Format_RGBA64: - case QImage::Format_RGBA64_Premultiplied: - case QImage::Format_Grayscale16: - return true; - default: - break; - } - return false; -} - /*! \internal */ @@ -2092,9 +2071,11 @@ QImage QImage::convertToFormat_helper(Format format, Qt::ImageConversionFlags fl if (format == Format_Invalid || d->format == Format_Invalid) return QImage(); + const QPixelLayout *destLayout = &qPixelLayouts[format]; Image_Converter converter = qimage_converter_map[d->format][format]; if (!converter && format > QImage::Format_Indexed8 && d->format > QImage::Format_Indexed8) { - if (highColorPrecision(format) && highColorPrecision(d->format)) { + if (qt_highColorPrecision(d->format, !destLayout->hasAlphaChannel) + && qt_highColorPrecision(format, !hasAlphaChannel())) { converter = convert_generic_to_rgb64; } else converter = convert_generic; diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp index 9e1df7058c..97a5f89e68 100644 --- a/src/gui/image/qimage_conversions.cpp +++ b/src/gui/image/qimage_conversions.cpp @@ -260,10 +260,17 @@ bool convert_generic_inplace(QImageData *data, QImage::Format dst_format, Qt::Im if (data->depth != qt_depthForFormat(dst_format)) return false; - uint buf[BufferSize]; - uint *buffer = buf; const QPixelLayout *srcLayout = &qPixelLayouts[data->format]; const QPixelLayout *destLayout = &qPixelLayouts[dst_format]; + + // The precision here is only ARGB32PM so don't convert between higher accuracy + // formats (assert instead when we have a convert_generic_over_rgb64_inplace). + if (qt_highColorPrecision(data->format, !destLayout->hasAlphaChannel) + && qt_highColorPrecision(dst_format, !srcLayout->hasAlphaChannel)) + return false; + + uint buf[BufferSize]; + uint *buffer = buf; uchar *srcData = data->data; Q_ASSERT(srcLayout->bpp == destLayout->bpp); @@ -626,12 +633,13 @@ static bool convert_rgbswap_generic_inplace(QImageData *data, Qt::ImageConversio } template -static void convert_RGB_to_RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) +static void convert_ARGB_to_A2RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) { - Q_ASSERT(RGBA || src->format == QImage::Format_RGB32 || src->format == QImage::Format_ARGB32); - Q_ASSERT(!RGBA || src->format == QImage::Format_RGBX8888 || src->format == QImage::Format_RGBA8888); - Q_ASSERT(dest->format == QImage::Format_BGR30 || dest->format == QImage::Format_RGB30); + Q_ASSERT(RGBA || src->format == QImage::Format_ARGB32); + Q_ASSERT(!RGBA || src->format == QImage::Format_RGBA8888); + Q_ASSERT(dest->format == QImage::Format_A2BGR30_Premultiplied + || dest->format == QImage::Format_A2RGB30_Premultiplied); Q_ASSERT(src->width == dest->width); Q_ASSERT(src->height == dest->height); @@ -646,7 +654,9 @@ static void convert_RGB_to_RGB30(QImageData *dest, const QImageData *src, Qt::Im QRgb c = *src_data; if (RGBA) c = RGBA2ARGB(c); - *dest_data = qConvertRgb32ToRgb30(c); + const uint alpha = (qAlpha(c) >> 6) * 85; + c = BYTE_MUL(c, alpha); + *dest_data = (qConvertRgb32ToRgb30(c) & 0x3fffffff) | (alpha << 30); ++src_data; ++dest_data; } @@ -656,10 +666,10 @@ static void convert_RGB_to_RGB30(QImageData *dest, const QImageData *src, Qt::Im } template -static bool convert_RGB_to_RGB30_inplace(QImageData *data, Qt::ImageConversionFlags) +static bool convert_ARGB_to_A2RGB30_inplace(QImageData *data, Qt::ImageConversionFlags) { - Q_ASSERT(RGBA || (data->format == QImage::Format_RGB32 || data->format == QImage::Format_ARGB32)); - Q_ASSERT(!RGBA || (data->format == QImage::Format_RGBX8888 || data->format == QImage::Format_RGBA8888)); + Q_ASSERT(RGBA || data->format == QImage::Format_ARGB32); + Q_ASSERT(!RGBA || data->format == QImage::Format_RGBA8888); const int pad = (data->bytes_per_line >> 2) - data->width; QRgb *rgb_data = (QRgb *) data->data; @@ -670,13 +680,16 @@ static bool convert_RGB_to_RGB30_inplace(QImageData *data, Qt::ImageConversionFl QRgb c = *rgb_data; if (RGBA) c = RGBA2ARGB(c); - *rgb_data = qConvertRgb32ToRgb30(c); + const uint alpha = (qAlpha(c) >> 6) * 85; + c = BYTE_MUL(c, alpha); + *rgb_data = (qConvertRgb32ToRgb30(c) & 0x3fffffff) | (alpha << 30); ++rgb_data; } rgb_data += pad; } - data->format = (PixelOrder == PixelOrderRGB) ? QImage::Format_RGB30 : QImage::Format_BGR30; + data->format = (PixelOrder == PixelOrderRGB) ? QImage::Format_A2RGB30_Premultiplied + : QImage::Format_A2BGR30_Premultiplied; return true; } @@ -2353,9 +2366,9 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat 0, 0, 0, - convert_RGB_to_RGB30, 0, - convert_RGB_to_RGB30, + 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 @@ -2381,10 +2394,10 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat convert_ARGB_to_RGBx, convert_ARGB_to_RGBA, 0, - convert_RGB_to_RGB30, 0, - convert_RGB_to_RGB30, + convert_ARGB_to_A2RGB30, 0, + convert_ARGB_to_A2RGB30, 0, 0, 0, convert_ARGB32_to_RGBA64, @@ -2634,9 +2647,9 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat 0, convert_passthrough, convert_passthrough, - convert_RGB_to_RGB30, 0, - convert_RGB_to_RGB30, + 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 @@ -2661,10 +2674,10 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat mask_alpha_converter_RGBx, 0, 0, - convert_RGB_to_RGB30, 0, - convert_RGB_to_RGB30, + convert_ARGB_to_A2RGB30, 0, + convert_ARGB_to_A2RGB30, 0, 0, 0, convert_ARGB32_to_RGBA64, @@ -3017,9 +3030,9 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma 0, 0, 0, - convert_RGB_to_RGB30_inplace, 0, - convert_RGB_to_RGB30_inplace, + 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 @@ -3044,10 +3057,10 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma convert_ARGB_to_RGBA_inplace, convert_ARGB_to_RGBA_inplace, 0, - convert_RGB_to_RGB30_inplace, 0, - convert_RGB_to_RGB30_inplace, + convert_ARGB_to_A2RGB30_inplace, 0, + convert_ARGB_to_A2RGB30_inplace, 0, 0, 0, 0, 0, 0, 0 }, // Format_ARGB32 @@ -3123,9 +3136,9 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma 0, convert_passthrough_inplace, convert_passthrough_inplace, - convert_RGB_to_RGB30_inplace, 0, - convert_RGB_to_RGB30_inplace, + 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 @@ -3150,10 +3163,10 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma mask_alpha_converter_rgbx_inplace, 0, 0, - convert_RGB_to_RGB30_inplace, 0, - convert_RGB_to_RGB30_inplace, + convert_ARGB_to_A2RGB30_inplace, 0, + convert_ARGB_to_A2RGB30_inplace, 0, 0, 0, 0, 0, 0, 0 }, // Format_RGBA8888 diff --git a/src/gui/image/qimage_p.h b/src/gui/image/qimage_p.h index 9e2d9c86bb..0930955f5a 100644 --- a/src/gui/image/qimage_p.h +++ b/src/gui/image/qimage_p.h @@ -276,6 +276,29 @@ inline QImage::Format qt_alphaVersion(QImage::Format format) return QImage::Format_ARGB32_Premultiplied; } +inline bool qt_highColorPrecision(QImage::Format format, bool opaque = false) +{ + // Formats with higher color precision than ARGB32_Premultiplied. + switch (format) { + case QImage::Format_ARGB32: + case QImage::Format_RGBA8888: + return !opaque; + case QImage::Format_BGR30: + case QImage::Format_RGB30: + case QImage::Format_A2BGR30_Premultiplied: + case QImage::Format_A2RGB30_Premultiplied: + case QImage::Format_RGBX64: + case QImage::Format_RGBA64: + case QImage::Format_RGBA64_Premultiplied: + case QImage::Format_Grayscale16: + return true; + default: + break; + } + return false; +} + + inline QImage::Format qt_maybeAlphaVersionWithSameDepth(QImage::Format format) { const QImage::Format toFormat = qt_alphaVersion(format); -- cgit v1.2.3 From a866055d18b2c2efc0f3cf5307d8eac78cce26eb Mon Sep 17 00:00:00 2001 From: Vitaly Fanaskov Date: Wed, 6 Nov 2019 21:37:48 +0100 Subject: QHighDpiScaling: impove readability of screenSubfactor method Task-number: QTBUG-53022 Change-Id: Idae4379dd78d3125c375fad37a5a3af5bbcdc51e Reviewed-by: Friedemann Kleint --- src/gui/kernel/qhighdpiscaling.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/gui') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 704dcee633..0782a49481 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -644,7 +644,7 @@ QPoint QHighDpiScaling::mapPositionFromGlobal(const QPoint &pos, const QPoint &w qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen) { - qreal factor = qreal(1.0); + auto factor = qreal(1.0); if (!screen) return factor; @@ -657,15 +657,16 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen) // 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. - auto qScreen = screen->screen(); - auto byIndex = qScreen ? qScreen->property(scaleFactorProperty) : QVariant(); - auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name()); - if (byIndex.isValid()) { - screenPropertyUsed = true; - factor = byIndex.toReal(); - } else if (byNameIt != qNamedScreenScaleFactors()->cend()) { - screenPropertyUsed = true; - factor = *byNameIt; + if (auto qScreen = screen->screen()) { + auto screenFactor = qScreen->property(scaleFactorProperty).toReal(&screenPropertyUsed); + if (screenPropertyUsed) + factor = screenFactor; + } + + if (!screenPropertyUsed) { + auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name()); + if ((screenPropertyUsed = byNameIt != qNamedScreenScaleFactors()->cend())) + factor = *byNameIt; } } -- cgit v1.2.3