Skip to content

Commit

Permalink
fixed musescore#16810: Progress dialog instead of splash screen for n…
Browse files Browse the repository at this point in the history
…ew instance
  • Loading branch information
Eism committed May 16, 2023
1 parent ba4ebb8 commit ee1005d
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 51 deletions.
10 changes: 8 additions & 2 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <QThreadPool>
#endif

#include "appshell/view/internal/splashscreen.h"
#include "appshell/view/internal/splashscreen/splashscreen.h"
#include "appshell/view/dockwindow/docksetup.h"

#include "modularity/ioc.h"
Expand Down Expand Up @@ -166,7 +166,13 @@ int App::run(int argc, char** argv)
#ifdef MUE_BUILD_APPSHELL_MODULE
SplashScreen* splashScreen = nullptr;
if (runMode == framework::IApplication::RunMode::GuiApp) {
splashScreen = new SplashScreen();
if (multiInstancesProvider()->isMainInstance()) {
splashScreen = new SplashScreen(SplashScreen::Default);
} else {
QString fileName = io::basename(startupScenario()->startupScorePath()).toQString();
splashScreen = new SplashScreen(SplashScreen::ForNewInstance, fileName);
}

splashScreen->show();
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "diagnostics/idiagnosticdrawprovider.h"
#include "autobot/iautobot.h"
#include "audio/iregisteraudiopluginsscenario.h"
#include "multiinstances/imultiinstancesprovider.h"

#include "ui/iuiconfiguration.h"
#include "notation/inotationconfiguration.h"
Expand Down Expand Up @@ -64,6 +65,7 @@ class App
INJECT(app, iex::audioexport::IAudioExportConfiguration, audioExportConfiguration)
INJECT(app, iex::videoexport::IVideoExportConfiguration, videoExportConfiguration)
INJECT(app, iex::guitarpro::IGuitarProConfiguration, guitarProConfiguration)
INJECT(app, mi::IMultiInstancesProvider, multiInstancesProvider)

public:
App();
Expand Down
8 changes: 6 additions & 2 deletions src/appshell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ 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
${CMAKE_CURRENT_LIST_DIR}/view/internal/splashscreen/splashscreen.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/splashscreen/splashscreen.h
${CMAKE_CURRENT_LIST_DIR}/view/internal/splashscreen/loadingscreenview.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/splashscreen/loadingscreenview.h
${CMAKE_CURRENT_LIST_DIR}/view/internal/splashscreen/newinstanceloadingscreenview.cpp
${CMAKE_CURRENT_LIST_DIR}/view/internal/splashscreen/newinstanceloadingscreenview.h
${DOCKWINDOW_SRC}
)

Expand Down
2 changes: 2 additions & 0 deletions src/appshell/internal/istartupscenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class IStartupScenario : MODULE_EXPORT_INTERFACE
virtual ~IStartupScenario() = default;

virtual void setStartupType(const std::optional<std::string>& type) = 0;

virtual io::path_t startupScorePath() const = 0;
virtual void setStartupScorePath(const std::optional<io::path_t>& path) = 0;

virtual void run() = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/appshell/internal/startupscenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ void StartupScenario::setStartupType(const std::optional<std::string>& type)
m_startupTypeStr = type ? type.value() : "";
}

mu::io::path_t StartupScenario::startupScorePath() const
{
return m_startupScorePath;
}

void StartupScenario::setStartupScorePath(const std::optional<io::path_t>& path)
{
m_startupScorePath = path ? path.value() : "";
Expand Down
2 changes: 2 additions & 0 deletions src/appshell/internal/startupscenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class StartupScenario : public IStartupScenario, public async::Asyncable
public:

void setStartupType(const std::optional<std::string>& type) override;

io::path_t startupScorePath() const override;
void setStartupScorePath(const std::optional<io::path_t>& path) override;

void run() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "splashscreen.h"
#include "loadingscreenview.h"

#include <QApplication>
#include <QPainter>
Expand All @@ -34,43 +34,28 @@ using namespace mu::appshell;

static const QString imagePath(":/resources/LoadingScreen.svg");

static constexpr QSize splashScreenSize(810, 405);
static constexpr QSize loadingScreenSize(810, 405);

static const QColor messageColor("#99FFFFFF");
static constexpr QRectF messageRect(splashScreenSize.width() / 2, 269, 0, 0);
static constexpr QRectF messageRect(loadingScreenSize.width() / 2, 269, 0, 0);

static const QString website("www.musescore.org");
static constexpr QRectF websiteRect(splashScreenSize.width() - 48, splashScreenSize.height() - 48, 0, 0);
static constexpr QRectF websiteRect(loadingScreenSize.width() - 48, loadingScreenSize.height() - 48, 0, 0);

static const QColor versionNumberColor("#22A0F4");
static constexpr qreal versionNumberSpacing = 5.0;

#ifdef Q_OS_MAC
// Necessary to remove undesired background, so that we really get our rounded corners
static constexpr Qt::WindowFlags splashScreenWindowFlags = (Qt::SplashScreen | Qt::FramelessWindowHint) & ~Qt::Sheet | Qt::Window;
#else
static constexpr Qt::WindowFlags splashScreenWindowFlags = Qt::SplashScreen | Qt::FramelessWindowHint;
#endif

SplashScreen::SplashScreen()
: QWidget(nullptr, splashScreenWindowFlags),
LoadingScreenView::LoadingScreenView(QWidget* parent)
: QWidget(parent),
m_backgroundRenderer(new QSvgRenderer(imagePath, this))
{
setAttribute(Qt::WA_TranslucentBackground);
setSize(splashScreenSize);
resize(loadingScreenSize);

m_message = qtrc("appshell", "Loading…\u200e");

repaint();
}

void SplashScreen::repaint()
{
QWidget::repaint();
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}

bool SplashScreen::event(QEvent* event)
bool LoadingScreenView::event(QEvent* event)
{
if (event->type() == QEvent::Paint) {
QPainter painter(this);
Expand All @@ -81,7 +66,7 @@ bool SplashScreen::event(QEvent* event)
return QWidget::event(event);
}

void SplashScreen::draw(QPainter* painter)
void LoadingScreenView::draw(QPainter* painter)
{
painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);

Expand Down Expand Up @@ -114,12 +99,3 @@ void SplashScreen::draw(QPainter* painter)
Qt::AlignBottom | alignment | Qt::TextDontClip,
qtrc("appshell", "Version %1").arg(QString::fromStdString(framework::MUVersion::fullVersion().toStdString())));
}

void SplashScreen::setSize(const QSize& size)
{
resize(size);

if (screen()) {
move(screen()->geometry().center() - QPoint(size.width() / 2, size.height() / 2));
}
}
54 changes: 54 additions & 0 deletions src/appshell/view/internal/splashscreen/loadingscreenview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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_LOADINGSCREENVIEW_H
#define MU_APPSHELL_LOADINGSCREENVIEW_H

#include <QWidget>

#include "modularity/ioc.h"
#include "ui/iuiconfiguration.h"
#include "languages/ilanguagesservice.h"

class QSvgRenderer;

namespace mu::appshell {
class LoadingScreenView : public QWidget
{
Q_OBJECT

INJECT(appshell, ui::IUiConfiguration, uiConfiguration)
INJECT(appshell, languages::ILanguagesService, languagesService)

public:
explicit LoadingScreenView(QWidget* parent = nullptr);

private:
bool event(QEvent* event) override;
void draw(QPainter* painter);

QString m_message;
QSvgRenderer* m_backgroundRenderer = nullptr;
};
}

#endif // MU_APPSHELL_LOADINGSCREENVIEW_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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 "newinstanceloadingscreenview.h"

#include <QApplication>
#include <QPainter>
#include <QScreen>

#include "translation.h"

using namespace mu::appshell;

NewInstanceLoadingScreenView::NewInstanceLoadingScreenView(const QString& openingFileName)
: QWidget(nullptr)
{
setAttribute(Qt::WA_TranslucentBackground);

if (openingFileName.isEmpty()) {
m_message = qtrc("appshell", "Loading new score…\u200e");
m_dialogSize = QSize(288, 80);
} else {
m_message = qtrc("appshell", "Loading \"%1\"\u200e").arg(openingFileName);
m_dialogSize = QSize(360, 80);
}

resize(m_dialogSize);
}

bool NewInstanceLoadingScreenView::event(QEvent* event)
{
if (event->type() == QEvent::Paint) {
QPainter painter(this);
painter.setLayoutDirection(layoutDirection());
draw(&painter);
}

return QWidget::event(event);
}

void NewInstanceLoadingScreenView::draw(QPainter* painter)
{
painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);

// Draw background
QString bgColorStr = uiConfiguration()->currentTheme().values.value(ui::BACKGROUND_PRIMARY_COLOR).toString();
painter->fillRect(0, 0, width(), height(), QColor(bgColorStr));

// Draw message
QFont font(QString::fromStdString(uiConfiguration()->fontFamily()));
font.setPixelSize(uiConfiguration()->fontSize(ui::FontSizeType::BODY_LARGE));
font.setBold(true);

painter->setFont(font);

QString messageColorStr = uiConfiguration()->currentTheme().values.value(ui::FONT_PRIMARY_COLOR).toString();
QPen pen(messageColorStr);
painter->setPen(pen);

const QRectF messageRect(m_dialogSize.width() / 2, m_dialogSize.height() / 2, 0, 0);
painter->drawText(messageRect, Qt::AlignCenter | Qt::TextDontClip, m_message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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_NEWINSTANCELOADINSCREENVIEW_H
#define MU_APPSHELL_NEWINSTANCELOADINSCREENVIEW_H

#include <QWidget>

#include "modularity/ioc.h"
#include "ui/iuiconfiguration.h"
#include "languages/ilanguagesservice.h"

class QSvgRenderer;

namespace mu::appshell {
class NewInstanceLoadingScreenView : public QWidget
{
Q_OBJECT

INJECT(appshell, ui::IUiConfiguration, uiConfiguration)
INJECT(appshell, languages::ILanguagesService, languagesService)

public:
explicit NewInstanceLoadingScreenView(const QString& openingFileName);

private:
bool event(QEvent* event) override;
void draw(QPainter* painter);

QString m_message;

QSize m_dialogSize;
};
}

#endif // MU_APPSHELL_NEWINSTANCELOADINSCREENVIEW_H
Loading

0 comments on commit ee1005d

Please sign in to comment.