]> git.mxchange.org Git - flightgear.git/commitdiff
GUI exclude support.
authorJames Turner <zakalawe@mac.com>
Mon, 16 Mar 2015 16:34:22 +0000 (17:34 +0100)
committerJames Turner <zakalawe@mac.com>
Fri, 10 Apr 2015 13:44:44 +0000 (14:44 +0100)
- visual refinements in the delegate.

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

index e950abf3c87a7cd3d9f071ba377dda9a5706c72d..b13a9500b4c4e77c4ccc1c145c1eb7b4ae148416 100644 (file)
@@ -68,6 +68,10 @@ void AircraftItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem
     painter->setBrush(Qt::NoBrush);
     painter->drawRect(contentRect.left(), yPos, thumbnail.width(), thumbnail.height());
 
+    // draw bottom dividing line
+    painter->drawLine(contentRect.left(), contentRect.bottom() + MARGIN,
+                      contentRect.right(), contentRect.bottom() + MARGIN);
+
     int variantCount = index.data(AircraftVariantCountRole).toInt();
     int currentVariant =index.data(AircraftVariantRole).toInt();
     QString description = index.data(Qt::DisplayRole).toString();
@@ -125,15 +129,17 @@ void AircraftItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem
     r.moveLeft(r.right());
     r.setHeight(24);
 
-    drawRating(painter, "Flight model:", r, index.data(AircraftRatingRole).toInt());
-    r.moveTop(r.bottom());
-    drawRating(painter, "Systems:", r, index.data(AircraftRatingRole + 1).toInt());
+    if (index.data(AircraftHasRatingsRole).toBool()) {
+        drawRating(painter, "Flight model:", r, index.data(AircraftRatingRole).toInt());
+        r.moveTop(r.bottom());
+        drawRating(painter, "Systems:", r, index.data(AircraftRatingRole + 1).toInt());
 
-    r.moveTop(actualBounds.bottom() + MARGIN);
-    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());
+        r.moveTop(actualBounds.bottom() + MARGIN);
+        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());
+    }
 
     QVariant v = index.data(AircraftPackageStatusRole);
     AircraftItemStatus status = static_cast<AircraftItemStatus>(v.toInt());
@@ -182,8 +188,13 @@ QSize AircraftItemDelegate::sizeHint(const QStyleOptionViewItem & option, const
         textHeight += smallMetrics.boundingRect(contentRect, Qt::TextWordWrap, desc).height();
     }
 
-    // ratings
-    textHeight += 48; // (24px per rating box)
+    if (index.data(AircraftHasRatingsRole).toBool()) {
+        // ratings
+        textHeight += 48; // (24px per rating box)
+    } else {
+        // just the button height
+        textHeight += BUTTON_HEIGHT;
+    }
 
     textHeight = qMax(textHeight, 128);
 
@@ -262,13 +273,13 @@ QRect AircraftItemDelegate::packageButtonRect(const QRect& visualRect, const QMo
     QPixmap thumbnail = index.data(Qt::DecorationRole).value<QPixmap>();
     contentRect.setLeft(contentRect.left() + MARGIN + thumbnail.width());
 
-    return QRect(contentRect.left() + ARROW_SIZE, contentRect.bottom() - 24, 60, 24);
+    return QRect(contentRect.left() + ARROW_SIZE, contentRect.bottom() - 24, 60, BUTTON_HEIGHT);
 }
 
 void AircraftItemDelegate::drawRating(QPainter* painter, QString label, const QRect& box, int value) const
 {
     const int DOT_SIZE = 10;
-    const int DOT_MARGIN = 4;
+    const int DOT_MARGIN = 2;
 
     QRect dotBox = box;
     dotBox.setLeft(box.right() - (DOT_MARGIN * 6 + DOT_SIZE * 5));
index 0a5f3f609b0a03d3fac476067a5627504cecc9eb..f2a3988721ff34d856eda9908c54437c71535cbb 100644 (file)
@@ -31,6 +31,7 @@ class AircraftItemDelegate : public QStyledItemDelegate
 public:
     static const int MARGIN = 4;
     static const int ARROW_SIZE = 20;
+    static const int BUTTON_HEIGHT = 24;
 
     AircraftItemDelegate(QListView* view);
     
index a7e2b00cdf33813b2b0d91047ea2204742833505..e357bb02ed24a2916dcce75c6014bdea13b9e8f7 100644 (file)
 
 using namespace simgear::pkg;
 
-AircraftItem::AircraftItem()
+AircraftItem::AircraftItem() :
+    excluded(false)
 {
     // oh for C++11 initialisers
     for (int i=0; i<4; ++i) ratings[i] = 0;
 }
 
-AircraftItem::AircraftItem(QDir dir, QString filePath)
+AircraftItem::AircraftItem(QDir dir, QString filePath) :
+    excluded(false)
 {
     for (int i=0; i<4; ++i) ratings[i] = 0;
 
@@ -62,6 +64,10 @@ AircraftItem::AircraftItem(QDir dir, QString filePath)
 
     path = filePath;
     pathModTime = QFileInfo(path).lastModified();
+    if (sim->getBoolValue("exclude-from-gui", false)) {
+        excluded = true;
+        return;
+    }
 
     description = sim->getStringValue("description");
     authors =  sim->getStringValue("author");
@@ -89,16 +95,24 @@ QString AircraftItem::baseName() const
 
 void AircraftItem::fromDataStream(QDataStream& ds)
 {
-    ds >> path >> description >> authors >> variantOf;
+    ds >> path >> pathModTime >> excluded;
+    if (excluded) {
+        return;
+    }
+
+    ds >> description >> authors >> variantOf;
     for (int i=0; i<4; ++i) ds >> ratings[i];
-    ds >> pathModTime;
 }
 
 void AircraftItem::toDataStream(QDataStream& ds) const
 {
-    ds << path << description << authors << variantOf;
+    ds << path << pathModTime << excluded;
+    if (excluded) {
+        return;
+    }
+
+    ds << description << authors << variantOf;
     for (int i=0; i<4; ++i) ds << ratings[i];
-    ds << pathModTime;
 }
 
 QPixmap AircraftItem::thumbnail() const
@@ -119,7 +133,7 @@ QPixmap AircraftItem::thumbnail() const
 }
 
 
-static int CACHE_VERSION = 2;
+static int CACHE_VERSION = 3;
 
 class AircraftScanThread : public QThread
 {
@@ -239,6 +253,10 @@ private:
 
                     m_nextCache[absolutePath] = item;
 
+                    if (item->excluded) {
+                        continue;
+                    }
+
                     if (item->variantOf.isNull()) {
                         baseAircraft.insert(item->baseName(), item);
                     } else {
@@ -394,6 +412,12 @@ QVariant AircraftItemModel::dataFromItem(const AircraftItem* item, quint32 varia
         return PackageInstalled; // always the case
     } else if (role == Qt::ToolTipRole) {
         return item->path;
+    } else if (role == AircraftHasRatingsRole) {
+        bool have = false;
+        for (int i=0; i<4; ++i) {
+            have |= (item->ratings[i] > 0);
+        }
+        return have;
     } else if (role == AircraftLongDescriptionRole) {
         return "Lorum Ipsum, etc. Is this the real life? Is this just fantasy? Caught in a land-slide, "
             "no escape from reality. Open your eyes, like up to the skies and see. "
index 6ce2583338567965da94a567910795f5ecd0b738..c1bb77cf07b7147186521806f894d0b164b5d14c 100644 (file)
@@ -38,6 +38,7 @@ const int AircraftPackageIdRole = Qt::UserRole + 6;
 const int AircraftPackageStatusRole = Qt::UserRole + 7;
 const int AircraftPackageProgressRole = Qt::UserRole + 8;
 const int AircraftLongDescriptionRole = Qt::UserRole + 9;
+const int AircraftHasRatingsRole = Qt::UserRole + 10;
 
 const int AircraftRatingRole = Qt::UserRole + 100;
 const int AircraftVariantDescriptionRole = Qt::UserRole + 200;
@@ -61,6 +62,7 @@ struct AircraftItem
 
     QPixmap thumbnail() const;
 
+    bool excluded;
     QString path;
     QString description;
     QString authors;