diff --git a/src/modules/packagechooser/PackageChooserPage.cpp b/src/modules/packagechooser/PackageChooserPage.cpp
index 6f565c914..f0a6579b4 100644
--- a/src/modules/packagechooser/PackageChooserPage.cpp
+++ b/src/modules/packagechooser/PackageChooserPage.cpp
@@ -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() ) );
+ }
}
}
diff --git a/src/modules/packagechooser/images/no-selection.png b/src/modules/packagechooser/images/no-selection.png
index f9dbbbac4..437c97051 100644
Binary files a/src/modules/packagechooser/images/no-selection.png and b/src/modules/packagechooser/images/no-selection.png differ
diff --git a/src/modules/packagechooser/page_package.ui b/src/modules/packagechooser/page_package.ui
index 17a960549..496c478a1 100644
--- a/src/modules/packagechooser/page_package.ui
+++ b/src/modules/packagechooser/page_package.ui
@@ -37,21 +37,36 @@
-
- TextLabel
+ Product Name
-
+
+
+ 1
+ 0
+
+
TextLabel
+
+ Qt::AlignCenter
+
-
+
+
+ 0
+ 2
+
+
- TextLabel
+ Long Product Description
true