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 setWindowIcon(KisIconUtils::loadIcon("krita-branding"));
52
53 m_loadingTextLabel = new QLabel(lblSplash);
54 m_loadingTextLabel->setTextFormat(Qt::RichText);
55 m_loadingTextLabel->setStyleSheet(QStringLiteral("QLabel { color: #fff; background-color: transparent; }"));
56 m_loadingTextLabel->setAlignment(Qt::AlignRight | Qt::AlignTop);
58
59 m_brandingSvg = new QSvgWidget(QStringLiteral(":/krita-branding.svgz"), lblSplash);
60 m_bannerSvg = new QSvgWidget(QStringLiteral(":/splash/banner.svg"), lblSplash);
62
63 m_artCreditsLabel = new QLabel(lblSplash);
64 m_artCreditsLabel->setTextFormat(Qt::PlainText);
65 m_artCreditsLabel->setStyleSheet(QStringLiteral("QLabel { color: #fff; background-color: transparent; font: 10pt; }"));
66 m_artCreditsLabel->setAlignment(Qt::AlignRight | Qt::AlignBottom);
68
70 setLoadingText(QString());
71
72 bnClose->hide();
73 connect(bnClose, SIGNAL(clicked()), this, SLOT(close()));
74 chkShowAtStartup->hide();
75 connect(chkShowAtStartup, SIGNAL(toggled(bool)), this, SLOT(toggleShowAtStartup(bool)));
76
77 KConfigGroup cfg( KSharedConfig::openConfig(), "SplashScreen");
78 bool hideSplash = cfg.readEntry("HideSplashAfterStartup", false);
79 chkShowAtStartup->setChecked(hideSplash);
80
81 connect(lblRecent, SIGNAL(linkActivated(QString)), SLOT(linkClicked(QString)));
82 connect(&m_timer, SIGNAL(timeout()), SLOT(raise()));
83
84 // hide these labels by default
85 displayLinks(false);
86 displayRecentFiles(false);
87
88 m_timer.setSingleShot(true);
89 m_timer.start(10);
90}
91
93{
94 constexpr int SPLASH_HEIGHT_LOADING = 480;
95 constexpr int SPLASH_HEIGHT_ABOUT = 320;
96
97 int splashHeight;
98 if (m_displayLinks) {
99 splashHeight = SPLASH_HEIGHT_ABOUT;
100 } else {
101 splashHeight = SPLASH_HEIGHT_LOADING;
102 }
103 const int bannerHeight = splashHeight * 0.16875;
104 const int marginTop = splashHeight * 0.05;
105 const int marginRight = splashHeight * 0.1;
106
107 QString splashName = QStringLiteral(":/splash/0.png");
108 QString splashArtist = QStringLiteral("Tyson Tan");
109 // TODO: Re-add the holiday splash...
110#if 0
111 QDate currentDate = QDate::currentDate();
112 if (currentDate > QDate(currentDate.year(), 12, 4) ||
113 currentDate < QDate(currentDate.year(), 1, 9)) {
114 splashName = QStringLiteral(":/splash/1.png");
115 splashArtist = QStringLiteral("???");
116 }
117#endif
118
119 QPixmap img(splashName);
120
121 if (img.isNull() || img.height() == 0) return;
122
123 // Preserve aspect ratio of splash.
124 const int height = splashHeight;
125 const int width = height * img.width() / img.height();
126
127 setFixedWidth(width);
128 setFixedHeight(height);
129 lblSplash->setFixedWidth(width);
130 lblSplash->setFixedHeight(height);
131
132 // Get a downscaled pixmap of the splash.
133 const int pixelWidth = width * devicePixelRatioF();
134 const int pixelHeight = height * devicePixelRatioF();
135 img = img.scaled(pixelWidth, pixelHeight, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
136 img.setDevicePixelRatio(devicePixelRatioF());
137 lblSplash->setPixmap(img);
138
139 // Align banner to top-left with margin.
140 m_bannerSvg->setFixedHeight(bannerHeight);
141 m_bannerSvg->setFixedWidth(bannerHeight * m_bannerSvg->sizeHint().width() / m_bannerSvg->sizeHint().height());
142 m_bannerSvg->move(width - m_bannerSvg->width() - marginRight, marginTop);
143
144 // Place logo to the left of banner.
145 m_brandingSvg->setFixedSize(bannerHeight, bannerHeight);
146 m_brandingSvg->move(m_bannerSvg->x() - m_brandingSvg->width(), marginTop);
147
148 // Place loading text immediately below.
149 m_loadingTextLabel->move(marginRight, m_brandingSvg->geometry().bottom());
150 m_loadingTextLabel->setFixedWidth(m_bannerSvg->geometry().right() - marginRight);
151
152 // Place credits text on bottom right with similar margins.
153 if (splashArtist.isEmpty()) {
154 m_artCreditsLabel->setText(QString());
155 } else {
156 m_artCreditsLabel->setText(i18nc("splash image credit", "Artwork by: %1", splashArtist));
157 }
158 m_artCreditsLabel->setFixedWidth(m_loadingTextLabel->width());
159 m_artCreditsLabel->setFixedHeight(20);
160 m_artCreditsLabel->move(m_loadingTextLabel->x(), height - marginTop - m_artCreditsLabel->height());
161
162 if (m_displayLinks) {
163 setFixedSize(sizeHint());
164 }
165}
166
167void KisSplashScreen::resizeEvent(QResizeEvent *event)
168{
169 QWidget::resizeEvent(event);
170 updateText();
171}
172
174{
175 QString color = colorString();
176
177 KConfigGroup cfg2( KSharedConfig::openConfig(), "RecentFiles");
178 int i = 1;
179
180 QString recent = i18n("<html>"
181 "<head/>"
182 "<body>"
183 "<p><b><span style=\" color:%1;\">Recent Files</span></b></p>", color);
184
185 QString path;
186 QStringList recentfiles;
187
188 QFontMetrics metrics(lblRecent->font());
189
190 do {
191 path = cfg2.readPathEntry(QString("File%1").arg(i), QString());
192 if (!path.isEmpty()) {
193 QString name = cfg2.readPathEntry(QString("Name%1").arg(i), QString());
194 QUrl url(path);
195 if (name.isEmpty()) {
196 name = url.fileName();
197 }
198
199 name = metrics.elidedText(name, Qt::ElideMiddle, lblRecent->width());
200
201 if (!url.isLocalFile() || QFile::exists(url.toLocalFile())) {
202 recentfiles.insert(0, QString("<p><a href=\"%1\"><span style=\"color:%3;\">%2</span></a></p>").arg(path).arg(name).arg(color));
203 }
204 }
205
206 i++;
207 } while (!path.isEmpty() || i <= 8);
208
209 recent += recentfiles.join("\n");
210 recent += "</body>"
211 "</html>";
212 lblRecent->setText(recent);
213}
214
216
217 if (show) {
218 QString color = colorString();
219 QStringList lblLinksText;
220 lblLinksText << "<html>"
221 << "<head/>"
222 << "<body><table style=\"width:100%\" cellpadding=\"30\"><tr><td>"
223 << i18n("<p><span style=\" color:%1;\"><b>Using Krita</b></span></p>",color);
224
225#ifdef Q_OS_MACOS
226 // macOS store version should not contain external links containing donation buttons or forms
227 if (!KisMacosEntitlements().sandbox()) {
228#endif
229
230 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)
231 << i18n("<p><a href=\"https://krita.org/\"><span style=\" text-decoration: underline; color:%1;\">Krita Website</span></a></p>",color);
232#ifdef Q_OS_MACOS
233 }
234#endif
235 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)
236 << i18n("<p><a href=\"https://docs.krita.org/\"><span style=\" text-decoration: underline; color:%1;\">Manual</span></a></p>",color)
237 << "</td><td>"
238 << i18n("<p><span style=\" color:%1;\"><b>Coding Krita</b></span></p>",color)
239 << i18n("<p><a href=\"https://krita-artists.org\"><span style=\" text-decoration: underline; color:%1;\">User Community</span></a></p>",color)
240 << i18n("<p><a href=\"https://invent.kde.org/graphics/krita\"><span style=\" text-decoration: underline; color:%1;\">Source Code</span></a></p>",color)
241 << 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)
242 << i18n("<p><a href=\"https://scripting.krita.org/lessons/introduction\"><span style=\" text-decoration: underline; color:%1;\">Scripting School</span></a></p>",color)
243 << "</td></tr></table></body>"
244 << "</html>";
245
246
247 lblLinks->setTextFormat(Qt::RichText);
248 lblLinks->setText(lblLinksText.join(""));
249
250 filesLayout->setContentsMargins(10,10,10,10);
251 actionControlsLayout->setContentsMargins(5,5,5,5);
252
253 } else {
254 // eliminating margins here allows for the splash screen image to take the entire area with nothing underneath
255 filesLayout->setContentsMargins(0,0,0,0);
256 actionControlsLayout->setContentsMargins(0,0,0,0);
257 }
258
259 lblLinks->setVisible(show);
260
261 updateText();
262
263 if (m_displayLinks != show) {
266 }
267}
268
269
271 lblRecent->setVisible(show);
272 line->setVisible(show);
273}
274
276{
277 int larger = 12;
278 int notAsLarge = larger - 1;
279 QString htmlText = QStringLiteral("<span style='font: %3pt;'><span style='font: bold %4pt;'>%1</span><br><i>%2</i></span>")
280 .arg(m_versionHtml, text.toHtmlEscaped(), QString::number(notAsLarge), QString::number(larger));
281 m_loadingTextLabel->setText(htmlText);
282}
283
284
285
287{
288 QString color = "#FFFFFF";
289 if (m_themed && qApp->palette().window().color().value() > 100) {
290 color = "#000000";
291 }
292
293 return color;
294}
295
296
298{
299 QWidget::repaint();
300 qApp->sendPostedEvents();
301}
302
304{
305 if (!this->parentWidget()) {
306 this->winId(); // Force creation of native window
307 QWindow *windowHandle = this->windowHandle();
308 QScreen *screen = windowHandle ? windowHandle->screen() : nullptr;
309 if (windowHandle && !screen) {
310 // At least on Windows, the window may be created on a non-primary
311 // screen with a different scale factor. If we don't explicitly
312 // move it to the primary screen, the position will be scaled with
313 // the wrong factor and the splash will be offset.
314 // XXX: In theory this branch should be unreachable, but leaving
315 // this here just in case.
316 windowHandle->setScreen(QApplication::primaryScreen());
317 }
318 if (!screen) {
319 screen = QApplication::primaryScreen();
320 }
321 // Reinitialize the splash image as the screen may have a different
322 // devicePixelRatio.
324 QRect r(QPoint(), size());
325 move(screen->availableGeometry().center() - r.center());
326 }
327 if (isVisible()) {
328 repaint();
329 }
330 m_timer.setSingleShot(true);
331 m_timer.start(1);
332 QWidget::show();
333}
334
336{
337 KConfigGroup cfg( KSharedConfig::openConfig(), "SplashScreen");
338 cfg.writeEntry("HideSplashAfterStartup", toggle);
339}
340
341void KisSplashScreen::linkClicked(const QString &link)
342{
344 if (isTopLevel()) {
345 close();
346 }
347}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static KisPart * instance()
Definition KisPart.cpp:131
void openExistingFile(const QString &path)
Definition KisPart.cpp:537
void resizeEvent(QResizeEvent *event) override
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)