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

#include <kis_splash_screen.h>

+ Inheritance diagram for KisSplashScreen:

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 ()
 

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 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}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
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(), connect(), 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 286 of file kis_splash_screen.cpp.

287{
288 QString color = "#FFFFFF";
289 if (m_themed && qApp->palette().window().color().value() > 100) {
290 color = "#000000";
291 }
292
293 return color;
294}

References m_themed.

◆ displayLinks()

void KisSplashScreen::displayLinks ( bool show)

Definition at line 215 of file kis_splash_screen.cpp.

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

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

◆ displayRecentFiles()

void KisSplashScreen::displayRecentFiles ( bool show)

Definition at line 270 of file kis_splash_screen.cpp.

270 {
271 lblRecent->setVisible(show);
272 line->setVisible(show);
273}

References show().

◆ linkClicked

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

Definition at line 341 of file kis_splash_screen.cpp.

342{
344 if (isTopLevel()) {
345 close();
346 }
347}
static KisPart * instance()
Definition KisPart.cpp:131
void openExistingFile(const QString &path)
Definition KisPart.cpp:537

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

◆ repaint()

void KisSplashScreen::repaint ( )

Definition at line 297 of file kis_splash_screen.cpp.

298{
299 QWidget::repaint();
300 qApp->sendPostedEvents();
301}

◆ resizeEvent()

void KisSplashScreen::resizeEvent ( QResizeEvent * event)
overrideprotected

Definition at line 167 of file kis_splash_screen.cpp.

168{
169 QWidget::resizeEvent(event);
170 updateText();
171}

References updateText().

◆ setLoadingText()

void KisSplashScreen::setLoadingText ( QString text)

Definition at line 275 of file kis_splash_screen.cpp.

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}

References m_loadingTextLabel, and m_versionHtml.

◆ show()

void KisSplashScreen::show ( )

Definition at line 303 of file kis_splash_screen.cpp.

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}
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 335 of file kis_splash_screen.cpp.

336{
337 KConfigGroup cfg( KSharedConfig::openConfig(), "SplashScreen");
338 cfg.writeEntry("HideSplashAfterStartup", toggle);
339}

◆ updateSplashImage()

void KisSplashScreen::updateSplashImage ( )
private

Definition at line 92 of file kis_splash_screen.cpp.

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}

References m_artCreditsLabel, m_bannerSvg, m_brandingSvg, m_displayLinks, and m_loadingTextLabel.

◆ updateText()

void KisSplashScreen::updateText ( )
private

Definition at line 173 of file kis_splash_screen.cpp.

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

References colorString().

Member Data Documentation

◆ m_artCreditsLabel

QLabel* KisSplashScreen::m_artCreditsLabel
private

Definition at line 55 of file kis_splash_screen.h.

◆ m_bannerSvg

QSvgWidget* KisSplashScreen::m_bannerSvg
private

Definition at line 53 of file kis_splash_screen.h.

◆ m_brandingSvg

QSvgWidget* KisSplashScreen::m_brandingSvg
private

Definition at line 52 of file kis_splash_screen.h.

◆ m_displayLinks

bool KisSplashScreen::m_displayLinks { false }
private

Definition at line 51 of file kis_splash_screen.h.

51{ false };

◆ m_loadingTextLabel

QLabel* KisSplashScreen::m_loadingTextLabel
private

Definition at line 54 of file kis_splash_screen.h.

◆ m_themed

bool KisSplashScreen::m_themed
private

Definition at line 50 of file kis_splash_screen.h.

◆ m_timer

QTimer KisSplashScreen::m_timer
private

Definition at line 49 of file kis_splash_screen.h.

◆ m_versionHtml

QString KisSplashScreen::m_versionHtml
private

Definition at line 56 of file kis_splash_screen.h.


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