From e7a807efdf21b990116c1141e6c699d9de18554f Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 22 Dec 2018 06:27:13 +0100 Subject: [PATCH] Allow text messages on the splash screen, currently used with setup reader --- src/blackcore/setupreader.cpp | 6 ++-- src/blackcore/setupreader.h | 3 ++ src/blackgui/guiapplication.cpp | 52 ++++++++++++++++++++++++----- src/blackgui/guiapplication.h | 34 +++++++++++-------- src/blackgui/splashscreen.cpp | 58 +++++++++++++++++++++++++++++++++ src/blackgui/splashscreen.h | 53 ++++++++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 24 deletions(-) create mode 100644 src/blackgui/splashscreen.cpp create mode 100644 src/blackgui/splashscreen.h diff --git a/src/blackcore/setupreader.cpp b/src/blackcore/setupreader.cpp index 149026afd..3b49a22e2 100644 --- a/src/blackcore/setupreader.cpp +++ b/src/blackcore/setupreader.cpp @@ -385,7 +385,8 @@ namespace BlackCore nwReplyPtr->close(); if (setupJson.isEmpty()) { - CLogMessage(this).info("No bootstrap setup file at '%1'") << urlString; + const CStatusMessage m = CLogMessage(this).info("No bootstrap setup file at '%1'") << urlString; + emit this->setupLoadingMessages(m); } else { @@ -416,7 +417,8 @@ namespace BlackCore { // no issue with cache m_updateInfoUrls = loadedSetup.getSwiftUpdateInfoFileUrls(); - CLogMessage(this).info("Loaded setup from '%1'") << urlString; + const CStatusMessage m = CLogMessage(this).info("Loaded setup from '%1'") << urlString; + emit this->setupLoadingMessages(m); CLogMessage(this).info("Setup: Updated data cache in '%1'") << m_setup.getFilename(); { QWriteLocker l(&m_lockSetup); diff --git a/src/blackcore/setupreader.h b/src/blackcore/setupreader.h index 0d9f58b6e..6467370d5 100644 --- a/src/blackcore/setupreader.h +++ b/src/blackcore/setupreader.h @@ -129,6 +129,9 @@ namespace BlackCore //! A shared URL was successfully read void successfullyReadSharedUrl(const BlackMisc::Network::CUrl &sharedUrl); + //! Message about the loading status + void setupLoadingMessages(const BlackMisc::CStatusMessageList &messages); + protected: //! Constructor explicit CSetupReader(QObject *parent); diff --git a/src/blackgui/guiapplication.cpp b/src/blackgui/guiapplication.cpp index 2a390d50f..33e34be31 100644 --- a/src/blackgui/guiapplication.cpp +++ b/src/blackgui/guiapplication.cpp @@ -7,19 +7,19 @@ * contained in the LICENSE file. */ -#include "blackconfig/buildconfig.h" +#include "blackgui/components/applicationclosedialog.h" +#include "blackgui/components/updateinfodialog.h" +#include "blackgui/components/aboutdialog.h" +#include "blackgui/components/setuploadingdialog.h" +#include "blackgui/splashscreen.h" +#include "blackgui/guiapplication.h" +#include "blackgui/guiutility.h" +#include "blackgui/registermetadata.h" #include "blackcore/context/contextnetwork.h" #include "blackcore/data/globalsetup.h" #include "blackcore/db/networkwatchdog.h" #include "blackcore/webdataservices.h" #include "blackcore/setupreader.h" -#include "blackgui/components/applicationclosedialog.h" -#include "blackgui/components/updateinfodialog.h" -#include "blackgui/components/aboutdialog.h" -#include "blackgui/components/setuploadingdialog.h" -#include "blackgui/guiapplication.h" -#include "blackgui/guiutility.h" -#include "blackgui/registermetadata.h" #include "blackmisc/slot.h" #include "blackmisc/directoryutils.h" #include "blackmisc/datacache.h" @@ -30,6 +30,7 @@ #include "blackmisc/registermetadata.h" #include "blackmisc/settingscache.h" #include "blackmisc/verify.h" +#include "blackconfig/buildconfig.h" #include #include @@ -42,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -104,8 +106,10 @@ namespace BlackGui this->settingsChanged(); this->setCurrentFontValues(); // most likely the default font and not any stylesheet font at this time sGui = this; + connect(&m_styleSheetUtility, &CStyleSheetUtility::styleSheetsChanged, this, &CGuiApplication::onStyleSheetsChanged, Qt::QueuedConnection); connect(this, &CGuiApplication::startUpCompleted, this, &CGuiApplication::superviseWindowMinSizes, Qt::QueuedConnection); + connect(this->getSetupReader(), &CSetupReader::setupLoadingMessages, this, &CGuiApplication::displaySplashMessages, Qt::QueuedConnection); } } @@ -185,11 +189,41 @@ namespace BlackGui { m_splashScreen.reset(); // delete old one } - m_splashScreen.reset(new QSplashScreen(pixmap.scaled(256, 256))); + + QFont splashFont; + splashFont.setFamily("Arial"); + // splashFont.setBold(true); + splashFont.setPointSize(10); + splashFont.setStretch(125); + + m_splashScreen.reset(new CSplashScreen(pixmap.scaled(256, 256))); m_splashScreen->show(); + m_splashScreen->showStatusMessage(CBuildConfig::getVersionString()); + m_splashScreen->setSplashFont(splashFont); + this->processEventsToRefreshGui(); } + void CGuiApplication::displaySplashMessage(const CStatusMessage &msg) + { + if (msg.isEmpty()) { return; } + if (!m_splashScreen) { return; } + if (this->isShuttingDown()) { return; } + if (!m_splashScreen->isVisible()) { return; } + m_splashScreen->showStatusMessage(msg); + } + + void CGuiApplication::displaySplashMessages(const CStatusMessageList &msgs) + { + if (msgs.isEmpty()) { return; } + for (const CStatusMessage &m : msgs) + { + if (!m_splashScreen) { return; } + this->displaySplashMessage(m); + this->processEventsToRefreshGui(); + } + } + void CGuiApplication::processEventsToRefreshGui() const { if (this->isShuttingDown()) { return; } diff --git a/src/blackgui/guiapplication.h b/src/blackgui/guiapplication.h index afcc395e6..c09e9d4c9 100644 --- a/src/blackgui/guiapplication.h +++ b/src/blackgui/guiapplication.h @@ -34,9 +34,9 @@ #include class QMenu; -class QSplashScreen; class QWidget; class QMainWindow; +class CSplashScreen; namespace BlackMisc { class CLogCategoryList; } namespace BlackGui @@ -107,12 +107,6 @@ namespace BlackGui //! Window mode (window flags) CEnableForFramelessWindow::WindowMode getWindowMode() const; - //! Add a splash screen based on resource, empty means remove splash screen - void splashScreen(const QString &resource); - - //! Add a splash screen based on resource, empty means remove splash screen - void splashScreen(const QPixmap &pixmap); - //! Allow the GUI to refresh by processing events, call the event loop void processEventsToRefreshGui() const; @@ -140,6 +134,20 @@ namespace BlackGui virtual bool displayInOverlayWindow(const BlackMisc::CStatusMessageList &messages, int timeOutMs = -1) override; //! @} + // -------- Splash screen related --------- + //! Add a splash screen based on resource, empty means remove splash screen + void splashScreen(const QString &resource); + + //! Add a splash screen based on resource, empty means remove splash screen + void splashScreen(const QPixmap &pixmap); + + //! Display splash screen messages if screen is available and visible @{ + void displaySplashMessage(const BlackMisc::CStatusMessage &msg); + void displaySplashMessages(const BlackMisc::CStatusMessageList &msgs); + //! @} + + // -------- Splash screen related --------- + //! Add menu items for settings and cache void addMenuForSettingsAndCache(QMenu &menu); @@ -309,12 +317,12 @@ namespace BlackGui QCommandLineOption m_cmdWindowMode { "emptyWindowMode" }; //!< window mode (flags: frameless ...) QCommandLineOption m_cmdWindowSizeReset { "emptySizeReset" }; //!< window size reset QCommandLineOption m_cmdWindowScaleSize { "emptyScale" }; //!< window scale size - CStyleSheetUtility m_styleSheetUtility {{}, this}; //!< style sheet utility - bool m_uiSetupCompleted = false; //!< ui setup completed - bool m_saveMainWidgetState = true; //!< save/restore main widget's state - QScopedPointer m_splashScreen; //!< splash screen - Components::CUpdateInfoDialog *m_updateDialog = nullptr; //!< software installation dialog - Components::CApplicationCloseDialog *m_closeDialog = nullptr; //!< close dialog (no QScopedPointer because I need to set parent) + CStyleSheetUtility m_styleSheetUtility {{}, this}; //!< style sheet utility + bool m_uiSetupCompleted = false; //!< ui setup completed + bool m_saveMainWidgetState = true; //!< save/restore main widget's state + QScopedPointer m_splashScreen; //!< splash screen + Components::CUpdateInfoDialog *m_updateDialog = nullptr; //!< software installation dialog + Components::CApplicationCloseDialog *m_closeDialog = nullptr; //!< close dialog (no QScopedPointer because I need to set parent) BlackMisc::CSettingReadOnly m_guiSettings { this, &CGuiApplication::settingsChanged }; BlackMisc::CSettingReadOnly m_updateSetting { this }; //!< update notification settings diff --git a/src/blackgui/splashscreen.cpp b/src/blackgui/splashscreen.cpp new file mode 100644 index 000000000..b140185f5 --- /dev/null +++ b/src/blackgui/splashscreen.cpp @@ -0,0 +1,58 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "splashscreen.h" + +using namespace BlackMisc; + +namespace BlackGui +{ + CSplashScreen::CSplashScreen(const QPixmap &pixmap) : QSplashScreen(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); + } + + void CSplashScreen::showStatusMessage(const QString &html) + { + if (html.isEmpty()) { return; } + m_label->setVisible(true); + m_label->setText(html); + m_hideTextTimer.start(2000); + } + + void CSplashScreen::showStatusMessage(const BlackMisc::CStatusMessage &message) + { + this->showStatusMessage(message.toHtml(true, true)); + } + + void CSplashScreen::setSplashFont(const QFont &font) + { + this->setFont(font); + m_label->setFont(font); + } + + void CSplashScreen::hideText() + { + m_label->setVisible(false); + }; +} diff --git a/src/blackgui/splashscreen.h b/src/blackgui/splashscreen.h new file mode 100644 index 000000000..031ab5210 --- /dev/null +++ b/src/blackgui/splashscreen.h @@ -0,0 +1,53 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_SPLASHSCREEN_H +#define BLACKGUI_SPLASHSCREEN_H + +#include "blackmisc/statusmessage.h" +#include +#include +#include +#include +#include +#include + +namespace BlackGui +{ + /** + * Own splash screen + */ + class CSplashScreen : public QSplashScreen + { + public: + //! Ctor + CSplashScreen(const QPixmap &pixmap); + + //! Show status message + void showStatusMessage(const QString &html); + + //! Show status message + void showStatusMessage(const BlackMisc::CStatusMessage &message); + + //! Set the font for the splash screen + void setSplashFont(const QFont &font); + + private: + //! Hide text + void hideText(); + + QString m_message; + QTimer m_hideTextTimer; + QLabel *m_label = nullptr; + }; +} // ns + +#endif // guard