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