]> git.mxchange.org Git - flightgear.git/commitdiff
Fixes to launcher aircraft delegate.
authorJames Turner <zakalawe@mac.com>
Mon, 11 Jan 2016 05:46:44 +0000 (23:46 -0600)
committerJames Turner <zakalawe@mac.com>
Mon, 11 Jan 2016 05:46:44 +0000 (23:46 -0600)
- fix some text size computation issues

src/GUI/AircraftItemDelegate.cxx
src/GUI/AircraftModel.cxx

index 7e45801a5f4d39711a0c5793597662878bbcff96..0e293bc1929ef792772ea6ff0aafa1f9ab3c5994 100644 (file)
@@ -101,10 +101,11 @@ void AircraftItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem
     }
 
     painter->drawText(descriptionRect, Qt::TextWordWrap, description, &actualBounds);
-
     QString authors = index.data(AircraftAuthorsRole).toString();
 
     f.setPointSize(12);
+    QFontMetrics smallMetrics(f);
+
     painter->setFont(f);
 
     if (!authors.isEmpty()) {
@@ -127,7 +128,7 @@ void AircraftItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem
     r.setWidth(contentRect.width() / 3);
     r.moveTop(actualBounds.bottom() + MARGIN);
     r.moveLeft(r.right());
-    r.setHeight(24);
+    r.setHeight(qMax(24, smallMetrics.height() + MARGIN));
 
     if (index.data(AircraftHasRatingsRole).toBool()) {
         drawRating(painter, "Flight model:", r, index.data(AircraftRatingRole).toInt());
@@ -138,7 +139,7 @@ void AircraftItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem
         r.moveLeft(r.right());
         drawRating(painter, "Cockpit:", r, index.data(AircraftRatingRole + 2).toInt());
         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);
@@ -212,7 +213,9 @@ QSize AircraftItemDelegate::sizeHint(const QStyleOptionViewItem & option, const
 
     QSize thumbnailSize = index.data(AircraftThumbnailSizeRole).toSize();
     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;
     f.setPointSize(18);
     QFontMetrics metrics(f);
@@ -223,7 +226,8 @@ QSize AircraftItemDelegate::sizeHint(const QStyleOptionViewItem & option, const
     f.setPointSize(12);
     QFontMetrics smallMetrics(f);
 
-    QString authors = index.data(AircraftAuthorsRole).toString();
+    QString authors = QString("by: %1").arg(index.data(AircraftAuthorsRole).toString());
+
     if (!authors.isEmpty()) {
         textHeight += MARGIN;
         textHeight += smallMetrics.boundingRect(contentRect, Qt::TextWordWrap, authors).height();
@@ -237,14 +241,14 @@ QSize AircraftItemDelegate::sizeHint(const QStyleOptionViewItem & option, const
 
     if (index.data(AircraftHasRatingsRole).toBool()) {
         // ratings
-        textHeight += 48; // (24px per rating box)
+        int ratingHeight = qMax(24, smallMetrics.height() + MARGIN);
+        textHeight += ratingHeight * 2;
     } else {
         // just the button height
         textHeight += BUTTON_HEIGHT;
     }
 
     textHeight = qMax(textHeight, thumbnailSize.height());
-
     return QSize(option.rect.width(), textHeight + (MARGIN * 2));
 }
 
index 0ca5f1ebcfdc10953d9a4a9dc9176c9f98e68cef..2871da8e06a95ce74f4a8a9fc8f785793d015a66 100644 (file)
@@ -615,11 +615,19 @@ QVariant AircraftItemModel::dataFromPackage(const PackageRef& item, quint32 vari
 
     if ((role >= AircraftVariantDescriptionRole) && (role < AircraftThumbnailRole)) {
         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) {
-        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) {
         InstallRef i = item->existingInstall();
         if (i.valid()) {