From: James Turner Date: Tue, 10 Nov 2015 23:28:24 +0000 (+0000) Subject: Fixes to launcher aircraft thumbnail sizing X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5043bf096602aab9280dc7767a4a3cf6b43e062a;p=flightgear.git Fixes to launcher aircraft thumbnail sizing - handle large images and longer descriptions correctly --- diff --git a/src/GUI/AircraftItemDelegate.cxx b/src/GUI/AircraftItemDelegate.cxx index f07cbee4c..7e45801a5 100644 --- a/src/GUI/AircraftItemDelegate.cxx +++ b/src/GUI/AircraftItemDelegate.cxx @@ -73,7 +73,7 @@ void AircraftItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem contentRect.right(), contentRect.bottom() + MARGIN); int variantCount = index.data(AircraftVariantCountRole).toInt(); - int currentVariant =index.data(AircraftVariantRole).toInt(); + int currentVariant = index.data(AircraftVariantRole).toInt(); QString description = index.data(Qt::DisplayRole).toString(); contentRect.setLeft(contentRect.left() + MARGIN + thumbnail.width()); @@ -210,11 +210,8 @@ QSize AircraftItemDelegate::sizeHint(const QStyleOptionViewItem & option, const { QRect contentRect = option.rect.adjusted(MARGIN, MARGIN, -MARGIN, -MARGIN); - const int THUMBNAIL_WIDTH = 172; - // don't request the thumbnail here for remote sources. Assume the default - //QPixmap thumbnail = index.data(Qt::DecorationRole).value(); - //contentRect.setLeft(contentRect.left() + MARGIN + thumbnail.width()); - contentRect.setLeft(contentRect.left() + MARGIN + THUMBNAIL_WIDTH); + QSize thumbnailSize = index.data(AircraftThumbnailSizeRole).toSize(); + contentRect.setLeft(contentRect.left() + MARGIN + thumbnailSize.width()); QFont f; f.setPointSize(18); @@ -246,7 +243,7 @@ QSize AircraftItemDelegate::sizeHint(const QStyleOptionViewItem & option, const textHeight += BUTTON_HEIGHT; } - textHeight = qMax(textHeight, 128); + textHeight = qMax(textHeight, thumbnailSize.height()); return QSize(option.rect.width(), textHeight + (MARGIN * 2)); } diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index 56a5c64c6..3b156e701 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -40,7 +40,9 @@ // FlightGear #include
+ const int STANDARD_THUMBNAIL_HEIGHT = 128; +const int STANDARD_THUMBNAIL_WIDTH = 172; using namespace simgear::pkg; @@ -367,8 +369,12 @@ protected: return; } + QPixmap pix = QPixmap::fromImage(img); + if (pix.height() > STANDARD_THUMBNAIL_HEIGHT) { + pix = pix.scaledToHeight(STANDARD_THUMBNAIL_HEIGHT); + } m_model->m_thumbnailPixmapCache.insert(QString::fromStdString(aThumbnailUrl), - QPixmap::fromImage(img)); + pix); // notify any affected items. Linear scan here avoids another map/dict // structure. @@ -515,6 +521,10 @@ QVariant AircraftItemModel::dataFromItem(AircraftItemPtr item, quint32 variantIn return p.isNull() ? 0 : 1; } + if (role == AircraftThumbnailSizeRole) { + return item->thumbnail().size(); + } + if ((role >= AircraftVariantDescriptionRole) && (role < AircraftThumbnailRole)) { int variantIndex = role - AircraftVariantDescriptionRole; return item->variants.at(variantIndex)->description; @@ -601,6 +611,11 @@ QVariant AircraftItemModel::dataFromPackage(const PackageRef& item, quint32 vari } else { return PackageNotInstalled; } + } else if (role == AircraftThumbnailSizeRole) { + QPixmap pm = packageThumbnail(item, 0, false).value(); + if (pm.isNull()) + return QSize(STANDARD_THUMBNAIL_WIDTH, STANDARD_THUMBNAIL_HEIGHT); + return pm.size(); } else if (role >= AircraftThumbnailRole) { return packageThumbnail(item , role - AircraftThumbnailRole); } else if (role == AircraftAuthorsRole) { @@ -628,7 +643,7 @@ QVariant AircraftItemModel::dataFromPackage(const PackageRef& item, quint32 vari return QVariant(); } -QVariant AircraftItemModel::packageThumbnail(PackageRef p, int index) const +QVariant AircraftItemModel::packageThumbnail(PackageRef p, int index, bool download) const { const string_list& thumbnails(p->thumbnailUrls()); if (index >= thumbnails.size()) { @@ -663,7 +678,9 @@ QVariant AircraftItemModel::packageThumbnail(PackageRef p, int index) const } // of have thumbnail file names } // of have existing install - m_packageRoot->requestThumbnailData(thumbnailUrl); + if (download) { + m_packageRoot->requestThumbnailData(thumbnailUrl); + } return QVariant(); } diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index 975e6808c..43208253d 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -45,6 +45,7 @@ const int AircraftInstallPercentRole = Qt::UserRole + 11; const int AircraftPackageSizeRole = Qt::UserRole + 12; const int AircraftInstallDownloadedSizeRole = Qt::UserRole + 13; const int AircraftURIRole = Qt::UserRole + 14; +const int AircraftThumbnailSizeRole = Qt::UserRole + 15; const int AircraftRatingRole = Qt::UserRole + 100; const int AircraftVariantDescriptionRole = Qt::UserRole + 200; @@ -143,7 +144,7 @@ private: QVariant dataFromPackage(const simgear::pkg::PackageRef& item, quint32 variantIndex, int role) const; - QVariant packageThumbnail(simgear::pkg::PackageRef p, int index) const; + QVariant packageThumbnail(simgear::pkg::PackageRef p, int index, bool download = true) const; void abandonCurrentScan(); void refreshPackages();