Merge pull request #12396 from cbjeukendrup/try_splashscreen

Implement Loading Screen
This commit is contained in:
RomanPudashkin 2022-07-14 15:19:03 +03:00 committed by GitHub
commit d916c4d402
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 149 additions and 0 deletions

View file

@ -102,6 +102,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/view/internal/iappmenumodelhook.h
${CMAKE_CURRENT_LIST_DIR}/view/internal/maintoolbarmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/maintoolbarmodel.h
${CMAKE_CURRENT_LIST_DIR}/view/internal/splashscreen.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/splashscreen.h
${DOCKWINDOW_SRC}
)

View file

@ -30,6 +30,9 @@
#ifndef Q_OS_WASM
#include <QThreadPool>
#endif
#include "view/internal/splashscreen.h"
#include "view/dockwindow/docksetup.h"
#include "modularity/ioc.h"
@ -127,6 +130,11 @@ int AppShell::run(int argc, char** argv)
commandLine.apply();
framework::IApplication::RunMode runMode = muapplication()->runMode();
SplashScreen splashScreen;
if (runMode == framework::IApplication::RunMode::Editor) {
splashScreen.show();
}
// ====================================================
// Setup modules: onInit
// ====================================================
@ -228,6 +236,8 @@ int AppShell::run(int argc, char** argv)
QQuickWindow::setDefaultAlphaBuffer(true);
engine->load(url);
splashScreen.close();
}
}

View file

@ -104,5 +104,6 @@
<file>qml/platform/win/AppSystemButtons.qml</file>
<file>qml/platform/AppMenuBar.qml</file>
<file>qml/platform/AppButtonBackground.qml</file>
<file>resources/LoadingScreen.svg</file>
</qresource>
</RCC>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 7.9 KiB

View file

@ -0,0 +1,83 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2022 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "splashscreen.h"
#include <QPainter>
#include <QSvgRenderer>
#include "version.h"
using namespace mu::appshell;
static const QString imagePath(":/resources/LoadingScreen.svg");
static const QSize splashScreenSize(810, 405);
static const QColor messageColor("#99FFFFFF");
static const QRectF messageRect(splashScreenSize.width() / 2, 269, 0, 0);
static const QString website("www.musescore.org");
static const QRectF websiteRect(splashScreenSize.width() - 48, splashScreenSize.height() - 48, 0, 0);
static const QColor versionNumberColor("#22A0F4");
static constexpr qreal versionNumberSpacing = 5.0;
SplashScreen::SplashScreen()
: QSplashScreen(QPixmap(splashScreenSize)),
m_backgroundRenderer(new QSvgRenderer(imagePath, this))
{
// Can't make translatable, because translation system not yet initialized
showMessage("Loading…");
}
void SplashScreen::drawContents(QPainter* painter)
{
painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
// Draw background
m_backgroundRenderer->render(painter);
// Draw message
// Can't use font from settings, because that's not yet initialized
QFont font(QString::fromStdString(uiConfiguration()->defaultFontFamily()));
font.setPixelSize(uiConfiguration()->defaultFontSize());
painter->setFont(font);
QPen pen(messageColor);
painter->setPen(pen);
painter->drawText(messageRect, Qt::AlignTop | Qt::AlignHCenter | Qt::TextDontClip, message());
// Draw website URL
QRectF websiteBoundingRect;
painter->drawText(websiteRect, Qt::AlignBottom | Qt::AlignRight | Qt::TextDontClip, website, &websiteBoundingRect);
// Draw version number
pen.setColor(versionNumberColor);
painter->setPen(pen);
painter->drawText(websiteRect.translated(0.0, -websiteBoundingRect.height() - versionNumberSpacing),
Qt::AlignBottom | Qt::AlignRight | Qt::TextDontClip,
QString("Version %1").arg(QString::fromStdString(framework::Version::fullVersion())));
}

View file

@ -0,0 +1,52 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2022 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MU_APPSHELL_SPLASHSCREEN_H
#define MU_APPSHELL_SPLASHSCREEN_H
#include <QSplashScreen>
#include "modularity/ioc.h"
#include "ui/iuiconfiguration.h"
class QSvgRenderer;
namespace mu::appshell {
class SplashScreen : public QSplashScreen
{
Q_OBJECT
//! The uiConfiguration has not yet been initialized, so we can't use user settings.
//! We only use it for querying the default system font
INJECT(appshell, ui::IUiConfiguration, uiConfiguration)
public:
SplashScreen();
private:
void drawContents(QPainter* painter) override;
QSvgRenderer* m_backgroundRenderer = nullptr;
};
}
#endif // MU_APPSHELL_SPLASHSCREEN_H