CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
splash_screen.cpp
Go to the documentation of this file.
1
9
10#include <spdlog/spdlog.h>
11
12#include <QPainter>
13#include <QScreen>
14#include <QFontMetrics>
15
16namespace CaptureMoment::UI {
17
18SplashScreen::SplashScreen(const QString& image_path, QScreen* screen)
19 : QSplashScreen(screen, QPixmap())
20{
21 setupPixmap(image_path, screen);
22}
23
24void SplashScreen::setupPixmap(const QString& image_path, QScreen* screen)
25{
26 QPixmap original_logo {image_path};
27 if (original_logo.isNull())
28 {
29 spdlog::error("Splash screen logo NOT FOUND at {}", qPrintable(image_path));
30 original_logo = QPixmap {400, 400};
31 original_logo.fill(Qt::white);
32 }
33
34 const qreal dpr {screen ? screen->devicePixelRatio() : 1.0};
35
36 const int target_width {700};
37 const int target_height {380};
38 const int bottom_padding {45};
39
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);
43
44 QPainter painter {&final_pixmap};
45 painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
46
47 painter.drawPixmap(0, 0, target_width, target_height, original_logo);
48
49 painter.end();
50
51 setPixmap(final_pixmap);
52}
53
54void SplashScreen::showMessage(const QString& message, int alignment, const QColor& color)
55{
56 m_current_message = message;
57 m_alignment = alignment;
58 m_color = color;
59
60 // Call base class to trigger the repaint (which calls drawContents)
61 QSplashScreen::showMessage(message, alignment, color);
62}
63
64void SplashScreen::drawContents(QPainter* painter)
65{
66 const int8_t margin {15};
67 const int bottom_zone_height {45};
68
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);
74
75 QFont slogan_font {"Segoe UI", 10};
76 painter->setFont(slogan_font);
77 painter->setPen(Qt::black);
78 painter->setOpacity(0.9);
79
80 const QString slogan {tr("Capture Moment - A photographic moment, captured freely.")};
81 painter->drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, slogan);
82
83 if (!m_current_message.isEmpty())
84 {
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);
90
91 painter->drawText(text_rect, Qt::AlignRight | Qt::AlignVCenter, m_current_message);
92 }
93
94 painter->setOpacity(1.0);
95}
96
97} // namespace CaptureMoment::UI
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.
CaptureMoment — footer