annotate main/SVSplash.cpp @ 1464:cb41b2184622 3.0-integration

Next actual release will be 3.0-beta1
author Chris Cannam
date Tue, 03 Jan 2017 16:13:48 +0000
parents ee908153066e
children 893f556cd5c9
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@954 21 #include <QDesktopWidget>
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@954 36 QRect desk = QApplication::desktop()->availableGeometry();
Chris@954 37
Chris@954 38 double dpratio = devicePixelRatio();
Chris@954 39 double widthMultiple = double(desk.width()) / double(w);
Chris@954 40
Chris@954 41 int sw = w, sh = h;
Chris@954 42
Chris@954 43 if (widthMultiple > 2.5 || dpratio > 1.0) {
Chris@954 44
Chris@954 45 // Hi-dpi either via pixel doubling or simply via lots of
Chris@954 46 // pixels
Chris@954 47
Chris@954 48 double factor = widthMultiple / 2.5;
Chris@954 49 if (factor < 1.0) factor = 1.0;
Chris@954 50 sw = int(floor(w * factor));
Chris@954 51 sh = int(floor(h * factor));
Chris@954 52
Chris@954 53 delete p1;
Chris@954 54 m_pixmap = new QPixmap(int(floor(sw * dpratio)),
Chris@954 55 int(floor(sh * dpratio)));
Chris@954 56
Chris@1288 57 // cerr << "pixmap size = " << m_pixmap->width() << " * "
Chris@1288 58 // << m_pixmap->height() << endl;
Chris@954 59
Chris@954 60 m_pixmap->fill(Qt::red);
Chris@954 61 QSvgRenderer renderer(QString(":icons/scalable/sv-splash.svg"));
Chris@954 62 QPainter painter(m_pixmap);
Chris@954 63 renderer.render(&painter);
Chris@954 64 painter.end();
Chris@954 65
Chris@954 66 } else {
Chris@954 67 // The "low dpi" case
Chris@954 68 m_pixmap = p1;
Chris@954 69 }
Chris@954 70
Chris@954 71 setFixedWidth(sw);
Chris@954 72 setFixedHeight(sh);
Chris@954 73 setGeometry(desk.x() + desk.width()/2 - sw/2,
Chris@954 74 desk.y() + desk.height()/2 - sh/2,
Chris@954 75 sw, sh);
Chris@954 76 }
Chris@954 77
Chris@954 78 SVSplash::~SVSplash()
Chris@954 79 {
Chris@954 80 delete m_pixmap;
Chris@954 81 }
Chris@954 82
Chris@954 83 void
Chris@954 84 SVSplash::finishSplash(QWidget *w)
Chris@954 85 {
Chris@954 86 finish(w);
Chris@954 87 }
Chris@954 88
Chris@954 89 void
Chris@954 90 SVSplash::drawContents(QPainter *painter)
Chris@954 91 {
Chris@954 92 painter->drawPixmap(rect(), *m_pixmap, m_pixmap->rect());
Chris@954 93 QString text = QString("v%1").arg(SV_VERSION);
Chris@954 94 painter->drawText
Chris@954 95 (width() - painter->fontMetrics().width(text) - (width()/50),
Chris@956 96 (width()/70) + painter->fontMetrics().ascent(),
Chris@954 97 text);
Chris@954 98 }
Chris@954 99
Chris@954 100