Skip to content

Commit

Permalink
Merge pull request #2368 from nirvn/welcome_page_fix_resize
Browse files Browse the repository at this point in the history
[welcome page] fix recent project list not resizing on window / docked panel size change
  • Loading branch information
nyalldawson committed Oct 13, 2015
2 parents ff43a5d + 537d195 commit 7b9148a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/app/qgswelcomepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
22 changes: 16 additions & 6 deletions src/app/qgswelcomepageitemsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand All @@ -89,16 +90,25 @@ 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 width;
if ( option.rect.width() < 450 )
{
width = 450;
}
else
{
width = option.rect.width();
}

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( width - ( !icon.isNull() ? icon.width() + 35 : 35 ) );

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

QgsWelcomePageItemsModel::QgsWelcomePageItemsModel( QObject* parent )
Expand Down

0 comments on commit 7b9148a

Please sign in to comment.