Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2022 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "loadingscreenview.h"
24 :
25 : #include <QApplication>
26 : #include <QPainter>
27 : #include <QScreen>
28 : #include <QSvgRenderer>
29 : #include <QFontDatabase>
30 :
31 : #include "translation.h"
32 : #include "global/internal/baseapplication.h"
33 :
34 : using namespace mu::appshell;
35 :
36 : static const QString imagePath(":/resources/LoadingScreen.svg");
37 :
38 : static constexpr QSize loadingScreenSize(800, 380);
39 :
40 : static const QColor messageColor("#F1F1EE");
41 :
42 : static const QString website("www.musescore.org");
43 : static constexpr QRectF websiteRect(loadingScreenSize.width() - 48, loadingScreenSize.height() - 48, 0, 0);
44 :
45 : static const QColor versionNumberColor("#19F3FF");
46 : static constexpr qreal versionNumberSpacing = 5.0;
47 :
48 0 : LoadingScreenView::LoadingScreenView(QWidget* parent)
49 : : QWidget(parent),
50 0 : m_backgroundRenderer(new QSvgRenderer(imagePath, this))
51 : {
52 0 : setAttribute(Qt::WA_TranslucentBackground);
53 0 : resize(loadingScreenSize);
54 0 : }
55 :
56 0 : bool LoadingScreenView::event(QEvent* event)
57 : {
58 0 : if (event->type() == QEvent::Paint) {
59 0 : QPainter painter(this);
60 0 : painter.setLayoutDirection(layoutDirection());
61 0 : draw(&painter);
62 0 : }
63 :
64 0 : return QWidget::event(event);
65 : }
66 :
67 0 : void LoadingScreenView::draw(QPainter* painter)
68 : {
69 0 : painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
70 :
71 : // Draw background
72 0 : m_backgroundRenderer->render(painter);
73 :
74 : // Draw message
75 0 : QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
76 0 : painter->setFont(font);
77 :
78 0 : QPen pen(messageColor);
79 0 : painter->setPen(pen);
80 :
81 0 : Qt::AlignmentFlag alignment = layoutDirection() == Qt::RightToLeft ? Qt::AlignLeft : Qt::AlignRight;
82 :
83 : // Draw website URL
84 0 : QRectF websiteBoundingRect;
85 0 : painter->drawText(websiteRect, Qt::AlignBottom | alignment | Qt::TextDontClip, website, &websiteBoundingRect);
86 :
87 : // Draw version number
88 0 : pen.setColor(versionNumberColor);
89 0 : painter->setPen(pen);
90 :
91 0 : painter->drawText(websiteRect.translated(0.0, -websiteBoundingRect.height() - versionNumberSpacing),
92 0 : Qt::AlignBottom | alignment | Qt::TextDontClip,
93 0 : muse::qtrc("appshell", "Version %1").arg(muse::BaseApplication::appFullVersion().toString()));
94 0 : }
|