annotate main/SVSplash.cpp @ 2560:cbde01e5c626 smoother-recording

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