mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 15:15:39 +08:00
Allow to rescale airline icons (actually all icons)
This commit is contained in:
@@ -61,7 +61,7 @@ namespace BlackGui
|
|||||||
const QMetaType::Type type = static_cast<QMetaType::Type>(dataCVariant.type());
|
const QMetaType::Type type = static_cast<QMetaType::Type>(dataCVariant.type());
|
||||||
|
|
||||||
if (type == QMetaType::QPixmap) { return dataCVariant; }
|
if (type == QMetaType::QPixmap) { return dataCVariant; }
|
||||||
if (type == QMetaType::QIcon) { return dataCVariant; }
|
if (type == QMetaType::QIcon) { return dataCVariant; }
|
||||||
|
|
||||||
// convert to pixmap
|
// convert to pixmap
|
||||||
if (type == QMetaType::QImage)
|
if (type == QMetaType::QImage)
|
||||||
@@ -71,9 +71,9 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Our CIcon class
|
// Our CIcon class
|
||||||
if (dataCVariant.canConvert<BlackMisc::CIcon>())
|
if (dataCVariant.canConvert<CIcon>())
|
||||||
{
|
{
|
||||||
const CIcon i = dataCVariant.value<BlackMisc::CIcon>();
|
const CIcon i = dataCVariant.value<CIcon>();
|
||||||
return CVariant::from(i.toPixmap());
|
return CVariant::from(i.toPixmap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,20 +157,49 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
Q_UNUSED(dataCVariant);
|
Q_UNUSED(dataCVariant);
|
||||||
Q_ASSERT_X(false, "CPixmapFormatter", "this role should be disabled with pixmaps");
|
Q_ASSERT_X(false, "CPixmapFormatter", "this role should be disabled with pixmaps");
|
||||||
return CVariant();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
CVariant CPixmapFormatter::tooltipRole(const CVariant &dataCVariant) const
|
CVariant CPixmapFormatter::tooltipRole(const CVariant &dataCVariant) const
|
||||||
{
|
{
|
||||||
if (dataCVariant.isNull()) return {};
|
if (dataCVariant.isNull()) { return {}; }
|
||||||
if (dataCVariant.canConvert<BlackMisc::CIcon>())
|
if (dataCVariant.canConvert<CIcon>())
|
||||||
{
|
{
|
||||||
BlackMisc::CIcon icon = dataCVariant.value<BlackMisc::CIcon>();
|
const CIcon icon = dataCVariant.value<CIcon>();
|
||||||
return icon.getDescriptiveText();
|
return icon.getDescriptiveText();
|
||||||
}
|
}
|
||||||
return emptyStringVariant();
|
return emptyStringVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CVariant CPixmapFormatter::decorationRole(const CVariant &dataCVariant) const
|
||||||
|
{
|
||||||
|
if (dataCVariant.isNull()) { return {}; }
|
||||||
|
if (m_maxWidth < 0 && m_maxHeight < 0) { return CDefaultFormatter::decorationRole(dataCVariant); }
|
||||||
|
|
||||||
|
QPixmap pm;
|
||||||
|
if (dataCVariant.canConvert<CIcon>())
|
||||||
|
{
|
||||||
|
const CIcon icon = dataCVariant.value<CIcon>();
|
||||||
|
pm = icon.toPixmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pm.isNull()) { return {}; }
|
||||||
|
const int pmw = pm.width();
|
||||||
|
const int pmh = pm.height();
|
||||||
|
|
||||||
|
if (m_maxHeight >= 0 && m_maxHeight < pmh)
|
||||||
|
{
|
||||||
|
return CVariant::fromValue(pm.scaledToHeight(m_maxHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_maxWidth >= 0 && m_maxWidth < pmw)
|
||||||
|
{
|
||||||
|
return CVariant::fromValue(pm.scaledToWidth(m_maxWidth));
|
||||||
|
}
|
||||||
|
|
||||||
|
return CVariant::fromValue(pm);
|
||||||
|
}
|
||||||
|
|
||||||
CVariant CValueObjectFormatter::displayRole(const CVariant &valueObject) const
|
CVariant CValueObjectFormatter::displayRole(const CVariant &valueObject) const
|
||||||
{
|
{
|
||||||
return CVariant(valueObject.toQString(m_useI18n));
|
return CVariant(valueObject.toQString(m_useI18n));
|
||||||
|
|||||||
@@ -141,6 +141,20 @@ namespace BlackGui
|
|||||||
|
|
||||||
//! \copydoc CDefaultFormatter::tooltipRole
|
//! \copydoc CDefaultFormatter::tooltipRole
|
||||||
virtual BlackMisc::CVariant tooltipRole(const BlackMisc::CVariant &dataCVariant) const override;
|
virtual BlackMisc::CVariant tooltipRole(const BlackMisc::CVariant &dataCVariant) const override;
|
||||||
|
|
||||||
|
//! \copydoc CDefaultFormatter::decorationRole
|
||||||
|
virtual BlackMisc::CVariant decorationRole(const BlackMisc::CVariant &dataCVariant) const override;
|
||||||
|
|
||||||
|
//! Width/height @{
|
||||||
|
int getMaxWidth() const { return m_maxWidth; }
|
||||||
|
int getMaxHeight() const { return m_maxHeight; }
|
||||||
|
void setMaxWidth(int w) { m_maxWidth = w; }
|
||||||
|
void setMaxHeight(int h) { m_maxHeight = h; }
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_maxWidth = -1;
|
||||||
|
int m_maxHeight = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! String formatter, if known the variant already contains the appropriate string
|
//! String formatter, if known the variant already contains the appropriate string
|
||||||
|
|||||||
@@ -68,7 +68,10 @@ namespace BlackGui
|
|||||||
m_columns.addColumn(CColumn::standardString("icao", "icao and livery info", { CSimulatedAircraft::IndexCombinedIcaoLiveryStringNetworkModel}));
|
m_columns.addColumn(CColumn::standardString("icao", "icao and livery info", { CSimulatedAircraft::IndexCombinedIcaoLiveryStringNetworkModel}));
|
||||||
|
|
||||||
// icon column for airline
|
// icon column for airline
|
||||||
CColumn col("airline", { CSimulatedAircraft::IndexNetworkModel, CAircraftModel::IndexLivery, CLivery::IndexAirlineIcaoCode, CAirlineIcaoCode::IndexIcon });
|
CPixmapFormatter *pmf = new CPixmapFormatter();
|
||||||
|
pmf->setMaxHeight(25);
|
||||||
|
pmf->setMaxWidth(100);
|
||||||
|
CColumn col("airline", { CSimulatedAircraft::IndexNetworkModel, CAircraftModel::IndexLivery, CLivery::IndexAirlineIcaoCode, CAirlineIcaoCode::IndexIcon }, pmf);
|
||||||
col.setSortPropertyIndex({ CSimulatedAircraft::IndexNetworkModel, CAircraftModel::IndexLivery, CLivery::IndexAirlineIcaoCode, CAirlineIcaoCode::IndexAirlineDesignator});
|
col.setSortPropertyIndex({ CSimulatedAircraft::IndexNetworkModel, CAircraftModel::IndexLivery, CLivery::IndexAirlineIcaoCode, CAirlineIcaoCode::IndexAirlineDesignator});
|
||||||
m_columns.addColumn(col);
|
m_columns.addColumn(col);
|
||||||
|
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
if (this->isGenerated()) { return m_pixmap; }
|
if (this->isGenerated()) { return m_pixmap; }
|
||||||
if (this->isFileBased()) { return m_pixmap; }
|
if (this->isFileBased()) { return m_pixmap; }
|
||||||
return CIcons::pixmapByIndex(getIndex(), m_rotateDegrees);
|
return CIcons::pixmapByIndex(this->getIndex(), m_rotateDegrees);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return CIcons::pixmapByIndex(getIndex());
|
return CIcons::pixmapByIndex(this->getIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user