Skip to content

Commit

Permalink
Make all splash screen text scalable
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Jan 25, 2025
1 parent 2cab699 commit 333c4c0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
Binary file modified data/splash-gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 42 additions & 3 deletions src/StelSplashScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,51 @@ void SplashScreen::SplashScreenWidget::paintEvent(QPaintEvent* event)
{
QSplashScreen::paintEvent(event);

// Add version text
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(Qt::white);

// Add branding text: "Stellarium" in large bold font centered horizontally,
// and "stellarium.org" under it in a smaller font, both aligned to each
// other on the right side.
QFont font("Sans");
font.setPixelSize(55 * sizeRatio);
font.setWeight(QFont::Bold);
static const QString titleText = "Stellarium";
QFontMetrics titleFM(font);
auto titleBR = titleFM.tightBoundingRect(titleText);
const double maxWidth = sizeRatio * 310;
if(titleBR.width() > maxWidth)
{
font.setStretch(QFont::SemiCondensed);
titleFM = QFontMetrics(font);
titleBR = titleFM.tightBoundingRect(titleText);
}
if(titleBR.width() > maxWidth)
{
font.setStretch(QFont::Condensed);
titleFM = QFontMetrics(font);
titleBR = titleFM.tightBoundingRect(titleText);
}
p.setFont(font);
const QPoint titlePos((width() - titleBR.width()) / 2,
std::lround(height() * 0.89));
titleBR.translate(titlePos);
p.drawText(titlePos, titleText);
font.setWeight(QFont::Normal);
font.setPixelSize(18 * sizeRatio);
p.setFont(font);
static const QString subtitleText = "stellarium.org";
const QFontMetrics subtitleFM(font);
const auto subtitleBR = subtitleFM.tightBoundingRect(subtitleText);
p.drawText(QPoint(titleBR.right() - subtitleBR.width() - 1,
titleBR.bottom() + subtitleBR.height()),
subtitleText);

// Add version text
#if defined(GIT_REVISION)
QFontMetrics metrics(splashFont);
p.setFont(this->font());
p.drawText(QPointF(metrics.averageCharWidth(), 1.3*metrics.height()), QString("%1+ (v%2)").arg(StelUtils::getApplicationPublicVersion(), StelUtils::getApplicationVersion()));
#else
QFont versionFont(splashFont);
Expand All @@ -100,8 +139,8 @@ void SplashScreen::SplashScreenWidget::paintEvent(QPaintEvent* event)
versionFont.setBold(true);
QFontMetrics versionMetrics(versionFont);
p.setFont(versionFont);
const int height = BASE_PIXMAP_HEIGHT * sizeRatio;
p.drawText(height - versionMetrics.horizontalAdvance(version), 0.803 * height, version);
p.drawText(titleBR.right() - versionMetrics.tightBoundingRect(version).width() - 1,
0.8 * height(), version);
#endif

painted=true;
Expand Down

0 comments on commit 333c4c0

Please sign in to comment.