Skip to content
Permalink
Browse files

Try to balance UI element sizes on windows builds

  • Loading branch information
nyalldawson committed Jul 26, 2017
1 parent a48c146 commit 11dd4170de9098021992771ec424efe005dbb705
Showing with 35 additions and 16 deletions.
  1. +7 −0 python/core/qgis.sip
  2. +6 −0 src/core/qgis.cpp
  3. +7 −0 src/core/qgis.h
  4. +5 −5 src/gui/qgscolorswatchgrid.cpp
  5. +5 −5 src/gui/qgscolorwidgets.cpp
  6. +5 −6 src/gui/qgsmenuheader.cpp
@@ -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

};
@@ -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
@@ -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
@@ -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;
@@ -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 );
}

@@ -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 );
}

@@ -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" ) ) );
}
}

@@ -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 )
@@ -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 * )
@@ -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();
}

0 comments on commit 11dd417

Please sign in to comment.
You can’t perform that action at this time.