2 #include <score/model/Skin.hpp>
3 #include <score/widgets/Pixmap.hpp>
5 #include <core/view/QRecentFilesMenu.h>
7 #include <QApplication>
8 #include <QDesktopServices>
11 #include <QNetworkAccessManager>
12 #include <QNetworkReply>
13 #include <QNetworkRequest>
19 #include <score_git_info.hpp>
26 template <
typename OnSuccess,
typename OnError>
27 class HTTPGet final :
public QNetworkAccessManager
30 explicit HTTPGet(QUrl url, OnSuccess on_success, OnError on_error) noexcept
31 : m_callback{std::move(on_success)}
32 , m_error{std::move(on_error)}
34 connect(
this, &QNetworkAccessManager::finished,
this, [
this](QNetworkReply* reply) {
37 qDebug() << reply->errorString();
42 m_callback(reply->readAll());
49 QNetworkRequest req{std::move(url)};
50 req.setRawHeader(
"User-Agent",
"curl/7.35.0");
52 req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute,
true);
54 QNetworkRequest::RedirectPolicyAttribute,
55 QNetworkRequest::UserVerifiedRedirectPolicy);
56 req.setAttribute(QNetworkRequest::Http2AllowedAttribute,
true);
58 auto reply = get(req);
59 connect(reply, &QNetworkReply::redirected, reply, &QNetworkReply::redirectAllowed);
73 const QFont& font,
const QString& text,
const QString url, QWidget* parent = 0);
75 void setOpenExternalLink(
bool val) { m_openExternalLink = val; }
76 void setPixmaps(
const QPixmap& pixmap,
const QPixmap& pixmapOn);
78 void disableInteractivity();
79 void setActiveColor(
const QColor& c);
81 void labelPressed(
const QString& file) W_SIGNAL(labelPressed, file)
84 void paintEvent(QPaintEvent* event)
override;
85 void enterEvent(QEnterEvent* event)
override;
86 void leaveEvent(QEvent* event)
override;
87 void mousePressEvent(QMouseEvent* event)
override;
94 bool m_openExternalLink;
97 QPixmap m_currentPixmap;
102 QColor m_currentColor;
103 QColor m_activeColor;
106 InteractiveLabel::InteractiveLabel(
107 const QFont& font,
const QString& title,
const QString url, QWidget* parent)
112 , m_openExternalLink(false)
113 , m_drawPixmap(false)
114 , m_interactive(true)
116 auto& skin = score::Skin::instance();
117 m_currentColor = QColor{
"#f0f0f0"};
118 m_activeColor = QColor{
"#03C3DD"};
120 setFixedSize(200, 34);
123 void InteractiveLabel::setPixmaps(
const QPixmap& pixmap,
const QPixmap& pixmapOn)
127 m_pixmapOn = pixmapOn;
128 m_currentPixmap = m_pixmap;
131 void InteractiveLabel::disableInteractivity()
133 m_interactive =
false;
137 void InteractiveLabel::setActiveColor(
const QColor& c)
142 void InteractiveLabel::paintEvent(QPaintEvent* event)
144 QPainter painter(
this);
146 painter.setRenderHint(QPainter::Antialiasing,
true);
147 painter.setRenderHint(QPainter::TextAntialiasing,
true);
148 painter.setPen(QPen{m_currentColor});
150 QRectF textRect = rect();
153 int size = m_currentPixmap.width();
154 painter.drawPixmap(0, 0, m_currentPixmap);
155 textRect.setX(textRect.x() + size / qApp->devicePixelRatio() + 6);
157 painter.setFont(m_font);
158 painter.drawText(textRect, m_title);
161 void InteractiveLabel::enterEvent(QEnterEvent* event)
166 m_currentColor = m_activeColor;
167 m_font.setUnderline(
true);
168 m_currentPixmap = m_pixmapOn;
173 void InteractiveLabel::leaveEvent(QEvent* event)
178 m_currentColor = QColor{
"#f0f0f0"};
179 m_font.setUnderline(
false);
180 m_currentPixmap = m_pixmap;
185 void InteractiveLabel::mousePressEvent(QMouseEvent* event)
187 if(m_openExternalLink)
189 QDesktopServices::openUrl(QUrl(m_url));
201 StartScreen(
const QPointer<QRecentFilesMenu>& recentFiles, QWidget* parent = 0);
203 void openNewDocument() W_SIGNAL(openNewDocument)
204 void openFile(
const QString& file) W_SIGNAL(openFile, file)
205 void openFileDialog() W_SIGNAL(openFileDialog)
206 void loadCrashedSession() W_SIGNAL(loadCrashedSession)
207 void exitApp() W_SIGNAL(exitApp)
209 void addLoadCrashedSession();
212 void paintEvent(QPaintEvent* event)
override;
213 void keyPressEvent(QKeyEvent* event)
override;
216 QPixmap m_background;
226 const QString& n,
const QString& u,
const QString& p,
const QString& pOn)
235 StartScreen::StartScreen(
const QPointer<QRecentFilesMenu>& recentFiles, QWidget* parent)
239 #if defined(__APPLE__)
240 static constexpr
double font_factor = 96. / 72.;
242 static constexpr
double font_factor = 1.;
244 QFont f(
"Ubuntu", 14 * font_factor, QFont::Light);
245 f.setHintingPreference(QFont::HintingPreference::PreferFullHinting);
246 f.setStyleStrategy(QFont::PreferAntialias);
248 QFont titleFont(
"Montserrat", 14 * font_factor, QFont::DemiBold);
249 titleFont.setHintingPreference(QFont::HintingPreference::PreferFullHinting);
250 titleFont.setStyleStrategy(QFont::PreferAntialias);
252 this->setEnabled(
true);
253 setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
254 setWindowModality(Qt::ApplicationModal);
256 m_background = score::get_pixmap(
":/startscreen/startscreensplash.png");
258 if(QPainter painter; painter.begin(&m_background))
260 painter.setRenderHint(QPainter::Antialiasing,
true);
261 painter.setRenderHint(QPainter::TextAntialiasing,
true);
262 painter.setPen(QPen(QColor(
"#0092CF")));
266 painter.drawText(QPointF(381, 195), QCoreApplication::applicationVersion());
271 setFixedSize(m_background.size() / std::floor(qApp->devicePixelRatio()));
275 InteractiveLabel* label =
new InteractiveLabel{titleFont, qApp->tr(
"New"),
"",
this};
277 score::get_pixmap(
":/icons/new_file_off.png"),
278 score::get_pixmap(
":/icons/new_file_on.png"));
280 label, &score::InteractiveLabel::labelPressed,
this,
281 &score::StartScreen::openNewDocument);
282 label->move(100, label_y);
286 InteractiveLabel* label
287 =
new InteractiveLabel{titleFont, qApp->tr(
"Load"),
"",
this};
289 score::get_pixmap(
":/icons/load_off.png"),
290 score::get_pixmap(
":/icons/load_on.png"));
292 label, &score::InteractiveLabel::labelPressed,
this,
293 &score::StartScreen::openFileDialog);
294 label->move(100, label_y);
299 auto library_path = settings.value(
"Library/RootPath").toString();
300 InteractiveLabel* label =
new InteractiveLabel{
301 titleFont, qApp->tr(
"Examples"),
"https://github.com/ossia/score-examples",
this};
303 score::get_pixmap(
":/icons/load_examples_off.png"),
304 score::get_pixmap(
":/icons/load_examples_on.png"));
305 label->setOpenExternalLink(
true);
306 label->move(100, label_y);
310 InteractiveLabel* label
311 =
new InteractiveLabel{titleFont, qApp->tr(
"Exit"),
"",
this};
313 score::get_pixmap(
":/icons/exit_off.png"),
314 score::get_pixmap(
":/icons/exit_on.png"));
316 label, &score::InteractiveLabel::labelPressed,
this,
317 &score::StartScreen::exitApp);
318 label->move(100, label_y);
323 InteractiveLabel* label
324 =
new InteractiveLabel{titleFont, qApp->tr(
"Recent files"),
"",
this};
326 score::get_pixmap(
":/icons/recent_files.png"),
327 score::get_pixmap(
":/icons/recent_files.png"));
328 label->disableInteractivity();
329 label->move(280, label_y);
334 auto m_getLastVersion =
new HTTPGet{
335 QUrl(
"https://ossia.io/score-last-version.txt"),
336 [=](
const QByteArray& data) {
337 auto version = QString::fromUtf8(data.simplified());
338 if(SCORE_TAG_NO_V < version)
341 = qApp->tr(
"New version %1 is available, click to update !").arg(version);
342 QString url =
"https://github.com/ossia/score/releases/latest/";
343 InteractiveLabel* label =
new InteractiveLabel{titleFont, text, url,
this};
345 score::get_pixmap(
":/icons/version_off.png"),
346 score::get_pixmap(
":/icons/version_on.png"));
347 label->setOpenExternalLink(
true);
348 label->setFixedWidth(600);
349 label->move(140, 245);
356 for(
const auto& action : recentFiles->actions())
358 InteractiveLabel* fileLabel
359 =
new InteractiveLabel{f, action->text(), action->data().toString(),
this};
361 fileLabel, &score::InteractiveLabel::labelPressed,
this,
362 &score::StartScreen::openFile);
364 fileLabel->move(310, label_y);
369 std::array<score::StartScreenLink, 4> menus
370 = {{{qApp->tr(
"Tutorials"),
371 "https://www.youtube.com/"
372 "watch?v=R-3d8K6gQkw&list=PLIHLSiZpIa6YoY1_aW1yetDgZ7tZcxfEC&index=1",
373 ":/icons/tutorials_off.png",
":/icons/tutorials_on.png"},
374 {qApp->tr(
"Contribute"),
"https://opencollective.com/ossia/contribute",
375 ":/icons/contribute_off.png",
":/icons/contribute_on.png"},
376 {qApp->tr(
"Forum"),
"http://forum.ossia.io/",
":/icons/forum_off.png",
377 ":/icons/forum_on.png"},
378 {qApp->tr(
"Chat"),
"https://gitter.im/ossia/score",
":/icons/chat_off.png",
379 ":/icons/chat_on.png"}}};
381 for(
const auto& m : menus)
383 InteractiveLabel* menu_url =
new InteractiveLabel{titleFont, m.name, m.url,
this};
384 menu_url->setOpenExternalLink(
true);
385 menu_url->setPixmaps(score::get_pixmap(m.pixmap), score::get_pixmap(m.pixmapOn));
386 menu_url->move(530, label_y);
390 m_crashLabel =
new InteractiveLabel{
391 titleFont, qApp->tr(
"Reload your previously crashed work ?"),
"",
this};
392 m_crashLabel->setPixmaps(
393 score::get_pixmap(
":/icons/reload_crash_off.png"),
394 score::get_pixmap(
":/icons/reload_crash_on.png"));
395 m_crashLabel->move(150, 460);
396 m_crashLabel->setFixedWidth(600);
397 m_crashLabel->setActiveColor(QColor{
"#f6a019"});
398 m_crashLabel->setDisabled(
true);
399 m_crashLabel->hide();
401 m_crashLabel, &score::InteractiveLabel::labelPressed,
this,
402 &score::StartScreen::loadCrashedSession);
405 void StartScreen::addLoadCrashedSession()
407 m_crashLabel->show();
408 m_crashLabel->setEnabled(
true);
412 void StartScreen::paintEvent(QPaintEvent* event)
414 QPainter painter(
this);
415 painter.drawPixmap(0, 0, m_background);
418 void StartScreen::keyPressEvent(QKeyEvent* event)
420 if(event->key() == Qt::Key_Escape)
422 this->openNewDocument();
424 return QWidget::keyPressEvent(event);
Definition: StartScreen.hpp:28
Definition: StartScreen.hpp:68
Definition: StartScreen.hpp:198
Base toolkit upon which the software is built.
Definition: Application.cpp:90
void setCursor(Qt::CursorShape c)
setCursor sets the cursor safely.
Definition: ClearLayout.cpp:8
Definition: StartScreen.hpp:220