Paste P155

Adding text to the splash screen.
ActivePublic

Authored by woltherav on Jan 7 2018, 8:22 PM.
diff --git a/libs/ui/KisApplication.cpp b/libs/ui/KisApplication.cpp
index 635eca9..c5207c1 100644
--- a/libs/ui/KisApplication.cpp
+++ b/libs/ui/KisApplication.cpp
@@ -581,6 +581,7 @@ void KisApplication::setSplashScreenLoadingText(QString textToLoad)
{
if (d->splashScreen) {
d->splashScreen->loadingLabel->setText(textToLoad);
+ d->splashScreen->setLoadingText(textToLoad);
d->splashScreen->repaint();
}
}
diff --git a/libs/ui/kis_splash_screen.cpp b/libs/ui/kis_splash_screen.cpp
index c54b51c..a5c96da 100644
--- a/libs/ui/kis_splash_screen.cpp
+++ b/libs/ui/kis_splash_screen.cpp
@@ -20,6 +20,7 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QPixmap>
+#include <QPainter>
#include <QCheckBox>
#include <kis_debug.h>
#include <QFile>
@@ -47,13 +48,38 @@ KisSplashScreen::KisSplashScreen(const QString &version, const QPixmap &pixmap,
setupUi(this);
setWindowIcon(KisIconUtils::loadIcon("calligrakrita"));
- // Maintain the aspect ratio on high DPI screens when scaling
- lblSplash->setPixmap(pixmap);
- setFixedWidth(pixmap.width());
-
QString color = colorString();
lblVersion->setText(i18n("Version: %1", version));
lblVersion->setStyleSheet("color:" + color);
+ QImage img = pixmap.toImage();
+ QFont font = this->font();
+ font.setPointSize(9);
+ font.setBold(true);
+ QFontMetrics metrics(font);
+
+ QPainter p(&img);
+ p.setFont(font);
+ p.setRenderHint(QPainter::Antialiasing);
+ int leftEdge = 404-metrics.width(version);
+ int topEdge = 64+metrics.ascent();
+
+ //draw shadow
+ QPen pen(QColor(0, 0, 0, 80));
+ p.setPen(pen);
+ p.drawText(leftEdge+1, topEdge+1, version);
+ //draw main text
+ p.setPen(QPen(QColor(255, 255, 255, 255)));
+ p.drawText(leftEdge, topEdge, version);
+ p.end();
+
+
+ //get this to have the loading text painted on later.
+ m_splashImage = img;
+ m_textTop = topEdge+metrics.height();
+
+ // Maintain the aspect ratio on high DPI screens when scaling
+ lblSplash->setPixmap(QPixmap::fromImage(img));
+ setFixedWidth(pixmap.width());
bnClose->hide();
connect(bnClose, SIGNAL(clicked()), this, SLOT(close()));
@@ -156,6 +182,31 @@ void KisSplashScreen::displayRecentFiles() {
line->setVisible(true);
}
+void KisSplashScreen::setLoadingText(QString text)
+{
+ QFont font = this->font();
+ font.setPointSize(7);
+ font.setItalic(true);
+
+ QImage img = m_splashImage;
+ QPainter p(&img);
+ QFontMetrics metrics(font);
+ p.setFont(font);
+ p.setRenderHint(QPainter::Antialiasing);
+ int leftEdge = 404-metrics.width(text);
+ int topEdge = m_textTop;
+
+ //draw shadow
+ QPen pen(QColor(0, 0, 0, 80));
+ p.setPen(pen);
+ p.drawText(leftEdge+1, topEdge+1, text);
+ //draw main text
+ p.setPen(QPen(QColor(255, 255, 255, 255)));
+ p.drawText(leftEdge, topEdge, text);
+ p.end();
+ lblSplash->setPixmap(QPixmap::fromImage(img));
+}
+
QString KisSplashScreen::colorString() const
diff --git a/libs/ui/kis_splash_screen.h b/libs/ui/kis_splash_screen.h
index 4ede0b1..d0e93ef 100644
--- a/libs/ui/kis_splash_screen.h
+++ b/libs/ui/kis_splash_screen.h
@@ -39,6 +39,8 @@ public:
void displayLinks();
void displayRecentFiles();
+ void setLoadingText(QString text);
+
private Q_SLOTS:
void toggleShowAtStartup(bool toggle);
@@ -55,7 +57,8 @@ private:
QTimer m_timer;
bool m_themed;
-
+ QImage m_splashImage;
+ int m_textTop;
};
#endif // KIS_SPLASH_SCREEN_H
woltherav created this paste.Jan 7 2018, 8:22 PM
woltherav created this object in space S1 KDE Community.
woltherav updated the paste's language from cpp to diff.