Skip to content

Commit

Permalink
[hidpi] Auto-scale cursors based on DPIs
Browse files Browse the repository at this point in the history
This should work well on different DPI screens.

Still needs some testing on the various platforms.
elpaso committed Nov 27, 2017
1 parent 7ae8e16 commit 346ab60
Showing 4 changed files with 22 additions and 17 deletions.
24 changes: 13 additions & 11 deletions images/themes/default/cursors/mSampler.svg

Unable to render rich display

Invalid image source.

2 changes: 2 additions & 0 deletions python/core/qgsapplication.sip
Original file line number Diff line number Diff line change
@@ -360,6 +360,8 @@ Returns the path to the default theme directory.
%Docstring
Helper to get a theme cursor. It will fall back to the
default theme if the active theme does not have the required icon.
Cursors are automatically scaled to look like a 16px cursor on 96dpi
screens.
:rtype: QCursor
%End

11 changes: 5 additions & 6 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
@@ -487,10 +487,7 @@ QCursor QgsApplication::getThemeCursor( const Cursor &cursor )
if ( app && app->mCursorCache.contains( cursor ) )
return app->mCursorCache.value( cursor );

// Cursor are supposed to be 32x32 as it seems to be the
// most cross-platform size
// If we want to make this size user-configurable or make
// a better guess: we might use fontMetrics
// All calculations are done on 32x32 icons
// Defaults to center, individual cursors may override
int activeX = 16;
int activeY = 16;
@@ -520,7 +517,7 @@ QCursor QgsApplication::getThemeCursor( const Cursor &cursor )
break;
case Sampler:
activeX = 0;
activeY = 0;
activeY = 32;
name = QStringLiteral( "mSampler.svg" );
break;
// No default
@@ -533,7 +530,9 @@ QCursor QgsApplication::getThemeCursor( const Cursor &cursor )
// Check if an icon exists for this cursor (the O.S. default cursor will be used if it does not)
if ( ! icon.isNull( ) )
{
_cursor = QCursor( icon.pixmap( 32, 32 ), activeX, activeY );
// Apply scaling
float scale( ( float ) app->fontMetrics().height() / 32 );
_cursor = QCursor( icon.pixmap( std::ceil( scale * 32 ), std::ceil( scale * 32 ) ), std::ceil( scale * activeX ), std::ceil( scale * activeY ) );
}
if ( app )
app->mCursorCache.insert( cursor, _cursor );
2 changes: 2 additions & 0 deletions src/core/qgsapplication.h
Original file line number Diff line number Diff line change
@@ -329,6 +329,8 @@ class CORE_EXPORT QgsApplication : public QApplication
/**
* Helper to get a theme cursor. It will fall back to the
* default theme if the active theme does not have the required icon.
* Cursors are automatically scaled to look like a 16px cursor on 96dpi
* screens.
*/
static QCursor getThemeCursor( const Cursor &cursor );

0 comments on commit 346ab60

Please sign in to comment.