10#include <spdlog/spdlog.h>
14#include <QFontMetrics>
19 : QSplashScreen(screen, QPixmap())
21 setupPixmap(image_path, screen);
24void SplashScreen::setupPixmap(
const QString& image_path, QScreen* screen)
26 QPixmap original_logo {image_path};
27 if (original_logo.isNull())
29 spdlog::error(
"Splash screen logo NOT FOUND at {}", qPrintable(image_path));
30 original_logo = QPixmap {400, 400};
31 original_logo.fill(Qt::white);
34 const qreal dpr {screen ? screen->devicePixelRatio() : 1.0};
36 const int target_width {700};
37 const int target_height {380};
38 const int bottom_padding {45};
40 QPixmap final_pixmap {
static_cast<int>(target_width * dpr),
static_cast<int>((target_height + bottom_padding) * dpr)};
41 final_pixmap.setDevicePixelRatio(dpr);
42 final_pixmap.fill(Qt::white);
44 QPainter painter {&final_pixmap};
45 painter.setRenderHint(QPainter::SmoothPixmapTransform,
true);
47 painter.drawPixmap(0, 0, target_width, target_height, original_logo);
51 setPixmap(final_pixmap);
56 m_current_message = message;
57 m_alignment = alignment;
61 QSplashScreen::showMessage(message, alignment, color);
66 const int8_t margin {15};
67 const int bottom_zone_height {45};
69 QRect text_rect {this->rect()};
70 text_rect.setTop(text_rect.bottom() - bottom_zone_height);
71 text_rect.setBottom(text_rect.bottom() - margin);
72 text_rect.setLeft(text_rect.left() + margin);
73 text_rect.setRight(text_rect.right() - margin);
75 QFont slogan_font {
"Segoe UI", 10};
76 painter->setFont(slogan_font);
77 painter->setPen(Qt::black);
78 painter->setOpacity(0.9);
80 const QString slogan {tr(
"Capture Moment - A photographic moment, captured freely.")};
81 painter->drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, slogan);
83 if (!m_current_message.isEmpty())
85 QFont status_font {
"Segoe UI", 9};
86 status_font.setItalic(
true);
87 painter->setFont(status_font);
88 painter->setPen(Qt::black);
89 painter->setOpacity(0.9);
91 painter->drawText(text_rect, Qt::AlignRight | Qt::AlignVCenter, m_current_message);
94 painter->setOpacity(1.0);
void showMessage(const QString &message, int alignment=Qt::AlignBottom|Qt::AlignHCenter, const QColor &color=Qt::darkGray)
Updates the loading status message displayed on the splash screen.
void drawContents(QPainter *painter) override
Draws the custom contents (the status message) over the pixmap.
SplashScreen(const QString &image_path=":/splash/splash-screen.png", QScreen *screen=nullptr)
Constructor for the splash screen.
Splash screen class for application startup.