From e46fa8bc722b7659beac43ed5a4e358dcfac522e Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 30 Oct 2024 12:51:17 +0100 Subject: [PATCH] using mm instead of dp --- src/common/QskPlatform.cpp | 23 +++++++++++++++++++++++ src/common/QskPlatform.h | 4 ++++ src/controls/QskSubWindow.cpp | 5 ++--- src/controls/QskSubWindowArea.cpp | 7 ++++--- src/controls/QskSwipeView.cpp | 2 +- src/dialogs/QskDialogSubWindow.cpp | 6 +----- 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/common/QskPlatform.cpp b/src/common/QskPlatform.cpp index 10fdc86f..419ed960 100644 --- a/src/common/QskPlatform.cpp +++ b/src/common/QskPlatform.cpp @@ -6,6 +6,7 @@ #include "QskPlatform.h" #include +#include #include QSK_QT_PRIVATE_BEGIN @@ -88,3 +89,25 @@ qreal qskPxToPixelsFactor() return 1.0; } + +static inline qreal qskWindowDpi( const QWindow* window ) +{ + QScreen* screen = nullptr; + if ( window ) + screen = window->screen(); + + if ( screen == nullptr ) + screen = QGuiApplication::primaryScreen(); + + return QHighDpiScaling::logicalDpi( screen ).first; +} + +qreal qskInchesToPixels( const QQuickWindow* window, qreal inches ) +{ + return qskWindowDpi( window ) * inches; +} + +qreal qskMMToPixels( const QQuickWindow* window, qreal mm ) +{ + return qskWindowDpi( window ) * mm / 25.4; +} diff --git a/src/common/QskPlatform.h b/src/common/QskPlatform.h index e5c9fa83..0cac2e44 100644 --- a/src/common/QskPlatform.h +++ b/src/common/QskPlatform.h @@ -12,6 +12,7 @@ class QScreen; class QPlatformIntegration; class QPlatformTheme; class QRect; +class QQuickWindow; QSK_EXPORT qreal qskGlobalScaleFactor(); @@ -33,6 +34,9 @@ QSK_EXPORT const QPlatformTheme* qskPlatformTheme(); QSK_EXPORT qreal qskDpToPixelsFactor(); QSK_EXPORT qreal qskPxToPixelsFactor(); +QSK_EXPORT qreal qskInchesToPixels( const QQuickWindow*, qreal mm ); +QSK_EXPORT qreal qskMMToPixels( const QQuickWindow*, qreal mm ); + inline qreal qskDpToPixels( qreal value ) { static qreal factor = -1.0; diff --git a/src/controls/QskSubWindow.cpp b/src/controls/QskSubWindow.cpp index 5daa8c2b..aae33665 100644 --- a/src/controls/QskSubWindow.cpp +++ b/src/controls/QskSubWindow.cpp @@ -5,7 +5,6 @@ #include "QskSubWindow.h" #include "QskAspect.h" -#include "QskPlatform.h" #include "QskGraphic.h" #include "QskGraphicProvider.h" #include "QskTextOptions.h" @@ -222,10 +221,10 @@ QSizeF QskSubWindow::layoutSizeHint( { // should be Minimum Width/Height from the skin hints if ( hint.width() < 0.0 ) - hint.setWidth( qskDpToPixels( 100 ) ); + hint.setWidth( 100 ); if ( hint.height() < 0.0 ) - hint.setHeight( qskDpToPixels( 80 ) ); + hint.setHeight( 80 ); } return hint; diff --git a/src/controls/QskSubWindowArea.cpp b/src/controls/QskSubWindowArea.cpp index 5e7db643..dc632894 100644 --- a/src/controls/QskSubWindowArea.cpp +++ b/src/controls/QskSubWindowArea.cpp @@ -24,9 +24,10 @@ static void qskUpdateEventFilter( QskSubWindowArea* area ) } } -static Qt::Edges qskSelectedEdges( const QRectF& rect, const QPointF& pos ) +static Qt::Edges qskSelectedEdges( const QskSubWindowArea* area, + const QRectF& rect, const QPointF& pos ) { - const qreal tolerance = qskDpToPixels( 10.0 ); + const qreal tolerance = qskMMToPixels( area->window(), 3 ); Qt::Edges edges; if ( pos.x() <= rect.left() + tolerance ) @@ -222,7 +223,7 @@ bool QskSubWindowArea::mouseEventFilter( QskSubWindow* window, const QMouseEvent if ( doDrag ) { m_data->isDragging = true; - m_data->draggedEdges = qskSelectedEdges( cr, mousePos ); + m_data->draggedEdges = qskSelectedEdges( this, cr, mousePos ); m_data->mousePos = qskMouseScenePosition( event ); setDragging( window, true ); diff --git a/src/controls/QskSwipeView.cpp b/src/controls/QskSwipeView.cpp index a1e94a09..a25cffdb 100644 --- a/src/controls/QskSwipeView.cpp +++ b/src/controls/QskSwipeView.cpp @@ -74,7 +74,7 @@ void QskSwipeView::setSwipeDistance( int distance ) void QskSwipeView::resetSwipeDistance() { - setSwipeDistance( qRound( qskDpToPixels( 40 ) ) ); + setSwipeDistance( qRound( qskMMToPixels( window(), 8 ) ) ); } int QskSwipeView::duration() const diff --git a/src/dialogs/QskDialogSubWindow.cpp b/src/dialogs/QskDialogSubWindow.cpp index 3cde7a12..765c805e 100644 --- a/src/dialogs/QskDialogSubWindow.cpp +++ b/src/dialogs/QskDialogSubWindow.cpp @@ -10,10 +10,6 @@ #include "QskLinearBox.h" #include "QskQuick.h" #include "QskEvent.h" -#if 1 -#include "QskSkin.h" -#include -#endif #include #include @@ -394,7 +390,7 @@ QSizeF QskDialogSubWindow::layoutSizeHint( if ( which == Qt::MinimumSize ) { - const auto w = qMax( qskDpToPixels( 300.0 ), size.width() ); + const auto w = qMax( 300.0, size.width() ); size.setWidth( w ); }