Skip to content

Commit

Permalink
Try to balance UI element sizes on windows builds
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 26, 2017
1 parent a48c146 commit 11dd417
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
7 changes: 7 additions & 0 deletions python/core/qgis.sip
Expand Up @@ -108,6 +108,13 @@ Default threshold between map coordinates and device coordinates for map2pixel s
Default Z coordinate value for 2.5d geometry
This value have to be assigned to the Z coordinate for the new 2.5d geometry vertex.
.. versionadded:: 3.0
%End

static const double UI_SCALE_FACTOR;
%Docstring
UI scaling factor. This should be applied to all widget sizes obtained from font metrics,
to account for differences in the default font sizes across different platforms.
.. versionadded:: 3.0
%End

};
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgis.cpp
Expand Up @@ -84,6 +84,12 @@ const double Qgis::SCALE_PRECISION = 0.9999999999;

const double Qgis::DEFAULT_Z_COORDINATE = 0.0;

#ifdef Q_OS_WIN
const double Qgis::UI_SCALE_FACTOR = 1.5;
#else
const double Qgis::UI_SCALE_FACTOR = 1;
#endif

double qgsPermissiveToDouble( QString string, bool &ok )
{
//remove any thousands separators
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgis.h
Expand Up @@ -120,6 +120,13 @@ class CORE_EXPORT Qgis
* \since QGIS 3.0 */
static const double DEFAULT_Z_COORDINATE;

/**
* UI scaling factor. This should be applied to all widget sizes obtained from font metrics,
* to account for differences in the default font sizes across different platforms.
* \since QGIS 3.0
*/
static const double UI_SCALE_FACTOR;

};

// hack to workaround warnings when casting void pointers
Expand Down
10 changes: 5 additions & 5 deletions src/gui/qgscolorswatchgrid.cpp
Expand Up @@ -38,14 +38,14 @@ QgsColorSwatchGrid::QgsColorSwatchGrid( QgsColorScheme *scheme, const QString &c
setFocusPolicy( Qt::StrongFocus );
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );

mLabelHeight = fontMetrics().height();
mLabelMargin = fontMetrics().width( QStringLiteral( "." ) );
mLabelHeight = Qgis::UI_SCALE_FACTOR * fontMetrics().height();
mLabelMargin = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "." ) );

mSwatchSize = fontMetrics().width( QStringLiteral( "X" ) ) * 1.75;
mSwatchOutlineSize = qMax( mLabelMargin * 0.4, 1.0 );
mSwatchSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "X" ) ) * 1.75;
mSwatchOutlineSize = qMax( fontMetrics().width( QStringLiteral( "." ) ) * 0.4, 1.0 );

mSwatchSpacing = mSwatchSize * 0.3;
mSwatchMargin = mLabelMargin * 1.5;
mSwatchMargin = mLabelMargin;

//calculate widget width
mWidth = NUMBER_COLORS_PER_ROW * mSwatchSize + ( NUMBER_COLORS_PER_ROW - 1 ) * mSwatchSpacing + mSwatchMargin + mSwatchMargin;
Expand Down
10 changes: 5 additions & 5 deletions src/gui/qgscolorwidgets.cpp
Expand Up @@ -397,7 +397,7 @@ QgsColorWheel::~QgsColorWheel()

QSize QgsColorWheel::sizeHint() const
{
int size = fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
return QSize( size, size );
}

Expand Down Expand Up @@ -758,7 +758,7 @@ QgsColorBox::~QgsColorBox()

QSize QgsColorBox::sizeHint() const
{
int size = fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
return QSize( size, size );
}

Expand Down Expand Up @@ -991,12 +991,12 @@ QSize QgsColorRampWidget::sizeHint() const
if ( mOrientation == QgsColorRampWidget::Horizontal )
{
//horizontal
return QSize( fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), fontMetrics().height() * 1.3 );
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3 );
}
else
{
//vertical
return QSize( fontMetrics().height() * 1.3, fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) );
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) );
}
}

Expand Down Expand Up @@ -1598,7 +1598,7 @@ void QgsColorPreviewWidget::paintEvent( QPaintEvent *event )

QSize QgsColorPreviewWidget::sizeHint() const
{
return QSize( fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) * 0.75 );
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) * 0.75 );
}

void QgsColorPreviewWidget::setColor2( const QColor &color )
Expand Down
11 changes: 5 additions & 6 deletions src/gui/qgsmenuheader.cpp
Expand Up @@ -25,20 +25,20 @@ QgsMenuHeader::QgsMenuHeader( const QString &text, QWidget *parent )
{
int textMinWidth = fontMetrics().width( mText );
mTextHeight = fontMetrics().height();
mLabelMargin = fontMetrics().width( QStringLiteral( "." ) );
mLabelMargin = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "." ) );
mMinWidth = 2 * mLabelMargin + textMinWidth;
setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
updateGeometry();
}

QSize QgsMenuHeader::minimumSizeHint() const
{
return QSize( mMinWidth, mTextHeight + 0.5 * mLabelMargin );
return QSize( mMinWidth, mTextHeight + mLabelMargin );
}

QSize QgsMenuHeader::sizeHint() const
{
return QSize( mMinWidth, mTextHeight + 0.5 * mLabelMargin );
return QSize( mMinWidth, mTextHeight + mLabelMargin );
}

void QgsMenuHeader::paintEvent( QPaintEvent * )
Expand All @@ -51,12 +51,11 @@ void QgsMenuHeader::paintEvent( QPaintEvent * )
//draw header background
painter.setBrush( headerBgColor );
painter.setPen( Qt::NoPen );
painter.drawRect( QRect( 0, 0, width(), mTextHeight + 0.5 * mLabelMargin ) );
painter.drawRect( QRect( 0, 0, width(), mTextHeight + mLabelMargin ) );

//draw header text
painter.setPen( headerTextColor );
painter.drawText( QRect( mLabelMargin, 0.25 * mLabelMargin, width() - 2 * mLabelMargin, mTextHeight ),
Qt::AlignLeft | Qt::AlignVCenter, mText );
painter.drawText( QPoint( mLabelMargin, 0.25 * mLabelMargin + mTextHeight ), mText );
painter.end();
}

Expand Down

0 comments on commit 11dd417

Please sign in to comment.