Gui: Make splashscreen use multiple splash images

This commit is contained in:
qewer33
2024-09-01 12:17:59 +03:00
committed by WandererFan
parent 5850c2e04b
commit 9beff61b72
4 changed files with 33 additions and 14 deletions

View File

@@ -50,6 +50,7 @@ Branding::Branding()
filter.push_back("SplashAlignment");
filter.push_back("SplashTextColor");
filter.push_back("SplashInfoColor");
filter.push_back("SplashWarningColor");
filter.push_back("StartWorkbench");

View File

@@ -1971,11 +1971,12 @@ QPixmap MainWindow::aboutImage() const
void MainWindow::renderDevBuildWarning(
QPainter &painter,
const QPoint startPosition,
const QSize maxSize)
const QSize maxSize,
QColor color)
{
// Create a background box that fades out the artwork for better legibility
QColor fader (Qt::black);
constexpr float halfDensity (0.5);
QColor fader (Qt::white);
constexpr float halfDensity (0.65);
fader.setAlphaF(halfDensity);
QBrush fillBrush(fader, Qt::BrushStyle::SolidPattern);
painter.setBrush(fillBrush);
@@ -2006,6 +2007,7 @@ void MainWindow::renderDevBuildWarning(
int boxHeight = static_cast<int>(lineHeight*lineExpansionFactor);
// Draw the background rectangle and the text
painter.setPen(color);
painter.drawRect(startPosition.x(), startPosition.y(), boxWidth, boxHeight);
painter.drawText(startPosition.x()+padding, startPosition.y()+lineHeight, devWarningLine1);
painter.drawText(startPosition.x()+padding, startPosition.y()+2*lineHeight, devWarningLine2);
@@ -2019,8 +2021,18 @@ QPixmap MainWindow::splashImage() const
if (fi.isFile() && fi.exists())
splash_image.load(fi.filePath(), "PNG");
// if no image was found try the config
// determine the count of splashes
std::string splash_path = App::Application::Config()["SplashScreen"];
QStringList pixmaps = Gui::BitmapFactory().findIconFiles().filter(QString::fromStdString(splash_path));
// divide by 2 since there's two sets (normal and 2x)
// minus 1 to ignore the default splash that isn't numbered
int splash_count = pixmaps.count()/2 - 1;
// set a random splash path
int random = rand() % splash_count;
splash_path += std::to_string(random);
// if no image was found try the config
if (splash_image.isNull()) {
QString path = QString::fromUtf8(splash_path.c_str());
if (QDir(path).isRelative()) {
@@ -2036,7 +2048,7 @@ QPixmap MainWindow::splashImage() const
if (splash_image.isNull()) {
if (qApp->devicePixelRatio() > 1.0) {
// For HiDPI screens, we have a double-resolution version of the splash image
splash_path += "2x";
splash_path += "_2x";
splash_image = Gui::BitmapFactory().pixmap(splash_path.c_str());
splash_image.setDevicePixelRatio(2.0);
pixelRatio = 2.0;
@@ -2048,7 +2060,8 @@ QPixmap MainWindow::splashImage() const
// include application name and version number
std::map<std::string,std::string>::const_iterator tc = App::Application::Config().find("SplashInfoColor");
if (tc != App::Application::Config().end()) {
std::map<std::string,std::string>::const_iterator wc = App::Application::Config().find("SplashWarningColor");
if (tc != App::Application::Config().end() && wc != App::Application::Config().end()) {
QString title = qApp->applicationName();
QString major = QString::fromLatin1(App::Application::Config()["BuildVersionMajor"].c_str());
QString minor = QString::fromLatin1(App::Application::Config()["BuildVersionMinor"].c_str());
@@ -2089,7 +2102,7 @@ QPixmap MainWindow::splashImage() const
int h = splash_image.height();
QFont fontVer = painter.font();
fontVer.setPointSizeF(14.0);
fontVer.setPointSizeF(11.0);
QFontMetrics metricVer(fontVer);
int v = QtTools::horizontalAdvance(metricVer, version);
@@ -2115,13 +2128,17 @@ QPixmap MainWindow::splashImage() const
painter.drawText(x, y, title);
}
painter.setFont(fontVer);
painter.drawText(x + (l + 5), y, version);
if (suffix == QLatin1String("dev")) {
painter.drawText(x + (l + 235), y - 7, version);
QColor warningColor;
warningColor.setNamedColor(QString::fromLatin1(wc->second.c_str()));
if (suffix == QLatin1String("dev") && warningColor.isValid()) {
fontVer.setPointSizeF(14.0);
painter.setFont(fontVer);
const int lineHeight = metricVer.lineSpacing();
const int padding {10}; // Distance from the edge of the graphic's bounding box
QPoint startPosition(padding, y + lineHeight);
const int padding {45}; // Distance from the edge of the graphic's bounding box
QPoint startPosition(padding, y + lineHeight*2);
QSize maxSize(w/pixelRatio - 2*padding, lineHeight * 3);
MainWindow::renderDevBuildWarning(painter, startPosition, maxSize);
MainWindow::renderDevBuildWarning(painter, startPosition, maxSize, warningColor);
}
painter.end();
}

View File

@@ -312,7 +312,7 @@ private:
void populateToolBarMenu(QMenu *);
void populateDockWindowMenu(QMenu *);
static void renderDevBuildWarning(QPainter &painter, const QPoint startPosition, const QSize maxSize);
static void renderDevBuildWarning(QPainter &painter, const QPoint startPosition, const QSize maxSize, QColor color);
private Q_SLOTS:
/**

View File

@@ -176,7 +176,8 @@ int main(int argc, char** argv)
// App::Application::Config()["HiddenDockWindow"] = "Property editor";
App::Application::Config()["SplashAlignment"] = "Bottom|Left";
App::Application::Config()["SplashTextColor"] = "#418FDE";
App::Application::Config()["SplashInfoColor"] = "#418FDE";
App::Application::Config()["SplashWarningColor"] = "#CA333B";
App::Application::Config()["SplashInfoColor"] = "#000000";
App::Application::Config()["SplashInfoPosition"] = "6,75";
QGuiApplication::setDesktopFileName(QStringLiteral("org.freecad.FreeCAD"));