1
0
Fork 0

GUI exclude support.

- visual refinements in the delegate.
This commit is contained in:
James Turner 2015-03-16 17:34:22 +01:00
parent d170de1909
commit 41ca6bd1de
4 changed files with 57 additions and 19 deletions

View 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));

View 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);

View file

@ -41,13 +41,15 @@
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. "

View 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;