]> git.mxchange.org Git - flightgear.git/commitdiff
Fixes to launcher aircraft thumbnail sizing
authorJames Turner <zakalawe@mac.com>
Tue, 10 Nov 2015 23:28:24 +0000 (23:28 +0000)
committerJames Turner <zakalawe@mac.com>
Mon, 23 Nov 2015 00:47:01 +0000 (00:47 +0000)
- handle large images and longer descriptions correctly

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

index f07cbee4c9d7973fef26b800ae4695bcb70b6906..7e45801a5f4d39711a0c5793597662878bbcff96 100644 (file)
@@ -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<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);
@@ -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));
 }
index 56a5c64c63938c3db0ef3f83482392c4c914e4e0..3b156e701c0573cca3575f7fd0dd08c4c19d8fe4 100644 (file)
@@ -40,7 +40,9 @@
 // FlightGear
 #include <Main/globals.hxx>
 
+
 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<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) {
@@ -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();
 }
 
index 975e6808c7823ca0f553205859377b602e308bf0..43208253d2c8f168b5f455229b820e7bcfe1adbe 100644 (file)
@@ -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();