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 <QWindow>
18#include <QSvgWidget>
19#include <QVBoxLayout>
20#include <QLabel>
21
22#include <KisPart.h>
23#include <KisApplication.h>
24
25#include <kis_icon.h>
26#include <kis_config.h>
27
28#include <klocalizedstring.h>
29
30#ifdef Q_OS_ANDROID
31#include <KisAndroidDonations.h>
32#endif
33
34static void addDropShadow(QWidget *widget)
35{
36 QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(widget);
37 effect->setBlurRadius(4);
38 effect->setOffset(0.5);
39 effect->setColor(QColor(0, 0, 0, 255));
40 widget->setGraphicsEffect(effect);
41}
42
44{
45 QString text = title;
46 if (isAvailable) {
47 if (isDefault) {
48 return i18nc("Splash image default", "%1 (default)", text);
49 } else {
50 return text;
51 }
52 } else {
53 return i18nc("Splash image unavailable", "%1 (not available)", text);
54 }
55}
56
58{
59 if (artistName.isEmpty()) {
60 return QString();
61 } else {
62 return i18nc("splash image credit", "Artwork by: %1", artistName);
63 }
64}
65
66KisSplashScreen::KisSplashScreen(int height, QWidget *parent, Qt::WindowFlags f)
67 : QWidget(parent, f)
68 , m_versionHtml(qApp->applicationVersion().toHtmlEscaped())
69{
70 setWindowTitle(i18n("Krita"));
71#ifndef Q_OS_MACOS
72 setWindowIcon(KisIconUtils::loadIcon("krita-branding"));
73#endif
74
75 setLayout(new QVBoxLayout());
76 layout()->setContentsMargins(QMargins());
77 m_lblSplash = new QLabel();
78 m_lblSplash->setFrameShape(QFrame::NoFrame);
79 layout()->addWidget(m_lblSplash);
80
81 m_loadingTextLabel = new QLabel(m_lblSplash);
82 m_loadingTextLabel->setTextFormat(Qt::RichText);
83 m_loadingTextLabel->setStyleSheet(QStringLiteral("QLabel { color: #fff; background-color: transparent; }"));
84 m_loadingTextLabel->setAlignment(Qt::AlignRight | Qt::AlignTop);
86
87 m_brandingSvg = new QSvgWidget(QStringLiteral(":/krita-branding.svgz"), m_lblSplash);
88 m_bannerSvg = new QSvgWidget(QStringLiteral(":/splash/banner.svg"), m_lblSplash);
90
91 m_artCreditsLabel = new QLabel(m_lblSplash);
92 m_artCreditsLabel->setTextFormat(Qt::PlainText);
93 m_artCreditsLabel->setStyleSheet(QStringLiteral("QLabel { color: #fff; background-color: transparent; font: 10pt; }"));
94 m_artCreditsLabel->setAlignment(Qt::AlignRight | Qt::AlignBottom);
96
97 updateSplashImage(height);
98 setLoadingText(QString()); // the version string is set here too
99
100 connect(&m_timer, SIGNAL(timeout()), SLOT(raise()));
101
102 m_timer.setSingleShot(true);
103 m_timer.start(10);
104}
105
107{
108 const int bannerHeight = height * 0.16875;
109 const int marginTop = height * 0.05;
110 const int marginRight = height * 0.1;
111
113 QPixmap img(source.resourcePath);
114
115 if (img.isNull() || img.height() == 0) return;
116
117 // Preserve aspect ratio of splash.
118 const int width = height * img.width() / img.height();
119
120 setFixedSize(width, height);
121 m_lblSplash->setFixedSize(width, height);
122
123 // Let scaledContents downscale to the fixedSize
124 m_lblSplash->setScaledContents(true);
125 m_lblSplash->setPixmap(img);
126
127 // Align banner to top-left with margin.
128 m_bannerSvg->setFixedHeight(bannerHeight);
129 m_bannerSvg->setFixedWidth(bannerHeight * m_bannerSvg->sizeHint().width() / m_bannerSvg->sizeHint().height());
130 m_bannerSvg->move(width - m_bannerSvg->width() - marginRight, marginTop);
131
132 // Place logo to the left of banner.
133 m_brandingSvg->setFixedSize(bannerHeight, bannerHeight);
134 m_brandingSvg->move(m_bannerSvg->x() - m_brandingSvg->width(), marginTop);
135
136 // Place loading text immediately below.
137 m_loadingTextLabel->move(marginRight, m_brandingSvg->geometry().bottom());
138 m_loadingTextLabel->setFixedWidth(m_bannerSvg->geometry().right() - marginRight);
139
140 // Place credits text on bottom right with similar margins.
141 m_artCreditsLabel->setText(source.artistCredit());
142 m_artCreditsLabel->setFixedWidth(m_loadingTextLabel->width());
143 m_artCreditsLabel->setFixedHeight(20);
144 m_artCreditsLabel->move(m_loadingTextLabel->x(), height - marginTop - m_artCreditsLabel->height());
145}
146
148{
149 int larger = 12;
150 int notAsLarge = larger - 1;
151 QString htmlText = QStringLiteral("<span style='font: %3pt;'><span style='font: bold %4pt;'>%1</span><br><i>%2</i></span>")
152 .arg(m_versionHtml, text.toHtmlEscaped(), QString::number(notAsLarge), QString::number(larger));
153 m_loadingTextLabel->setText(htmlText);
154}
155
160
162{
163 QVector<Source> sources = getSources();
164 for (const Source &source : sources) {
165 if (source.isAvailable && source.key == key) {
166 return source;
167 }
168 }
169 return sources[0];
170}
171
173{
174 // The "professional" splash screen is available on purchased versions of
175 // Krita, since professionals can pay for their tools. On Android, we'll
176 // err on the side of allowing changing the splash screen unless we have
177 // evidence to the contrary, otherwise a bad internet connection could
178 // show the user the wrong splash screen. KisAndroidDonations will reset
179 // the splash screen setting if it sees the user is not a supporter.
180#ifdef Q_OS_ANDROID
182 return !donations || donations->isMaybeSupporter();
183#else
185#endif
186}
187
189{
190 bool canChoose = canChooseSplashScreen();
191 return {
192 // First entry is used as the default.
193 {
194 QString(),
195 i18nc("Splash screen option showing Kiki", "Mascot"),
197 i18nc("Splash artist name", "Tyson Tan"),
198 true,
199 true,
200 },
201 {
202 QStringLiteral("corpo1"),
203 i18nc("Splash screen option without Kiki", "Plain"),
204 QStringLiteral(":/splash/corpo1.jpg"),
205 // This splash screen was also created by Tyson, but they preferred
206 // to not be credited prominently for something so simple.
207 QString(),
208 canChoose,
209 false,
210 },
211 };
212}
213
215{
216 // Loading the ginormous 4K PNG splash image increases the startup time on
217 // Android by several seconds and at the same time looks really bad when
218 // scaled down to a dinky size. Instead of overengineering this into an
219 // Enterprise Splash Screen Solution where we choose the image based on
220 // screen size or something, we'll just use a HD JPEG instead. It's fine.
221#ifdef Q_OS_ANDROID
222 return QStringLiteral(":/splash/hd.jpg");
223#else
224 return QStringLiteral(":/splash/0.png");
225#endif
226}
227
229{
230 QWidget::repaint();
231 qApp->sendPostedEvents();
232}
233
235{
236 if (!this->parentWidget()) {
237 this->winId(); // Force creation of native window
238 QWindow *windowHandle = this->windowHandle();
239 QScreen *screen = windowHandle ? windowHandle->screen() : nullptr;
240 if (windowHandle && !screen) {
241 // At least on Windows, the window may be created on a non-primary
242 // screen with a different scale factor. If we don't explicitly
243 // move it to the primary screen, the position will be scaled with
244 // the wrong factor and the splash will be offset.
245 // XXX: In theory this branch should be unreachable, but leaving
246 // this here just in case.
247 windowHandle->setScreen(QApplication::primaryScreen());
248 }
249 if (!screen) {
250 screen = QApplication::primaryScreen();
251 }
252 QRect r(QPoint(), size());
253 move(screen->availableGeometry().center() - r.center());
254 }
255 if (isVisible()) {
256 repaint();
257 }
258 m_timer.setSingleShot(true);
259 m_timer.start(1);
260 QWidget::show();
261}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
static KisAndroidDonations * instance()
static bool isStoreApplication()
static Source getAvailableSource(const QString &key)
void updateSplashImage(const int height)
static QString defaultSplashResourcePath()
static QVector< Source > getSources()
void setLoadingText(QString text)
QLabel * m_loadingTextLabel
QSvgWidget * m_brandingSvg
static Source getCurrentSource()
QSvgWidget * m_bannerSvg
static bool canChooseSplashScreen()
KisSplashScreen(int height, QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags(Qt::SplashScreen|Qt::FramelessWindowHint))
static void addDropShadow(QWidget *widget)
QIcon loadIcon(const QString &name)