Skip to content
Permalink
Browse files

[welcome page] fix recent project list not resizing

  • Loading branch information
nirvn committed Oct 13, 2015
1 parent e193c7c commit 06a41ef77fa10b793af47bb768397abe314698c3
Showing with 7 additions and 5 deletions.
  1. +2 −0 src/app/qgswelcomepage.cpp
  2. +5 −5 src/app/qgswelcomepageitemsmodel.cpp
@@ -42,6 +42,8 @@ QgsWelcomePage::QgsWelcomePage( QWidget* parent )
recentProjctsContainer->layout()->addWidget( recentProjectsTitle );

QListView* recentProjectsListView = new QListView();
recentProjectsListView->setResizeMode( QListView::Adjust );

mModel = new QgsWelcomePageItemsModel( recentProjectsListView );
recentProjectsListView->setModel( mModel );
recentProjectsListView->setItemDelegate( new QgsWelcomePageItemDelegate( recentProjectsListView ) );
@@ -36,6 +36,8 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
painter->save();

QTextDocument doc;
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );

QAbstractTextDocumentLayout::PaintContext ctx;
QStyleOptionViewItemV4 optionV4 = option;

@@ -71,9 +73,8 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
int textSize = titleSize * 0.85;

doc.setHtml( QString( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize ).arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::PathRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
doc.setTextWidth( 2800 );
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) );

QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
if ( !icon.isNull() )
{
painter->drawPixmap( option.rect.left() + 10, option.rect.top() + 10, icon );
@@ -89,14 +90,13 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
QSize QgsWelcomePageItemDelegate::sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
QTextDocument doc;
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );

int titleSize = QApplication::fontMetrics().height() * 1.1;
int textSize = titleSize * 0.85;

doc.setHtml( QString( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize ).arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::PathRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
doc.setTextWidth( 2800 );

QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) );

return QSize( option.rect.width(), qMax( doc.size().height() + 10, ( double )icon.height() ) + 20 );
}

0 comments on commit 06a41ef

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