Skip to content

Commit

Permalink
Print splashscreen text in separate statusbar
Browse files Browse the repository at this point in the history
  • Loading branch information
ltoenning committed Oct 5, 2023
1 parent bcc4bdd commit bfc27f6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/blackgui/guiapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ namespace BlackGui
splashFont.setFamily("Arial");
// splashFont.setBold(true);
splashFont.setPointSize(10);
splashFont.setStretch(125);
splashFont.setStretch(100);

m_splashScreen.reset(new CSplashScreen(pixmap.scaled(256, 256)));
m_splashScreen->show();
m_splashScreen->showStatusMessage(CBuildConfig::getVersionString());
m_splashScreen->showStatusMessage("Version " + CBuildConfig::getVersionString());
m_splashScreen->setSplashFont(splashFont);

this->processEventsToRefreshGui();
Expand Down
47 changes: 22 additions & 25 deletions src/blackgui/splashscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,38 @@

#include "splashscreen.h"

#include <QtMath>

using namespace BlackMisc;

namespace BlackGui
{
CSplashScreen::CSplashScreen(const QPixmap &pixmap) : QSplashScreen(pixmap)
CSplashScreen::CSplashScreen(const QPixmap &pixmap)
{
const int heightTe = 60;
const int height = pixmap.height();
const int width = qRound(0.9 * pixmap.width());
const int yPos = (height - heightTe) / 2;
const int xPos = (pixmap.width() - width) / 2;

m_label = new QLabel(this);
m_label->setGeometry(xPos, yPos, width, 80);
m_label->setAlignment(Qt::AlignCenter);
m_label->setStyleSheet("background: rgba(0,0,0,0); color: white;");
m_label->setWordWrap(true);
m_label->setVisible(false);

m_hideTextTimer.setSingleShot(true);
connect(&m_hideTextTimer, &QTimer::timeout, this, &CSplashScreen::hideText);
const int height = qFloor(pixmap.height() * 1.2);
const int width = pixmap.width();
QPixmap splash(pixmap.width(), height);
splash.fill(Qt::transparent);

QPainter painter(&splash);
painter.drawPixmap(0, 0, pixmap);

const int statusbar_height = qFloor((height - pixmap.height()) / 2.0);
QPixmap statusbar(width, statusbar_height);
statusbar.fill(QColor(200, 200, 200));
painter.drawPixmap(0, height - statusbar_height, statusbar);

this->setPixmap(splash);

m_clearTextTimer.setSingleShot(true);
connect(&m_clearTextTimer, &QTimer::timeout, this, &CSplashScreen::clearMessage);
}

void CSplashScreen::showStatusMessage(const QString &html)
{
if (html.isEmpty()) { return; }
m_label->setVisible(true);
m_label->setText(html);
m_hideTextTimer.start(2000);
this->showMessage(html, Qt::AlignHCenter | Qt::AlignBottom);
m_clearTextTimer.start(2000);
}

void CSplashScreen::showStatusMessage(const BlackMisc::CStatusMessage &message)
Expand All @@ -42,11 +45,5 @@ namespace BlackGui
void CSplashScreen::setSplashFont(const QFont &font)
{
this->setFont(font);
m_label->setFont(font);
}

void CSplashScreen::hideText()
{
m_label->setVisible(false);
};
}
6 changes: 1 addition & 5 deletions src/blackgui/splashscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ namespace BlackGui
void setSplashFont(const QFont &font);

private:
//! Hide text
void hideText();

QString m_message;
QTimer m_hideTextTimer;
QLabel *m_label = nullptr;
QTimer m_clearTextTimer;
};
} // ns

Expand Down

0 comments on commit bfc27f6

Please sign in to comment.