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#include <QVBoxLayout>
21#include <QLabel>
22
23#include <KisPart.h>
24#include <KisApplication.h>
25
26#include <kis_icon.h>
27
28#include <klocalizedstring.h>
29#include <kconfig.h>
30#include <ksharedconfig.h>
31#include <kconfiggroup.h>
32
33static void addDropShadow(QWidget *widget)
34{
35 QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(widget);
36 effect->setBlurRadius(4);
37 effect->setOffset(0.5);
38 effect->setColor(QColor(0, 0, 0, 255));
39 widget->setGraphicsEffect(effect);
40}
41
42KisSplashScreen::KisSplashScreen(int height, QWidget *parent, Qt::WindowFlags f)
43 : QWidget(parent, f)
44 , m_versionHtml(qApp->applicationVersion().toHtmlEscaped())
45{
46 setWindowTitle(i18n("Krita"));
47#ifndef Q_OS_MACOS
48 setWindowIcon(KisIconUtils::loadIcon("krita-branding"));
49#endif
50
51 setLayout(new QVBoxLayout());
52 layout()->setContentsMargins(QMargins());
53 m_lblSplash = new QLabel();
54 m_lblSplash->setFrameShape(QFrame::NoFrame);
55 layout()->addWidget(m_lblSplash);
56
57 m_loadingTextLabel = new QLabel(m_lblSplash);
58 m_loadingTextLabel->setTextFormat(Qt::RichText);
59 m_loadingTextLabel->setStyleSheet(QStringLiteral("QLabel { color: #fff; background-color: transparent; }"));
60 m_loadingTextLabel->setAlignment(Qt::AlignRight | Qt::AlignTop);
62
63 m_brandingSvg = new QSvgWidget(QStringLiteral(":/krita-branding.svgz"), m_lblSplash);
64 m_bannerSvg = new QSvgWidget(QStringLiteral(":/splash/banner.svg"), m_lblSplash);
66
67 m_artCreditsLabel = new QLabel(m_lblSplash);
68 m_artCreditsLabel->setTextFormat(Qt::PlainText);
69 m_artCreditsLabel->setStyleSheet(QStringLiteral("QLabel { color: #fff; background-color: transparent; font: 10pt; }"));
70 m_artCreditsLabel->setAlignment(Qt::AlignRight | Qt::AlignBottom);
72
73 updateSplashImage(height);
74 setLoadingText(QString()); // the version string is set here too
75
76 connect(&m_timer, SIGNAL(timeout()), SLOT(raise()));
77
78 m_timer.setSingleShot(true);
79 m_timer.start(10);
80}
81
83{
84 const int bannerHeight = height * 0.16875;
85 const int marginTop = height * 0.05;
86 const int marginRight = height * 0.1;
87
89 QPixmap img(source.resourcePath);
90
91 if (img.isNull() || img.height() == 0) return;
92
93 // Preserve aspect ratio of splash.
94 const int width = height * img.width() / img.height();
95
96 setFixedSize(width, height);
97 m_lblSplash->setFixedSize(width, height);
98
99 // Let scaledContents downscale to the fixedSize
100 m_lblSplash->setScaledContents(true);
101 m_lblSplash->setPixmap(img);
102
103 // Align banner to top-left with margin.
104 m_bannerSvg->setFixedHeight(bannerHeight);
105 m_bannerSvg->setFixedWidth(bannerHeight * m_bannerSvg->sizeHint().width() / m_bannerSvg->sizeHint().height());
106 m_bannerSvg->move(width - m_bannerSvg->width() - marginRight, marginTop);
107
108 // Place logo to the left of banner.
109 m_brandingSvg->setFixedSize(bannerHeight, bannerHeight);
110 m_brandingSvg->move(m_bannerSvg->x() - m_brandingSvg->width(), marginTop);
111
112 // Place loading text immediately below.
113 m_loadingTextLabel->move(marginRight, m_brandingSvg->geometry().bottom());
114 m_loadingTextLabel->setFixedWidth(m_bannerSvg->geometry().right() - marginRight);
115
116 // Place credits text on bottom right with similar margins.
117 m_artCreditsLabel->setText(source.artistCredit);
118 m_artCreditsLabel->setFixedWidth(m_loadingTextLabel->width());
119 m_artCreditsLabel->setFixedHeight(20);
120 m_artCreditsLabel->move(m_loadingTextLabel->x(), height - marginTop - m_artCreditsLabel->height());
121}
122
124{
125 int larger = 12;
126 int notAsLarge = larger - 1;
127 QString htmlText = QStringLiteral("<span style='font: %3pt;'><span style='font: bold %4pt;'>%1</span><br><i>%2</i></span>")
128 .arg(m_versionHtml, text.toHtmlEscaped(), QString::number(notAsLarge), QString::number(larger));
129 m_loadingTextLabel->setText(htmlText);
130}
131
133{
134 QString artistCredit = i18nc("Normal splash artist name", "Tyson Tan");
135 // Loading the ginormous 4K PNG splash image increases the startup time on
136 // Android by several seconds and at the same time looks really bad when
137 // scaled down to a dinky size. Instead of overengineering this into an
138 // Enterprise Splash Screen Solution where we choose the image based on
139 // screen size or something, we'll just use a HD JPEG instead. It's fine.
140#ifdef Q_OS_ANDROID
141 QString resourcePath = QStringLiteral(":/splash/hd.jpg");
142#else
143 QString resourcePath = QStringLiteral(":/splash/0.png");
144 // TODO: Re-add the holiday splash...
145#if 0
146 QDate currentDate = QDate::currentDate();
147 if (currentDate > QDate(currentDate.year(), 12, 4) ||
148 currentDate < QDate(currentDate.year(), 1, 9)) {
149 resourcePath = QStringLiteral(":/splash/1.png");
150 artistCredit = QStringLiteral("???")};
151 }
152#endif
153#endif
154 if (!artistCredit.isEmpty()) {
155 artistCredit = i18nc("splash image credit", "Artwork by: %1", artistCredit);
156 }
157 return Source{resourcePath, artistCredit};
158}
159
161{
162 QWidget::repaint();
163 qApp->sendPostedEvents();
164}
165
167{
168 if (!this->parentWidget()) {
169 this->winId(); // Force creation of native window
170 QWindow *windowHandle = this->windowHandle();
171 QScreen *screen = windowHandle ? windowHandle->screen() : nullptr;
172 if (windowHandle && !screen) {
173 // At least on Windows, the window may be created on a non-primary
174 // screen with a different scale factor. If we don't explicitly
175 // move it to the primary screen, the position will be scaled with
176 // the wrong factor and the splash will be offset.
177 // XXX: In theory this branch should be unreachable, but leaving
178 // this here just in case.
179 windowHandle->setScreen(QApplication::primaryScreen());
180 }
181 if (!screen) {
182 screen = QApplication::primaryScreen();
183 }
184 QRect r(QPoint(), size());
185 move(screen->availableGeometry().center() - r.center());
186 }
187 if (isVisible()) {
188 repaint();
189 }
190 m_timer.setSingleShot(true);
191 m_timer.start(1);
192 QWidget::show();
193}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
static Source getImageSource()
void updateSplashImage(const int height)
void setLoadingText(QString text)
QLabel * m_loadingTextLabel
QSvgWidget * m_brandingSvg
QSvgWidget * m_bannerSvg
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)