mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
Allow text messages on the splash screen, currently used with setup reader
This commit is contained in:
committed by
Mat Sutcliffe
parent
0817d38b4c
commit
e7a807efdf
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 <QAction>
|
||||
#include <QCloseEvent>
|
||||
@@ -42,6 +43,7 @@
|
||||
#include <QApplication>
|
||||
#include <QGuiApplication>
|
||||
#include <QIcon>
|
||||
#include <QFont>
|
||||
#include <QKeySequence>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
@@ -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; }
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
#include <Qt>
|
||||
|
||||
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<QSplashScreen> 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<CSplashScreen> 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<Settings::TGeneralGui> m_guiSettings { this, &CGuiApplication::settingsChanged };
|
||||
BlackMisc::CSettingReadOnly<Settings::TUpdateNotificationSettings> m_updateSetting { this }; //!< update notification settings
|
||||
|
||||
|
||||
58
src/blackgui/splashscreen.cpp
Normal file
58
src/blackgui/splashscreen.cpp
Normal file
@@ -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);
|
||||
};
|
||||
}
|
||||
53
src/blackgui/splashscreen.h
Normal file
53
src/blackgui/splashscreen.h
Normal file
@@ -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 <QSplashScreen>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QLabel>
|
||||
#include <QFont>
|
||||
#include <QTimer>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user