Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hidpi friendly welcome page sizes
  • Loading branch information
nyalldawson committed Nov 1, 2018
1 parent 187f741 commit 26c3dd3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/qgswelcomepage.cpp
Expand Up @@ -50,7 +50,7 @@ QgsWelcomePage::QgsWelcomePage( bool skipVersionCheck, QWidget *parent )

int titleSize = QApplication::fontMetrics().height() * 1.4;
QLabel *recentProjectsTitle = new QLabel( QStringLiteral( "<div style='font-size:%1px;font-weight:bold'>%2</div>" ).arg( titleSize ).arg( tr( "Recent Projects" ) ) );
recentProjectsTitle->setContentsMargins( 10, 3, 0, 0 );
recentProjectsTitle->setContentsMargins( titleSize / 2, titleSize / 6, 0, 0 );

recentProjectsContainer->layout()->addWidget( recentProjectsTitle );

Expand Down
16 changes: 9 additions & 7 deletions src/app/qgswelcomepageitemsmodel.cpp
Expand Up @@ -31,6 +31,7 @@

QgsWelcomePageItemDelegate::QgsWelcomePageItemDelegate( QObject *parent )
: QStyledItemDelegate( parent )
, mRoundedRectSizePixels( Qgis::UI_SCALE_FACTOR * QApplication::fontMetrics().height() * 0.5 )
{

}
Expand Down Expand Up @@ -73,7 +74,8 @@ void QgsWelcomePageItemDelegate::paint( QPainter *painter, const QStyleOptionVie
painter->setRenderHint( QPainter::Antialiasing );
painter->setPen( QColor( 0, 0, 0, 0 ) );
painter->setBrush( QBrush( color ) );
painter->drawRoundedRect( option.rect.left() + 5, option.rect.top() + 5, option.rect.width() - 10, option.rect.height() - 10, 8, 8 );
painter->drawRoundedRect( option.rect.left() + 0.625 * mRoundedRectSizePixels, option.rect.top() + 0.625 * mRoundedRectSizePixels,
option.rect.width() - 2 * 0.625 * mRoundedRectSizePixels, option.rect.height() - 2 * 0.625 * mRoundedRectSizePixels, mRoundedRectSizePixels, mRoundedRectSizePixels );

int titleSize = QApplication::fontMetrics().height() * 1.1;
int textSize = titleSize * 0.85;
Expand All @@ -83,15 +85,15 @@ void QgsWelcomePageItemDelegate::paint( QPainter *painter, const QStyleOptionVie
index.data( QgsWelcomePageItemsModel::PinRole ).toBool() ? QStringLiteral( "<img src=\"qrc:/images/themes/default/pin.svg\">" ) : QString(),
index.data( QgsWelcomePageItemsModel::NativePathRole ).toString(),
index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) );
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 4.375 * mRoundedRectSizePixels : 4.375 * mRoundedRectSizePixels ) );

if ( !icon.isNull() )
{
painter->drawPixmap( option.rect.left() + 10, option.rect.top() + 10, icon );
painter->drawPixmap( option.rect.left() + 1.25 * mRoundedRectSizePixels, option.rect.top() + 1.25 * mRoundedRectSizePixels, icon );
}

painter->translate( option.rect.left() + ( !icon.isNull() ? icon.width() + 25 : 15 ), option.rect.top() + 15 );
ctx.clip = QRect( 0, 0, option.rect.width() - ( !icon.isNull() ? icon.width() - 35 : 25 ), option.rect.height() - 25 );
painter->translate( option.rect.left() + ( !icon.isNull() ? icon.width() + 3.125 * mRoundedRectSizePixels : 1.875 * mRoundedRectSizePixels ), option.rect.top() + 1.875 * mRoundedRectSizePixels );
ctx.clip = QRect( 0, 0, option.rect.width() - ( !icon.isNull() ? icon.width() - 4.375 * mRoundedRectSizePixels : 3.125 * mRoundedRectSizePixels ), option.rect.height() - 3.125 * mRoundedRectSizePixels );
doc.documentLayout()->draw( painter, ctx );

painter->restore();
Expand Down Expand Up @@ -120,9 +122,9 @@ QSize QgsWelcomePageItemDelegate::sizeHint( const QStyleOptionViewItem &option,
index.data( QgsWelcomePageItemsModel::PinRole ).toBool() ? QStringLiteral( "<img src=\"qrc:/images/themes/default/pin.svg\">" ) : QString(),
index.data( QgsWelcomePageItemsModel::NativePathRole ).toString(),
index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
doc.setTextWidth( width - ( !icon.isNull() ? icon.width() + 35 : 35 ) );
doc.setTextWidth( width - ( !icon.isNull() ? icon.width() + 4.375 * mRoundedRectSizePixels : 4.375 * mRoundedRectSizePixels ) );

return QSize( width, std::max( ( double ) doc.size().height() + 10, static_cast<double>( icon.height() ) ) + 20 );
return QSize( width, std::max( ( double ) doc.size().height() + 1.25 * mRoundedRectSizePixels, static_cast<double>( icon.height() ) ) + 2.5 * mRoundedRectSizePixels );
}

QgsWelcomePageItemsModel::QgsWelcomePageItemsModel( QObject *parent )
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgswelcomepageitemsmodel.h
Expand Up @@ -28,6 +28,10 @@ class QgsWelcomePageItemDelegate : public QStyledItemDelegate
explicit QgsWelcomePageItemDelegate( QObject *parent = nullptr );
void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override;

private:

int mRoundedRectSizePixels = 5;
};

class QgsWelcomePageItemsModel : public QAbstractListModel
Expand Down

0 comments on commit 26c3dd3

Please sign in to comment.