annotate main/SVSplash.cpp @ 2032:40eb06ba0f1f

Use finer zoom levels for mouse-wheel zooming, as was already the case for the thumbwheel. Also extend thumbwheel to support pixels-per-frame
author Chris Cannam
date Wed, 10 Oct 2018 14:34:22 +0100
parents 893f556cd5c9
children 82cac4a6c581
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@1770 45 // Hi-dpi either via pixel doubling or simply via lots of
Chris@1770 46 // pixels
Chris@954 47
Chris@1770 48 double factor = widthMultiple / 2.5;
Chris@1770 49 if (factor < 1.0) factor = 1.0;
Chris@1770 50 sw = int(floor(w * factor));
Chris@1770 51 sh = int(floor(h * factor));
Chris@954 52
Chris@1770 53 delete p1;
Chris@1770 54 m_pixmap = new QPixmap(int(floor(sw * dpratio)),
Chris@1770 55 int(floor(sh * dpratio)));
Chris@954 56
Chris@1770 57 // cerr << "pixmap size = " << m_pixmap->width() << " * "
Chris@1770 58 // << m_pixmap->height() << endl;
Chris@1770 59
Chris@1770 60 m_pixmap->fill(Qt::red);
Chris@1770 61 QSvgRenderer renderer(QString(":icons/scalable/sv-splash.svg"));
Chris@1770 62 QPainter painter(m_pixmap);
Chris@1770 63 renderer.render(&painter);
Chris@1770 64 painter.end();
Chris@954 65
Chris@954 66 } else {
Chris@1770 67 // The "low dpi" case
Chris@1770 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@1770 74 desk.y() + desk.height()/2 - sh/2,
Chris@1770 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@1770 95 (width() - painter->fontMetrics().width(text) - (width()/50),
Chris@1770 96 (width()/70) + painter->fontMetrics().ascent(),
Chris@1770 97 text);
Chris@954 98 }
Chris@954 99
Chris@954 100