Mercurial > hg > sonic-visualiser
comparison 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 |
comparison
equal
deleted
inserted
replaced
953:4a8f87c175f7 | 954:74b3eaa684d3 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #include "SVSplash.h" | |
16 | |
17 #include "../version.h" | |
18 | |
19 #include <QPainter> | |
20 #include <QApplication> | |
21 #include <QDesktopWidget> | |
22 #include <QSvgRenderer> | |
23 | |
24 #include <iostream> | |
25 using namespace std; | |
26 | |
27 SVSplash::SVSplash() | |
28 { | |
29 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); | |
30 | |
31 QPixmap *p1 = new QPixmap(":icons/scalable/sv-splash.png"); | |
32 | |
33 int w = p1->width(), h = p1->height(); | |
34 QRect desk = QApplication::desktop()->availableGeometry(); | |
35 | |
36 double dpratio = devicePixelRatio(); | |
37 double widthMultiple = double(desk.width()) / double(w); | |
38 | |
39 int sw = w, sh = h; | |
40 | |
41 if (widthMultiple > 2.5 || dpratio > 1.0) { | |
42 | |
43 // Hi-dpi either via pixel doubling or simply via lots of | |
44 // pixels | |
45 | |
46 double factor = widthMultiple / 2.5; | |
47 if (factor < 1.0) factor = 1.0; | |
48 sw = int(floor(w * factor)); | |
49 sh = int(floor(h * factor)); | |
50 | |
51 delete p1; | |
52 m_pixmap = new QPixmap(int(floor(sw * dpratio)), | |
53 int(floor(sh * dpratio))); | |
54 | |
55 cerr << "pixmap size = " << m_pixmap->width() << " * " | |
56 << m_pixmap->height() << endl; | |
57 | |
58 m_pixmap->fill(Qt::red); | |
59 QSvgRenderer renderer(QString(":icons/scalable/sv-splash.svg")); | |
60 QPainter painter(m_pixmap); | |
61 renderer.render(&painter); | |
62 painter.end(); | |
63 | |
64 } else { | |
65 // The "low dpi" case | |
66 m_pixmap = p1; | |
67 } | |
68 | |
69 setFixedWidth(sw); | |
70 setFixedHeight(sh); | |
71 setGeometry(desk.x() + desk.width()/2 - sw/2, | |
72 desk.y() + desk.height()/2 - sh/2, | |
73 sw, sh); | |
74 } | |
75 | |
76 SVSplash::~SVSplash() | |
77 { | |
78 delete m_pixmap; | |
79 } | |
80 | |
81 void | |
82 SVSplash::finishSplash(QWidget *w) | |
83 { | |
84 finish(w); | |
85 } | |
86 | |
87 void | |
88 SVSplash::drawContents(QPainter *painter) | |
89 { | |
90 painter->drawPixmap(rect(), *m_pixmap, m_pixmap->rect()); | |
91 QString text = QString("v%1").arg(SV_VERSION); | |
92 painter->drawText | |
93 (width() - painter->fontMetrics().width(text) - (width()/50), | |
94 (width()/50) + painter->fontMetrics().ascent(), | |
95 text); | |
96 } | |
97 | |
98 |