SVSplash.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version. See the file
12  COPYING included with this distribution for more information.
13 */
14 
15 #include "SVSplash.h"
16 
17 #include "../version.h"
18 
19 #include <QPainter>
20 #include <QApplication>
21 #include <QScreen>
22 #include <QSvgRenderer>
23 
24 #include "system/System.h"
25 
26 #include <cmath>
27 
28 #include <iostream>
29 using namespace std;
30 
32 {
33  setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
34 
35  bool darkTheme = OSReportsDarkThemeActive();
36 
37  QPixmap *p1 = new QPixmap(QString(":icons/scalable/sv-splash.png"));
38 
39  int w = p1->width(), h = p1->height();
40  QScreen *screen = QApplication::primaryScreen();
41  QRect desk = screen->availableGeometry();
42 
43  double dpratio = devicePixelRatio();
44  double widthMultiple = double(desk.width()) / double(w);
45 
46  int sw = w, sh = h;
47 
48  if (widthMultiple > 2.5 || dpratio > 1.0 || darkTheme) {
49 
50  // Hi-dpi either via pixel doubling or simply via lots of
51  // pixels - or dark theme splash, for which we only have an
52  // svg version
53 
54  double factor = widthMultiple / 2.5;
55  if (factor < 1.0) factor = 1.0;
56  sw = int(floor(w * factor));
57  sh = int(floor(h * factor));
58 
59  delete p1;
60  m_pixmap = new QPixmap(int(floor(sw * dpratio)),
61  int(floor(sh * dpratio)));
62 
63 // cerr << "pixmap size = " << m_pixmap->width() << " * "
64 // << m_pixmap->height() << endl;
65 
66  m_pixmap->fill(Qt::white);
67  QString filename = "sv-splash";
68  if (darkTheme) {
69  filename = "sv-splash-dark";
70  }
71  QSvgRenderer renderer(QString(":icons/scalable/%1.svg").arg(filename));
72  QPainter painter(m_pixmap);
73  renderer.render(&painter);
74  painter.end();
75 
76  } else {
77  // The "low dpi" case
78  m_pixmap = p1;
79  }
80 
81  setFixedWidth(sw);
82  setFixedHeight(sh);
83  setGeometry(desk.x() + desk.width()/2 - sw/2,
84  desk.y() + desk.height()/2 - sh/2,
85  sw, sh);
86 }
87 
89 {
90  delete m_pixmap;
91 }
92 
93 void
95 {
96  finish(w);
97 }
98 
99 void
100 SVSplash::drawContents(QPainter *painter)
101 {
102  // Qt 5.13 deprecates QFontMetrics::width(), but its suggested
103  // replacement (horizontalAdvance) was only added in Qt 5.11
104  // which is too new for us
105 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
106 
107  painter->drawPixmap(rect(), *m_pixmap, m_pixmap->rect());
108  QString text = QString("v%1").arg(SV_VERSION);
109  painter->setPen(OSReportsDarkThemeActive() ? Qt::white : Qt::black);
110  painter->drawText
111  (width() - painter->fontMetrics().width(text) - (width()/50),
112  (width()/70) + painter->fontMetrics().ascent(),
113  text);
114 }
115 
116 
virtual ~SVSplash()
Definition: SVSplash.cpp:88
void finishSplash(QWidget *)
Definition: SVSplash.cpp:94
SVSplash()
Definition: SVSplash.cpp:31
void drawContents(QPainter *) override
Definition: SVSplash.cpp:100