Merge branch 'issue-1215'

FIXES #1215
FIXES #1216
This commit is contained in:
Adriaan de Groot 2019-08-26 21:42:40 +02:00
commit c28c97d3aa
3 changed files with 58 additions and 3 deletions

View File

@ -52,6 +52,37 @@ PackageChooserPage::PackageChooserPage( PackageChooserMode mode, QWidget* parent
}
}
/** @brief size the given @p pixmap to @p size
*
* This is "smart" in the sense that it tries to keep the image un-scaled
* (if it's just a little too big) and otherwise scales as needed.
*
* Returns a copy if any modifications are done.
*/
static QPixmap
smartClip( const QPixmap& pixmap, QSize size )
{
auto pixSize = pixmap.size();
if ( ( pixSize.width() <= size.width() ) && ( pixSize.height() <= size.height() ) )
{
return pixmap;
}
// only slightly bigger? Trim the edges
constexpr int margin = 16;
if ( ( pixSize.width() <= size.width() + margin ) && ( pixSize.height() <= size.height() + margin ) )
{
int x = pixSize.width() <= size.width() ? 0 : ( pixSize.width() - size.width() / 2 );
int new_width = pixSize.width() <= size.width() ? pixSize.width() : size.width();
int y = pixSize.height() <= size.height() ? 0 : ( pixSize.height() - size.height() / 2 );
int new_height = pixSize.height() <= size.height() ? pixSize.height() : size.height();
return pixmap.copy( x, y, new_width, new_height );
}
return pixmap.scaled( size, Qt::KeepAspectRatio );
}
void
PackageChooserPage::currentChanged( const QModelIndex& index )
{
@ -66,8 +97,17 @@ PackageChooserPage::currentChanged( const QModelIndex& index )
const auto* model = ui->products->model();
ui->productName->setText( model->data( index, PackageListModel::NameRole ).toString() );
ui->productScreenshot->setPixmap( model->data( index, PackageListModel::ScreenshotRole ).value< QPixmap >() );
ui->productDescription->setText( model->data( index, PackageListModel::DescriptionRole ).toString() );
QPixmap currentScreenshot = model->data( index, PackageListModel::ScreenshotRole ).value< QPixmap >();
if ( currentScreenshot.isNull() )
{
ui->productScreenshot->setPixmap( m_introduction.screenshot );
}
else
{
ui->productScreenshot->setPixmap( smartClip( currentScreenshot, ui->productScreenshot->size() ) );
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -37,21 +37,36 @@
<item>
<widget class="QLabel" name="productName">
<property name="text">
<string>TextLabel</string>
<string>Product Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="productScreenshot">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="productDescription">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
<string>Long Product Description</string>
</property>
<property name="wordWrap">
<bool>true</bool>