Skip to content
Permalink
Browse files

Merge pull request #2368 from nirvn/welcome_page_fix_resize

[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 7b9148a5ddcd1511a6cce3bdebd5ef23bfbb954d
Showing with 18 additions and 6 deletions.
  1. +2 −0 src/app/qgswelcomepage.cpp
  2. +16 −6 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,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 )

0 comments on commit 7b9148a

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