Skip to content

Commit 7b9148a

Browse files
committedOct 13, 2015
Merge pull request #2368 from nirvn/welcome_page_fix_resize
[welcome page] fix recent project list not resizing on window / docked panel size change
2 parents ff43a5d + 537d195 commit 7b9148a

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed
 

‎src/app/qgswelcomepage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ QgsWelcomePage::QgsWelcomePage( QWidget* parent )
4242
recentProjctsContainer->layout()->addWidget( recentProjectsTitle );
4343

4444
QListView* recentProjectsListView = new QListView();
45+
recentProjectsListView->setResizeMode( QListView::Adjust );
46+
4547
mModel = new QgsWelcomePageItemsModel( recentProjectsListView );
4648
recentProjectsListView->setModel( mModel );
4749
recentProjectsListView->setItemDelegate( new QgsWelcomePageItemDelegate( recentProjectsListView ) );

‎src/app/qgswelcomepageitemsmodel.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
3636
painter->save();
3737

3838
QTextDocument doc;
39+
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
40+
3941
QAbstractTextDocumentLayout::PaintContext ctx;
4042
QStyleOptionViewItemV4 optionV4 = option;
4143

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

7375
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() ) );
74-
doc.setTextWidth( 2800 );
76+
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) );
7577

76-
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
7778
if ( !icon.isNull() )
7879
{
7980
painter->drawPixmap( option.rect.left() + 10, option.rect.top() + 10, icon );
@@ -89,16 +90,25 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
8990
QSize QgsWelcomePageItemDelegate::sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const
9091
{
9192
QTextDocument doc;
93+
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
94+
95+
int width;
96+
if ( option.rect.width() < 450 )
97+
{
98+
width = 450;
99+
}
100+
else
101+
{
102+
width = option.rect.width();
103+
}
92104

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

96108
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() ) );
97-
doc.setTextWidth( 2800 );
98-
99-
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
109+
doc.setTextWidth( width - ( !icon.isNull() ? icon.width() + 35 : 35 ) );
100110

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

104114
QgsWelcomePageItemsModel::QgsWelcomePageItemsModel( QObject* parent )

0 commit comments

Comments
 (0)
Please sign in to comment.