From 9beff61b7214f855df865c18ca46d437d5cacc19 Mon Sep 17 00:00:00 2001 From: qewer33 Date: Sun, 1 Sep 2024 12:17:59 +0300 Subject: [PATCH] Gui: Make splashscreen use multiple splash images --- src/App/Branding.cpp | 1 + src/Gui/MainWindow.cpp | 41 +++++++++++++++++++++++++++++------------ src/Gui/MainWindow.h | 2 +- src/Main/MainGui.cpp | 3 ++- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/App/Branding.cpp b/src/App/Branding.cpp index 6f593022a6..ef50dc5302 100644 --- a/src/App/Branding.cpp +++ b/src/App/Branding.cpp @@ -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"); diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 9dc7efde87..25e0222707 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -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(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::const_iterator tc = App::Application::Config().find("SplashInfoColor"); - if (tc != App::Application::Config().end()) { + std::map::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(); } diff --git a/src/Gui/MainWindow.h b/src/Gui/MainWindow.h index 769086cddb..cf9103adda 100644 --- a/src/Gui/MainWindow.h +++ b/src/Gui/MainWindow.h @@ -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: /** diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp index 381888ec76..36087cffd6 100644 --- a/src/Main/MainGui.cpp +++ b/src/Main/MainGui.cpp @@ -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"));