Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSplashScreen Class Reference

#include <kis_splash_screen.h>

+ Inheritance diagram for KisSplashScreen:

Classes

struct  Source
 

Public Member Functions

void displayLinks (bool show)
 
void displayRecentFiles (bool show)
 
 KisSplashScreen (bool themed=false, QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())
 
void repaint ()
 
void setLoadingText (QString text)
 
void show ()
 

Static Public Member Functions

static Source getImageSource ()
 

Protected Member Functions

void resizeEvent (QResizeEvent *event) override
 

Private Slots

void linkClicked (const QString &link)
 
void toggleShowAtStartup (bool toggle)
 

Private Member Functions

QString colorString () const
 
void updateSplashImage ()
 
void updateText ()
 

Private Attributes

QLabel * m_artCreditsLabel
 
QSvgWidget * m_bannerSvg
 
QSvgWidget * m_brandingSvg
 
bool m_displayLinks { false }
 
QLabel * m_loadingTextLabel
 
bool m_themed
 
QTimer m_timer
 
QString m_versionHtml
 

Detailed Description

Definition at line 20 of file kis_splash_screen.h.

Constructor & Destructor Documentation

◆ KisSplashScreen()

KisSplashScreen::KisSplashScreen ( bool themed = false,
QWidget * parent = 0,
Qt::WindowFlags f = Qt::WindowFlags() )
explicit

Definition at line 44 of file kis_splash_screen.cpp.

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}
void displayLinks(bool show)
void displayRecentFiles(bool show)
void setLoadingText(QString text)
void linkClicked(const QString &link)
QLabel * m_loadingTextLabel
QSvgWidget * m_brandingSvg
QSvgWidget * m_bannerSvg
void toggleShowAtStartup(bool toggle)
static void addDropShadow(QWidget *widget)
QAction * close(const QObject *recvr, const char *slot, QObject *parent)
QIcon loadIcon(const QString &name)

References addDropShadow(), displayLinks(), displayRecentFiles(), linkClicked(), KisIconUtils::loadIcon(), m_artCreditsLabel, m_bannerSvg, m_brandingSvg, m_loadingTextLabel, m_timer, setLoadingText(), toggleShowAtStartup(), and updateSplashImage().

Member Function Documentation

◆ colorString()

QString KisSplashScreen::colorString ( ) const
private

Definition at line 300 of file kis_splash_screen.cpp.

301{
302 QString color = "#FFFFFF";
303 if (m_themed && qApp->palette().window().color().value() > 100) {
304 color = "#000000";
305 }
306
307 return color;
308}

References m_themed.

◆ displayLinks()

void KisSplashScreen::displayLinks ( bool show)

Definition at line 202 of file kis_splash_screen.cpp.

202 {
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}
QString colorString() const

References colorString(), m_displayLinks, show(), updateSplashImage(), and updateText().

◆ displayRecentFiles()

void KisSplashScreen::displayRecentFiles ( bool show)

Definition at line 257 of file kis_splash_screen.cpp.

257 {
258 lblRecent->setVisible(show);
259 line->setVisible(show);
260}

References show().

◆ getImageSource()

KisSplashScreen::Source KisSplashScreen::getImageSource ( )
static

Definition at line 271 of file kis_splash_screen.cpp.

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}

◆ linkClicked

void KisSplashScreen::linkClicked ( const QString & link)
privateslot

Definition at line 355 of file kis_splash_screen.cpp.

356{
358 if (isWindow()) {
359 close();
360 }
361}
static KisPart * instance()
Definition KisPart.cpp:131
void openExistingFile(const QString &path)
Definition KisPart.cpp:513

References KisPart::instance(), and KisPart::openExistingFile().

◆ repaint()

void KisSplashScreen::repaint ( )

Definition at line 311 of file kis_splash_screen.cpp.

312{
313 QWidget::repaint();
314 qApp->sendPostedEvents();
315}

◆ resizeEvent()

void KisSplashScreen::resizeEvent ( QResizeEvent * event)
overrideprotected

Definition at line 154 of file kis_splash_screen.cpp.

155{
156 QWidget::resizeEvent(event);
157 updateText();
158}

References updateText().

◆ setLoadingText()

void KisSplashScreen::setLoadingText ( QString text)

Definition at line 262 of file kis_splash_screen.cpp.

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}

References m_loadingTextLabel, and m_versionHtml.

◆ show()

void KisSplashScreen::show ( )

Definition at line 317 of file kis_splash_screen.cpp.

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}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References m_timer, repaint(), and updateSplashImage().

◆ toggleShowAtStartup

void KisSplashScreen::toggleShowAtStartup ( bool toggle)
privateslot

Definition at line 349 of file kis_splash_screen.cpp.

350{
351 KConfigGroup cfg( KSharedConfig::openConfig(), "SplashScreen");
352 cfg.writeEntry("HideSplashAfterStartup", toggle);
353}

◆ updateSplashImage()

void KisSplashScreen::updateSplashImage ( )
private

Definition at line 94 of file kis_splash_screen.cpp.

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
109 Source source = getImageSource();
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}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
static Source getImageSource()

References getImageSource(), m_artCreditsLabel, m_bannerSvg, m_brandingSvg, m_displayLinks, m_loadingTextLabel, and source().

◆ updateText()

void KisSplashScreen::updateText ( )
private

Definition at line 160 of file kis_splash_screen.cpp.

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}
const char * name(StandardAction id)

References colorString().

Member Data Documentation

◆ m_artCreditsLabel

QLabel* KisSplashScreen::m_artCreditsLabel
private

Definition at line 62 of file kis_splash_screen.h.

◆ m_bannerSvg

QSvgWidget* KisSplashScreen::m_bannerSvg
private

Definition at line 60 of file kis_splash_screen.h.

◆ m_brandingSvg

QSvgWidget* KisSplashScreen::m_brandingSvg
private

Definition at line 59 of file kis_splash_screen.h.

◆ m_displayLinks

bool KisSplashScreen::m_displayLinks { false }
private

Definition at line 58 of file kis_splash_screen.h.

58{ false };

◆ m_loadingTextLabel

QLabel* KisSplashScreen::m_loadingTextLabel
private

Definition at line 61 of file kis_splash_screen.h.

◆ m_themed

bool KisSplashScreen::m_themed
private

Definition at line 57 of file kis_splash_screen.h.

◆ m_timer

QTimer KisSplashScreen::m_timer
private

Definition at line 56 of file kis_splash_screen.h.

◆ m_versionHtml

QString KisSplashScreen::m_versionHtml
private

Definition at line 63 of file kis_splash_screen.h.


The documentation for this class was generated from the following files: