annotate main/SVSplash.cpp @ 954:74b3eaa684d3 scalable-icons

Add splash screen code
author Chris Cannam
date Wed, 06 May 2015 13:02:28 +0100
parents
children 76b46442fc2d
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@954 24 #include <iostream>
Chris@954 25 using namespace std;
Chris@954 26
Chris@954 27 SVSplash::SVSplash()
Chris@954 28 {
Chris@954 29 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
Chris@954 30
Chris@954 31 QPixmap *p1 = new QPixmap(":icons/scalable/sv-splash.png");
Chris@954 32
Chris@954 33 int w = p1->width(), h = p1->height();
Chris@954 34 QRect desk = QApplication::desktop()->availableGeometry();
Chris@954 35
Chris@954 36 double dpratio = devicePixelRatio();
Chris@954 37 double widthMultiple = double(desk.width()) / double(w);
Chris@954 38
Chris@954 39 int sw = w, sh = h;
Chris@954 40
Chris@954 41 if (widthMultiple > 2.5 || dpratio > 1.0) {
Chris@954 42
Chris@954 43 // Hi-dpi either via pixel doubling or simply via lots of
Chris@954 44 // pixels
Chris@954 45
Chris@954 46 double factor = widthMultiple / 2.5;
Chris@954 47 if (factor < 1.0) factor = 1.0;
Chris@954 48 sw = int(floor(w * factor));
Chris@954 49 sh = int(floor(h * factor));
Chris@954 50
Chris@954 51 delete p1;
Chris@954 52 m_pixmap = new QPixmap(int(floor(sw * dpratio)),
Chris@954 53 int(floor(sh * dpratio)));
Chris@954 54
Chris@954 55 cerr << "pixmap size = " << m_pixmap->width() << " * "
Chris@954 56 << m_pixmap->height() << endl;
Chris@954 57
Chris@954 58 m_pixmap->fill(Qt::red);
Chris@954 59 QSvgRenderer renderer(QString(":icons/scalable/sv-splash.svg"));
Chris@954 60 QPainter painter(m_pixmap);
Chris@954 61 renderer.render(&painter);
Chris@954 62 painter.end();
Chris@954 63
Chris@954 64 } else {
Chris@954 65 // The "low dpi" case
Chris@954 66 m_pixmap = p1;
Chris@954 67 }
Chris@954 68
Chris@954 69 setFixedWidth(sw);
Chris@954 70 setFixedHeight(sh);
Chris@954 71 setGeometry(desk.x() + desk.width()/2 - sw/2,
Chris@954 72 desk.y() + desk.height()/2 - sh/2,
Chris@954 73 sw, sh);
Chris@954 74 }
Chris@954 75
Chris@954 76 SVSplash::~SVSplash()
Chris@954 77 {
Chris@954 78 delete m_pixmap;
Chris@954 79 }
Chris@954 80
Chris@954 81 void
Chris@954 82 SVSplash::finishSplash(QWidget *w)
Chris@954 83 {
Chris@954 84 finish(w);
Chris@954 85 }
Chris@954 86
Chris@954 87 void
Chris@954 88 SVSplash::drawContents(QPainter *painter)
Chris@954 89 {
Chris@954 90 painter->drawPixmap(rect(), *m_pixmap, m_pixmap->rect());
Chris@954 91 QString text = QString("v%1").arg(SV_VERSION);
Chris@954 92 painter->drawText
Chris@954 93 (width() - painter->fontMetrics().width(text) - (width()/50),
Chris@954 94 (width()/50) + painter->fontMetrics().ascent(),
Chris@954 95 text);
Chris@954 96 }
Chris@954 97
Chris@954 98