From 062713e8ccd22f8725129a5493a53a8225b8c19d Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 13 Mar 2020 13:32:22 +0100 Subject: [PATCH] avoid using deprecated calls --- examples/automotive/SpeedometerSkinlet.cpp | 5 +++-- examples/listbox/main.cpp | 5 +++-- features/qskconfig.pri | 2 ++ playground/grids/main.cpp | 6 +++--- playground/inputpanel/main.cpp | 3 ++- src/common/QskFunctions.cpp | 25 +++++++++++++++------- src/common/QskFunctions.h | 6 ++++++ src/controls/QskSimpleListBox.cpp | 9 ++++---- src/graphic/QskGraphic.cpp | 16 +------------- 9 files changed, 41 insertions(+), 36 deletions(-) diff --git a/examples/automotive/SpeedometerSkinlet.cpp b/examples/automotive/SpeedometerSkinlet.cpp index 4ed99c3a..8f865475 100644 --- a/examples/automotive/SpeedometerSkinlet.cpp +++ b/examples/automotive/SpeedometerSkinlet.cpp @@ -12,7 +12,8 @@ #include #include #include -#include // ### remove +#include +#include #include #include @@ -174,7 +175,7 @@ QSGNode* SpeedometerSkinlet::updateLabelsNode( const Speedometer* speedometer, Q { const QString& text = labels.at( i ); - auto w = fontMetrics.width( text ); + auto w = qskHorizontalAdvance( fontMetrics, text ); auto h = fontMetrics.height(); auto adjustX = ( -0.5 * cosine - 0.5 ) * w; auto adjustY = ( -0.5 * sine - 0.5 ) * h; diff --git a/examples/listbox/main.cpp b/examples/listbox/main.cpp index c4a63dab..c42d184b 100644 --- a/examples/listbox/main.cpp +++ b/examples/listbox/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -46,8 +47,8 @@ class ListBox : public QskSimpleListBox // can prevent the list box from having to find it out // the expensive way. - const QFontMetricsF fm( effectiveFont( Cell ) ); - setColumnWidthHint( 0, fm.width( entries.last() ) ); + const qreal maxWidth = qskHorizontalAdvance( effectiveFont( Cell ), entries.last() ); + setColumnWidthHint( 0, maxWidth ); append( entries ); } diff --git a/features/qskconfig.pri b/features/qskconfig.pri index 89c38be5..8f08767a 100644 --- a/features/qskconfig.pri +++ b/features/qskconfig.pri @@ -166,3 +166,5 @@ debug { # Help out Qt Creator ide: DEFINES += QT_IDE + +# DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 diff --git a/playground/grids/main.cpp b/playground/grids/main.cpp index 74cd7edd..ab4e613e 100644 --- a/playground/grids/main.cpp +++ b/playground/grids/main.cpp @@ -6,6 +6,8 @@ #include "TestBox.h" #include +#include + #include #include #include @@ -367,9 +369,7 @@ class MainWidget : public QWidget const auto r = contentsRect(); const int spacing = 5; - auto fm = QFontMetricsF( m_listBox->font() ); - - const int w1 = fm.width( "Test 100" ) + 20; + const int w1 = qskHorizontalAdvance( m_listBox->font(), "Test 100" ) + 20; const int w2 = r.width() - w1 - spacing; m_listBox->setGeometry( r.left(), r.top(), w1, r.height() ); diff --git a/playground/inputpanel/main.cpp b/playground/inputpanel/main.cpp index faf56fe2..a64e58d5 100644 --- a/playground/inputpanel/main.cpp +++ b/playground/inputpanel/main.cpp @@ -16,6 +16,7 @@ #include #include +#include #include @@ -202,7 +203,7 @@ class LocaleListView final : public QskListView const QFontMetricsF fm( effectiveFont( Text ) ); for ( const auto& entry : m_values ) - m_maxWidth = qMax( m_maxWidth, fm.width( entry.first ) ); + m_maxWidth = qMax( m_maxWidth, qskHorizontalAdvance( fm, entry.first ) ); const QMarginsF padding = marginsHint( Cell | Padding ); m_maxWidth += padding.left() + padding.right(); diff --git a/src/common/QskFunctions.cpp b/src/common/QskFunctions.cpp index 9cb22b1f..559544ef 100644 --- a/src/common/QskFunctions.cpp +++ b/src/common/QskFunctions.cpp @@ -3,8 +3,11 @@ #include #include #include +#include +#include QSK_QT_PRIVATE_BEGIN +#include #include QSK_QT_PRIVATE_END @@ -146,6 +149,20 @@ qreal qskDpiScaled( qreal value ) return value * factor; } +qreal qskHorizontalAdvance( const QFont& font, const QString& text ) +{ + return qskHorizontalAdvance( QFontMetricsF( font ), text ); +} + +qreal qskHorizontalAdvance( const QFontMetricsF& fontMetrics, const QString& text ) +{ +#if QT_VERSION >= QT_VERSION_CHECK( 5, 11, 0 ) + return fontMetrics.horizontalAdvance( text ); +#else + return fontMetrics.width( text ); +#endif +} + bool qskHasPlatformWindowManagement() { if ( auto platform = QGuiApplicationPrivate::platformIntegration() ) @@ -162,17 +179,9 @@ QRect qskPlatformScreenGeometry( const QScreen* screen ) return screen->handle()->geometry(); } -#if 0 - -QSK_QT_PRIVATE_BEGIN -#include -QSK_QT_PRIVATE_END - qreal qskGlobalScaleFactor() { // The value of QT_SCALE_FACTOR const QScreen* noScreen = nullptr; return QHighDpiScaling::factor( noScreen ); } - -#endif diff --git a/src/common/QskFunctions.h b/src/common/QskFunctions.h index aac6a956..6f509a75 100644 --- a/src/common/QskFunctions.h +++ b/src/common/QskFunctions.h @@ -12,6 +12,9 @@ #include class QScreen; +class QFont; +class QFontMetricsF; +class QString; QSK_EXPORT qreal qskDpiScaled( qreal value ); QSK_EXPORT bool qskHasPlatformWindowManagement(); @@ -29,6 +32,9 @@ QSK_EXPORT QRectF qskInnerRectF( const QRectF& rect ); QSK_EXPORT QRectF qskValidOrEmptyInnerRect( const QRectF& rect, const QMarginsF& margins ); +QSK_EXPORT qreal qskHorizontalAdvance( const QFont&, const QString& ); +QSK_EXPORT qreal qskHorizontalAdvance( const QFontMetricsF&, const QString& ); + inline bool qskFuzzyCompare( qreal value1, qreal value2 ) { if ( qFuzzyIsNull( value1 ) ) diff --git a/src/controls/QskSimpleListBox.cpp b/src/controls/QskSimpleListBox.cpp index ae6a5b5d..5d6c7e3e 100644 --- a/src/controls/QskSimpleListBox.cpp +++ b/src/controls/QskSimpleListBox.cpp @@ -5,6 +5,7 @@ #include "QskSimpleListBox.h" #include "QskAspect.h" +#include "QskFunctions.h" #include @@ -16,7 +17,7 @@ static inline qreal qskMaxWidth( qreal max = 0.0; for ( int i = 0; i < list.size(); i++ ) { - const qreal w = fm.width( list[ i ] ); + const qreal w = qskHorizontalAdvance( fm, list[ i ] ); if ( w > max ) max = w; } @@ -146,7 +147,7 @@ void QskSimpleListBox::insert( const QString& text, int index ) { if ( m_data->columnWidthHint <= 0.0 ) { - const auto w = QFontMetricsF( effectiveFont( Cell ) ).width( text ); + const auto w = qskHorizontalAdvance( effectiveFont( Cell ), text ); if ( w > m_data->maxTextWidth ) m_data->maxTextWidth = w; } @@ -168,9 +169,7 @@ void QskSimpleListBox::removeAt( int index ) if ( m_data->columnWidthHint <= 0.0 ) { - const QFontMetricsF fm( effectiveFont( Cell ) ); - const auto w = fm.width( entries[ index ] ); - + const auto w = qskHorizontalAdvance( effectiveFont( Cell ), entries[ index ] ); if ( w >= m_data->maxTextWidth ) m_data->maxTextWidth = qskMaxWidth( effectiveFont( Text ), entries ); } diff --git a/src/graphic/QskGraphic.cpp b/src/graphic/QskGraphic.cpp index 3374bea7..30c62fcf 100644 --- a/src/graphic/QskGraphic.cpp +++ b/src/graphic/QskGraphic.cpp @@ -35,12 +35,6 @@ static bool qskHasScalablePen( const QPainter* painter ) if ( pen.style() != Qt::NoPen && pen.brush().style() != Qt::NoBrush ) { scalablePen = !pen.isCosmetic(); - if ( !scalablePen && pen.widthF() == 0.0 ) - { - const QPainter::RenderHints hints = painter->renderHints(); - if ( hints.testFlag( QPainter::NonCosmeticDefaultPen ) ) - scalablePen = true; - } } return scalablePen; @@ -89,15 +83,7 @@ static inline void qskExecCommand( if ( painter->transform().isScaling() ) { - bool isCosmetic = painter->pen().isCosmetic(); - if ( isCosmetic && painter->pen().widthF() == 0.0 ) - { - QPainter::RenderHints hints = painter->renderHints(); - if ( hints.testFlag( QPainter::NonCosmeticDefaultPen ) ) - isCosmetic = false; - } - - if ( isCosmetic ) + if ( painter->pen().isCosmetic() ) { // OpenGL2 seems to be buggy for cosmetic pens. // It interpolates curves in too rough steps then