Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_splash_screen.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 Boudewijn Rempt <boud@valdyas.org>
3 * SPDX-FileCopyrightText: 2021 Alvin Wong <alvin@alvinhc.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7#include "kis_splash_screen.h"
8
9#include <QApplication>
10#include <QScreen>
11#include <QGraphicsDropShadowEffect>
12#include <QPixmap>
13#include <QPainter>
14#include <QCheckBox>
15#include <kis_debug.h>
16#include <QFile>
17#include <QScreen>
18#include <QWindow>
19#include <QSvgWidget>
20
21#include <KisPart.h>
22#include <KisApplication.h>
23
24#include <kis_icon.h>
25
26#include <klocalizedstring.h>
27#include <kconfig.h>
28#include <ksharedconfig.h>
29#include <kconfiggroup.h>
30
31#ifdef Q_OS_MACOS
33#endif
34
35static void addDropShadow(QWidget *widget)
36{
37 QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(widget);
38 effect->setBlurRadius(4);
39 effect->setOffset(0.5);
40 effect->setColor(QColor(0, 0, 0, 255));
41 widget->setGraphicsEffect(effect);
42}
43
44KisSplashScreen::KisSplashScreen(bool themed, QWidget *parent, Qt::WindowFlags f)
45 : QWidget(parent, Qt::SplashScreen | Qt::FramelessWindowHint | f)
46 , m_themed(themed)
47 , m_versionHtml(qApp->applicationVersion().toHtmlEscaped())
48{
49
50 setupUi(this);
51#ifndef Q_OS_MACOS
52 setWindowIcon(KisIconUtils::loadIcon("krita-branding"));
53#endif
54
55 m_loadingTextLabel = new QLabel(lblSplash);
56 m_loadingTextLabel->setTextFormat(Qt::RichText);
57 m_loadingTextLabel->setStyleSheet(QStringLiteral("QLabel { color: #fff; background-color: transparent; }"));
58 m_loadingTextLabel->setAlignment(Qt::AlignRight | Qt::AlignTop);
60
61 m_brandingSvg = new QSvgWidget(QStringLiteral(":/krita-branding.svgz"), lblSplash);
62 m_bannerSvg = new QSvgWidget(QStringLiteral(":/splash/banner.svg"), lblSplash);
64
65 m_artCreditsLabel = new QLabel(lblSplash);
66 m_artCreditsLabel->setTextFormat(Qt::PlainText);
67 m_artCreditsLabel->setStyleSheet(QStringLiteral("QLabel { color: #fff; background-color: transparent; font: 10pt; }"));
68 m_artCreditsLabel->setAlignment(Qt::AlignRight | Qt::AlignBottom);
70
72 setLoadingText(QString());
73
74 bnClose->hide();
75 connect(bnClose, SIGNAL(clicked()), this, SLOT(close()));
76 chkShowAtStartup->hide();
77 connect(chkShowAtStartup, SIGNAL(toggled(bool)), this, SLOT(toggleShowAtStartup(bool)));
78
79 KConfigGroup cfg( KSharedConfig::openConfig(), "SplashScreen");
80 bool hideSplash = cfg.readEntry("HideSplashAfterStartup", false);
81 chkShowAtStartup->setChecked(hideSplash);
82
83 connect(lblRecent, SIGNAL(linkActivated(QString)), SLOT(linkClicked(QString)));
84 connect(&m_timer, SIGNAL(timeout()), SLOT(raise()));
85
86 // hide these labels by default
87 displayLinks(false);
88 displayRecentFiles(false);
89
90 m_timer.setSingleShot(true);
91 m_timer.start(10);
92}
93
95{
96 constexpr int SPLASH_HEIGHT_LOADING = 480;
97 constexpr int SPLASH_HEIGHT_ABOUT = 320;
98
99 int splashHeight;
100 if (m_displayLinks) {
101 splashHeight = SPLASH_HEIGHT_ABOUT;
102 } else {
103 splashHeight = SPLASH_HEIGHT_LOADING;
104 }
105 const int bannerHeight = splashHeight * 0.16875;
106 const int marginTop = splashHeight * 0.05;
107 const int marginRight = splashHeight * 0.1;
108
110 QPixmap img(source.resourcePath);
111
112 if (img.isNull() || img.height() == 0) return;
113
114 // Preserve aspect ratio of splash.
115 const int height = splashHeight;
116 const int width = height * img.width() / img.height();
117
118 setFixedWidth(width);
119 setFixedHeight(height);
120 lblSplash->setFixedWidth(width);
121 lblSplash->setFixedHeight(height);
122
123 // Get a downscaled pixmap of the splash.
124 const int pixelWidth = width * devicePixelRatioF();
125 const int pixelHeight = height * devicePixelRatioF();
126 img = img.scaled(pixelWidth, pixelHeight, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
127 img.setDevicePixelRatio(devicePixelRatioF());
128 lblSplash->setPixmap(img);
129
130 // Align banner to top-left with margin.
131 m_bannerSvg->setFixedHeight(bannerHeight);
132 m_bannerSvg->setFixedWidth(bannerHeight * m_bannerSvg->sizeHint().width() / m_bannerSvg->sizeHint().height());
133 m_bannerSvg->move(width - m_bannerSvg->width() - marginRight, marginTop);
134
135 // Place logo to the left of banner.
136 m_brandingSvg->setFixedSize(bannerHeight, bannerHeight);
137 m_brandingSvg->move(m_bannerSvg->x() - m_brandingSvg->width(), marginTop);
138
139 // Place loading text immediately below.
140 m_loadingTextLabel->move(marginRight, m_brandingSvg->geometry().bottom());
141 m_loadingTextLabel->setFixedWidth(m_bannerSvg->geometry().right() - marginRight);
142
143 // Place credits text on bottom right with similar margins.
144 m_artCreditsLabel->setText(source.artistCredit);
145 m_artCreditsLabel->setFixedWidth(m_loadingTextLabel->width());
146 m_artCreditsLabel->setFixedHeight(20);
147 m_artCreditsLabel->move(m_loadingTextLabel->x(), height - marginTop - m_artCreditsLabel->height());
148
149 if (m_displayLinks) {
150 setFixedSize(sizeHint());
151 }
152}
153
154void KisSplashScreen::resizeEvent(QResizeEvent *event)
155{
156 QWidget::resizeEvent(event);
157 updateText();
158}
159
161{
162 QString color = colorString();
163
164 KConfigGroup cfg2( KSharedConfig::openConfig(), "RecentFiles");
165 int i = 1;
166
167 QString recent = i18n("<html>"
168 "<head/>"
169 "<body>"
170 "<p><b><span style=\" color:%1;\">Recent Files</span></b></p>", color);
171
172 QString path;
173 QStringList recentfiles;
174
175 QFontMetrics metrics(lblRecent->font());
176
177 do {
178 path = cfg2.readPathEntry(QString("File%1").arg(i), QString());
179 if (!path.isEmpty()) {
180 QString name = cfg2.readPathEntry(QString("Name%1").arg(i), QString());
181 QUrl url(path);
182 if (name.isEmpty()) {
183 name = url.fileName();
184 }
185
186 name = metrics.elidedText(name, Qt::ElideMiddle, lblRecent->width());
187
188 if (!url.isLocalFile() || QFile::exists(url.toLocalFile())) {
189 recentfiles.insert(0, QString("<p><a href=\"%1\"><span style=\"color:%3;\">%2</span></a></p>").arg(path).arg(name).arg(color));
190 }
191 }
192
193 i++;
194 } while (!path.isEmpty() || i <= 8);
195
196 recent += recentfiles.join("\n");
197 recent += "</body>"
198 "</html>";
199 lblRecent->setText(recent);
200}
201
203
204 if (show) {
205 QString color = colorString();
206 QStringList lblLinksText;
207 lblLinksText << "<html>"
208 << "<head/>"
209 << "<body><table style=\"width:100%\" cellpadding=\"30\"><tr><td>"
210 << i18n("<p><span style=\" color:%1;\"><b>Using Krita</b></span></p>",color);
211
212#ifdef Q_OS_MACOS
213 // macOS store version should not contain external links containing donation buttons or forms
214 if (!KisMacosEntitlements().sandbox()) {
215#endif
216
217 lblLinksText << i18n("<p><a href=\"https://krita.org/support-us/\"><span style=\" text-decoration: underline; color:%1;\">Support Krita's Development!</span></a></p>",color)
218 << i18n("<p><a href=\"https://krita.org/\"><span style=\" text-decoration: underline; color:%1;\">Krita Website</span></a></p>",color);
219#ifdef Q_OS_MACOS
220 }
221#endif
222 lblLinksText << i18n("<p><a href=\"https://docs.krita.org/en/user_manual/getting_started.html\"><span style=\" text-decoration: underline; color:%1;\">Getting Started</span></a></p>",color)
223 << i18n("<p><a href=\"https://docs.krita.org/\"><span style=\" text-decoration: underline; color:%1;\">Manual</span></a></p>",color)
224 << "</td><td>"
225 << i18n("<p><span style=\" color:%1;\"><b>Coding Krita</b></span></p>",color)
226 << i18n("<p><a href=\"https://krita-artists.org\"><span style=\" text-decoration: underline; color:%1;\">User Community</span></a></p>",color)
227 << i18n("<p><a href=\"https://invent.kde.org/graphics/krita\"><span style=\" text-decoration: underline; color:%1;\">Source Code</span></a></p>",color)
228 << i18n("<p><a href=\"https://api.kde.org/krita/html/classKrita.html\"><span style=\" text-decoration: underline; color:%1;\">Scripting API</span></a></p>",color)
229 << i18n("<p><a href=\"https://scripting.krita.org/lessons/introduction\"><span style=\" text-decoration: underline; color:%1;\">Scripting School</span></a></p>",color)
230 << "</td></tr></table></body>"
231 << "</html>";
232
233
234 lblLinks->setTextFormat(Qt::RichText);
235 lblLinks->setText(lblLinksText.join(""));
236
237 filesLayout->setContentsMargins(10,10,10,10);
238 actionControlsLayout->setContentsMargins(5,5,5,5);
239
240 } else {
241 // eliminating margins here allows for the splash screen image to take the entire area with nothing underneath
242 filesLayout->setContentsMargins(0,0,0,0);
243 actionControlsLayout->setContentsMargins(0,0,0,0);
244 }
245
246 lblLinks->setVisible(show);
247
248 updateText();
249
250 if (m_displayLinks != show) {
253 }
254}
255
256
258 lblRecent->setVisible(show);
259 line->setVisible(show);
260}
261
263{
264 int larger = 12;
265 int notAsLarge = larger - 1;
266 QString htmlText = QStringLiteral("<span style='font: %3pt;'><span style='font: bold %4pt;'>%1</span><br><i>%2</i></span>")
267 .arg(m_versionHtml, text.toHtmlEscaped(), QString::number(notAsLarge), QString::number(larger));
268 m_loadingTextLabel->setText(htmlText);
269}
270
272{
273 QString artistCredit = i18nc("Normal splash artist name", "Tyson Tan");
274 // Loading the ginormous 4K PNG splash image increases the startup time on
275 // Android by several seconds and at the same time looks really bad when
276 // scaled down to a dinky size. Instead of overengineering this into an
277 // Enterprise Splash Screen Solution where we choose the image based on
278 // screen size or something, we'll just use a HD JPEG instead. It's fine.
279#ifdef Q_OS_ANDROID
280 QString resourcePath = QStringLiteral(":/splash/hd.jpg");
281#else
282 QString resourcePath = QStringLiteral(":/splash/0.png");
283 // TODO: Re-add the holiday splash...
284#if 0
285 QDate currentDate = QDate::currentDate();
286 if (currentDate > QDate(currentDate.year(), 12, 4) ||
287 currentDate < QDate(currentDate.year(), 1, 9)) {
288 resourcePath = QStringLiteral(":/splash/1.png");
289 artistCredit = QStringLiteral("???")};
290 }
291#endif
292#endif
293 if (!artistCredit.isEmpty()) {
294 artistCredit = i18nc("splash image credit", "Artwork by: %1", artistCredit);
295 }
296 return Source{resourcePath, artistCredit};
297}
298
299
301{
302 QString color = "#FFFFFF";
303 if (m_themed && qApp->palette().window().color().value() > 100) {
304 color = "#000000";
305 }
306
307 return color;
308}
309
310
312{
313 QWidget::repaint();
314 qApp->sendPostedEvents();
315}
316
318{
319 if (!this->parentWidget()) {
320 this->winId(); // Force creation of native window
321 QWindow *windowHandle = this->windowHandle();
322 QScreen *screen = windowHandle ? windowHandle->screen() : nullptr;
323 if (windowHandle && !screen) {
324 // At least on Windows, the window may be created on a non-primary
325 // screen with a different scale factor. If we don't explicitly
326 // move it to the primary screen, the position will be scaled with
327 // the wrong factor and the splash will be offset.
328 // XXX: In theory this branch should be unreachable, but leaving
329 // this here just in case.
330 windowHandle->setScreen(QApplication::primaryScreen());
331 }
332 if (!screen) {
333 screen = QApplication::primaryScreen();
334 }
335 // Reinitialize the splash image as the screen may have a different
336 // devicePixelRatio.
338 QRect r(QPoint(), size());
339 move(screen->availableGeometry().center() - r.center());
340 }
341 if (isVisible()) {
342 repaint();
343 }
344 m_timer.setSingleShot(true);
345 m_timer.start(1);
346 QWidget::show();
347}
348
350{
351 KConfigGroup cfg( KSharedConfig::openConfig(), "SplashScreen");
352 cfg.writeEntry("HideSplashAfterStartup", toggle);
353}
354
355void KisSplashScreen::linkClicked(const QString &link)
356{
358 if (isWindow()) {
359 close();
360 }
361}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
static KisPart * instance()
Definition KisPart.cpp:131
void openExistingFile(const QString &path)
Definition KisPart.cpp:513
void resizeEvent(QResizeEvent *event) override
static Source getImageSource()
void displayLinks(bool show)
void displayRecentFiles(bool show)
void setLoadingText(QString text)
QString colorString() const
void linkClicked(const QString &link)
QLabel * m_loadingTextLabel
QSvgWidget * m_brandingSvg
KisSplashScreen(bool themed=false, QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())
QSvgWidget * m_bannerSvg
void toggleShowAtStartup(bool toggle)
static void addDropShadow(QWidget *widget)
QIcon loadIcon(const QString &name)