comparison main/SVSplash.cpp @ 2463:7e70382e6ece background-mode

Render dark splash in dark mode (on platforms where OSReportsDarkThemeActive() works, i.e. only Windows at present - can't base this on actual UI colours as we haven't created the UI yet)
author Chris Cannam
date Fri, 24 Jan 2020 12:43:13 +0000
parents eb7f4579e5cc
children
comparison
equal deleted inserted replaced
2462:91154a387599 2463:7e70382e6ece
19 #include <QPainter> 19 #include <QPainter>
20 #include <QApplication> 20 #include <QApplication>
21 #include <QScreen> 21 #include <QScreen>
22 #include <QSvgRenderer> 22 #include <QSvgRenderer>
23 23
24 #include "system/System.h"
25
24 #include <cmath> 26 #include <cmath>
25 27
26 #include <iostream> 28 #include <iostream>
27 using namespace std; 29 using namespace std;
28 30
29 SVSplash::SVSplash() 31 SVSplash::SVSplash()
30 { 32 {
31 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); 33 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
34
35 bool darkTheme = OSReportsDarkThemeActive();
32 36
33 QPixmap *p1 = new QPixmap(":icons/scalable/sv-splash.png"); 37 QPixmap *p1 = new QPixmap(QString(":icons/scalable/sv-splash.png"));
34 38
35 int w = p1->width(), h = p1->height(); 39 int w = p1->width(), h = p1->height();
36 QScreen *screen = QApplication::primaryScreen(); 40 QScreen *screen = QApplication::primaryScreen();
37 QRect desk = screen->availableGeometry(); 41 QRect desk = screen->availableGeometry();
38 42
39 double dpratio = devicePixelRatio(); 43 double dpratio = devicePixelRatio();
40 double widthMultiple = double(desk.width()) / double(w); 44 double widthMultiple = double(desk.width()) / double(w);
41 45
42 int sw = w, sh = h; 46 int sw = w, sh = h;
43 47
44 if (widthMultiple > 2.5 || dpratio > 1.0) { 48 if (widthMultiple > 2.5 || dpratio > 1.0 || darkTheme) {
45 49
46 // Hi-dpi either via pixel doubling or simply via lots of 50 // Hi-dpi either via pixel doubling or simply via lots of
47 // pixels 51 // pixels - or dark theme splash, for which we only have an
52 // svg version
48 53
49 double factor = widthMultiple / 2.5; 54 double factor = widthMultiple / 2.5;
50 if (factor < 1.0) factor = 1.0; 55 if (factor < 1.0) factor = 1.0;
51 sw = int(floor(w * factor)); 56 sw = int(floor(w * factor));
52 sh = int(floor(h * factor)); 57 sh = int(floor(h * factor));
56 int(floor(sh * dpratio))); 61 int(floor(sh * dpratio)));
57 62
58 // cerr << "pixmap size = " << m_pixmap->width() << " * " 63 // cerr << "pixmap size = " << m_pixmap->width() << " * "
59 // << m_pixmap->height() << endl; 64 // << m_pixmap->height() << endl;
60 65
61 m_pixmap->fill(Qt::red); 66 m_pixmap->fill(Qt::white);
62 QSvgRenderer renderer(QString(":icons/scalable/sv-splash.svg")); 67 QString filename = "sv-splash";
68 if (darkTheme) {
69 filename = "sv-splash-dark";
70 }
71 QSvgRenderer renderer(QString(":icons/scalable/%1.svg").arg(filename));
63 QPainter painter(m_pixmap); 72 QPainter painter(m_pixmap);
64 renderer.render(&painter); 73 renderer.render(&painter);
65 painter.end(); 74 painter.end();
66 75
67 } else { 76 } else {
95 // which is too new for us 104 // which is too new for us
96 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 105 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
97 106
98 painter->drawPixmap(rect(), *m_pixmap, m_pixmap->rect()); 107 painter->drawPixmap(rect(), *m_pixmap, m_pixmap->rect());
99 QString text = QString("v%1").arg(SV_VERSION); 108 QString text = QString("v%1").arg(SV_VERSION);
100 painter->setPen(Qt::black); 109 painter->setPen(OSReportsDarkThemeActive() ? Qt::white : Qt::black);
101 painter->drawText 110 painter->drawText
102 (width() - painter->fontMetrics().width(text) - (width()/50), 111 (width() - painter->fontMetrics().width(text) - (width()/50),
103 (width()/70) + painter->fontMetrics().ascent(), 112 (width()/70) + painter->fontMetrics().ascent(),
104 text); 113 text);
105 } 114 }