From 2b7d3299d4e149f4be73cfc5f6aedc2a1ce7090a Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 16 Jul 2016 17:49:12 +0100 Subject: [PATCH] Improve rendering of longer parking names. --- src/GUI/AirportDiagram.cxx | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/GUI/AirportDiagram.cxx b/src/GUI/AirportDiagram.cxx index f5eaf7a07..6e07fb94b 100644 --- a/src/GUI/AirportDiagram.cxx +++ b/src/GUI/AirportDiagram.cxx @@ -399,13 +399,27 @@ void AirportDiagram::drawParking(QPainter* painter, const ParkingData& p) const painter->drawPath(useLeftIcon ? m_parkingIconLeftPath : m_parkingIconPath); - painter->fillRect(labelRect, Qt::white); + // ensure the selection colour is quite visible, by not filling + // with white when selected + if (p.parking != m_selectedParking) { + painter->fillRect(labelRect, Qt::white); + } + + QFont f = painter->font(); + f.setPixelSize(20); + painter->setFont(f); + + QString parkingName = QString::fromStdString(p.parking->name()); + int textFlags = Qt::AlignVCenter | Qt::AlignHCenter | Qt::TextWordWrap; + QRectF bounds = painter->boundingRect(labelRect, textFlags, parkingName); + if (bounds.height() > labelRect.height()) { + f.setPixelSize(10); + painter->setFont(f); + } // draw text painter->setPen(Qt::black); - painter->drawText(labelRect, - Qt::AlignVCenter | Qt::AlignHCenter, - QString::fromStdString(p.parking->name())); + painter->drawText(labelRect, textFlags, parkingName); } AirportDiagram::ParkingData AirportDiagram::findParkingData(const FGParkingRef &pk) const @@ -424,10 +438,6 @@ void AirportDiagram::drawParkings(QPainter* painter) const painter->save(); QTransform t = painter->transform(); - QFont f = painter->font(); - f.setPixelSize(16); - painter->setFont(f); - Q_FOREACH(const ParkingData& p, m_parking) { if (p.parking == m_selectedParking) { continue; // skip and draw last @@ -505,7 +515,6 @@ void AirportDiagram::mouseReleaseEvent(QMouseEvent* me) } } - Q_FOREACH(const HelipadData& pad, m_helipads) { QPainterPath pp = pathForHelipad(pad, t); if (pp.contains(me->pos())) { -- 2.39.5