commit
c28c97d3aa
@ -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 |
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user