annotate main/SVSplash.cpp @ 2446:0075f5b8f76c spectrogram-export

Only ask about writing a selection where the format supports it
author Chris Cannam
date Fri, 10 Jan 2020 14:31:42 +0000
parents eb7f4579e5cc
children 7e70382e6ece
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@955 24 #include <cmath>
Chris@955 25
Chris@954 26 #include <iostream>
Chris@954 27 using namespace std;
Chris@954 28
Chris@954 29 SVSplash::SVSplash()
Chris@954 30 {
Chris@954 31 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
Chris@954 32
Chris@954 33 QPixmap *p1 = new QPixmap(":icons/scalable/sv-splash.png");
Chris@954 34
Chris@954 35 int w = p1->width(), h = p1->height();
Chris@2300 36 QScreen *screen = QApplication::primaryScreen();
Chris@2300 37 QRect desk = screen->availableGeometry();
Chris@954 38
Chris@954 39 double dpratio = devicePixelRatio();
Chris@954 40 double widthMultiple = double(desk.width()) / double(w);
Chris@954 41
Chris@954 42 int sw = w, sh = h;
Chris@954 43
Chris@954 44 if (widthMultiple > 2.5 || dpratio > 1.0) {
Chris@954 45
Chris@1770 46 // Hi-dpi either via pixel doubling or simply via lots of
Chris@1770 47 // pixels
Chris@954 48
Chris@1770 49 double factor = widthMultiple / 2.5;
Chris@1770 50 if (factor < 1.0) factor = 1.0;
Chris@1770 51 sw = int(floor(w * factor));
Chris@1770 52 sh = int(floor(h * factor));
Chris@954 53
Chris@1770 54 delete p1;
Chris@1770 55 m_pixmap = new QPixmap(int(floor(sw * dpratio)),
Chris@1770 56 int(floor(sh * dpratio)));
Chris@954 57
Chris@1770 58 // cerr << "pixmap size = " << m_pixmap->width() << " * "
Chris@1770 59 // << m_pixmap->height() << endl;
Chris@1770 60
Chris@1770 61 m_pixmap->fill(Qt::red);
Chris@1770 62 QSvgRenderer renderer(QString(":icons/scalable/sv-splash.svg"));
Chris@1770 63 QPainter painter(m_pixmap);
Chris@1770 64 renderer.render(&painter);
Chris@1770 65 painter.end();
Chris@954 66
Chris@954 67 } else {
Chris@1770 68 // The "low dpi" case
Chris@1770 69 m_pixmap = p1;
Chris@954 70 }
Chris@954 71
Chris@954 72 setFixedWidth(sw);
Chris@954 73 setFixedHeight(sh);
Chris@954 74 setGeometry(desk.x() + desk.width()/2 - sw/2,
Chris@1770 75 desk.y() + desk.height()/2 - sh/2,
Chris@1770 76 sw, sh);
Chris@954 77 }
Chris@954 78
Chris@954 79 SVSplash::~SVSplash()
Chris@954 80 {
Chris@954 81 delete m_pixmap;
Chris@954 82 }
Chris@954 83
Chris@954 84 void
Chris@954 85 SVSplash::finishSplash(QWidget *w)
Chris@954 86 {
Chris@954 87 finish(w);
Chris@954 88 }
Chris@954 89
Chris@954 90 void
Chris@954 91 SVSplash::drawContents(QPainter *painter)
Chris@954 92 {
Chris@2300 93 // Qt 5.13 deprecates QFontMetrics::width(), but its suggested
Chris@2300 94 // replacement (horizontalAdvance) was only added in Qt 5.11
Chris@2300 95 // which is too new for us
Chris@2300 96 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Chris@2300 97
Chris@954 98 painter->drawPixmap(rect(), *m_pixmap, m_pixmap->rect());
Chris@954 99 QString text = QString("v%1").arg(SV_VERSION);
cannam@2085 100 painter->setPen(Qt::black);
Chris@954 101 painter->drawText
Chris@1770 102 (width() - painter->fontMetrics().width(text) - (width()/50),
Chris@1770 103 (width()/70) + painter->fontMetrics().ascent(),
Chris@1770 104 text);
Chris@954 105 }
Chris@954 106
Chris@954 107