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());
{
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<QPixmap>();
- //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);
textHeight += BUTTON_HEIGHT;
}
- textHeight = qMax(textHeight, 128);
+ textHeight = qMax(textHeight, thumbnailSize.height());
return QSize(option.rect.width(), textHeight + (MARGIN * 2));
}
// FlightGear
#include <Main/globals.hxx>
+
const int STANDARD_THUMBNAIL_HEIGHT = 128;
+const int STANDARD_THUMBNAIL_WIDTH = 172;
using namespace simgear::pkg;
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.
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;
} else {
return PackageNotInstalled;
}
+ } else if (role == AircraftThumbnailSizeRole) {
+ QPixmap pm = packageThumbnail(item, 0, false).value<QPixmap>();
+ 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) {
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()) {
} // of have thumbnail file names
} // of have existing install
- m_packageRoot->requestThumbnailData(thumbnailUrl);
+ if (download) {
+ m_packageRoot->requestThumbnailData(thumbnailUrl);
+ }
return QVariant();
}
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;
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();