1
0
Fork 0

Fixes to launcher aircraft delegate.

- fix some text size computation issues
This commit is contained in:
James Turner 2016-01-10 23:46:44 -06:00
parent 4396c035df
commit 409ffc971d
2 changed files with 21 additions and 9 deletions

View file

@ -101,10 +101,11 @@ void AircraftItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem
} }
painter->drawText(descriptionRect, Qt::TextWordWrap, description, &actualBounds); painter->drawText(descriptionRect, Qt::TextWordWrap, description, &actualBounds);
QString authors = index.data(AircraftAuthorsRole).toString(); QString authors = index.data(AircraftAuthorsRole).toString();
f.setPointSize(12); f.setPointSize(12);
QFontMetrics smallMetrics(f);
painter->setFont(f); painter->setFont(f);
if (!authors.isEmpty()) { if (!authors.isEmpty()) {
@ -127,7 +128,7 @@ void AircraftItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem
r.setWidth(contentRect.width() / 3); r.setWidth(contentRect.width() / 3);
r.moveTop(actualBounds.bottom() + MARGIN); r.moveTop(actualBounds.bottom() + MARGIN);
r.moveLeft(r.right()); r.moveLeft(r.right());
r.setHeight(24); r.setHeight(qMax(24, smallMetrics.height() + MARGIN));
if (index.data(AircraftHasRatingsRole).toBool()) { if (index.data(AircraftHasRatingsRole).toBool()) {
drawRating(painter, "Flight model:", r, index.data(AircraftRatingRole).toInt()); drawRating(painter, "Flight model:", r, index.data(AircraftRatingRole).toInt());
@ -138,7 +139,7 @@ void AircraftItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem
r.moveLeft(r.right()); r.moveLeft(r.right());
drawRating(painter, "Cockpit:", r, index.data(AircraftRatingRole + 2).toInt()); drawRating(painter, "Cockpit:", r, index.data(AircraftRatingRole + 2).toInt());
r.moveTop(r.bottom()); r.moveTop(r.bottom());
drawRating(painter, "Exterior model:", r, index.data(AircraftRatingRole + 3).toInt()); drawRating(painter, "Exterior:", r, index.data(AircraftRatingRole + 3).toInt());
} }
QVariant v = index.data(AircraftPackageStatusRole); QVariant v = index.data(AircraftPackageStatusRole);
@ -212,6 +213,8 @@ QSize AircraftItemDelegate::sizeHint(const QStyleOptionViewItem & option, const
QSize thumbnailSize = index.data(AircraftThumbnailSizeRole).toSize(); QSize thumbnailSize = index.data(AircraftThumbnailSizeRole).toSize();
contentRect.setLeft(contentRect.left() + MARGIN + thumbnailSize.width()); contentRect.setLeft(contentRect.left() + MARGIN + thumbnailSize.width());
contentRect.setBottom(9999); // large value to avoid clipping
contentRect.adjust(ARROW_SIZE, 0, -ARROW_SIZE, 0);
QFont f; QFont f;
f.setPointSize(18); f.setPointSize(18);
@ -223,7 +226,8 @@ QSize AircraftItemDelegate::sizeHint(const QStyleOptionViewItem & option, const
f.setPointSize(12); f.setPointSize(12);
QFontMetrics smallMetrics(f); QFontMetrics smallMetrics(f);
QString authors = index.data(AircraftAuthorsRole).toString(); QString authors = QString("by: %1").arg(index.data(AircraftAuthorsRole).toString());
if (!authors.isEmpty()) { if (!authors.isEmpty()) {
textHeight += MARGIN; textHeight += MARGIN;
textHeight += smallMetrics.boundingRect(contentRect, Qt::TextWordWrap, authors).height(); textHeight += smallMetrics.boundingRect(contentRect, Qt::TextWordWrap, authors).height();
@ -237,14 +241,14 @@ QSize AircraftItemDelegate::sizeHint(const QStyleOptionViewItem & option, const
if (index.data(AircraftHasRatingsRole).toBool()) { if (index.data(AircraftHasRatingsRole).toBool()) {
// ratings // ratings
textHeight += 48; // (24px per rating box) int ratingHeight = qMax(24, smallMetrics.height() + MARGIN);
textHeight += ratingHeight * 2;
} else { } else {
// just the button height // just the button height
textHeight += BUTTON_HEIGHT; textHeight += BUTTON_HEIGHT;
} }
textHeight = qMax(textHeight, thumbnailSize.height()); textHeight = qMax(textHeight, thumbnailSize.height());
return QSize(option.rect.width(), textHeight + (MARGIN * 2)); return QSize(option.rect.width(), textHeight + (MARGIN * 2));
} }

View file

@ -615,11 +615,19 @@ QVariant AircraftItemModel::dataFromPackage(const PackageRef& item, quint32 vari
if ((role >= AircraftVariantDescriptionRole) && (role < AircraftThumbnailRole)) { if ((role >= AircraftVariantDescriptionRole) && (role < AircraftThumbnailRole)) {
int variantIndex = role - AircraftVariantDescriptionRole; int variantIndex = role - AircraftVariantDescriptionRole;
return QString::fromStdString(item->nameForVariant(variantIndex)); QString desc = QString::fromStdString(item->nameForVariant(variantIndex));
if (desc.isEmpty()) {
desc = tr("Missing description for: %1").arg(QString::fromStdString(item->id()));
}
return desc;
} }
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
return QString::fromStdString(item->nameForVariant(variantIndex)); QString desc = QString::fromStdString(item->nameForVariant(variantIndex));
if (desc.isEmpty()) {
desc = tr("Missing description for: %1").arg(QString::fromStdString(item->id()));
}
return desc;
} else if (role == AircraftPathRole) { } else if (role == AircraftPathRole) {
InstallRef i = item->existingInstall(); InstallRef i = item->existingInstall();
if (i.valid()) { if (i.valid()) {