summaryrefslogtreecommitdiffstats
path: root/examples/multimedia/spectrum/spectrograph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/multimedia/spectrum/spectrograph.cpp')
-rw-r--r--examples/multimedia/spectrum/spectrograph.cpp91
1 files changed, 22 insertions, 69 deletions
diff --git a/examples/multimedia/spectrum/spectrograph.cpp b/examples/multimedia/spectrum/spectrograph.cpp
index 2ab1127d7..96274b50b 100644
--- a/examples/multimedia/spectrum/spectrograph.cpp
+++ b/examples/multimedia/spectrum/spectrograph.cpp
@@ -1,54 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "spectrograph.h"
+
#include <QDebug>
#include <QMouseEvent>
#include <QPainter>
@@ -59,17 +13,16 @@ const int NullIndex = -1;
const int BarSelectionInterval = 2000;
Spectrograph::Spectrograph(QWidget *parent)
- : QWidget(parent)
- , m_barSelected(NullIndex)
- , m_timerId(NullTimerId)
- , m_lowFreq(0.0)
- , m_highFreq(0.0)
+ : QWidget(parent),
+ m_barSelected(NullIndex),
+ m_timerId(NullTimerId),
+ m_lowFreq(0.0),
+ m_highFreq(0.0)
{
setMinimumHeight(100);
}
-Spectrograph::~Spectrograph()
-= default;
+Spectrograph::~Spectrograph() = default;
void Spectrograph::setParams(int numBars, qreal lowFreq, qreal highFreq)
{
@@ -132,8 +85,8 @@ void Spectrograph::paintEvent(QPaintEvent *event)
if (numBars) {
const int numHorizontalSections = numBars;
QLine line(rect().topLeft(), rect().bottomLeft());
- for (int i=1; i<numHorizontalSections; ++i) {
- line.translate(rect().width()/numHorizontalSections, 0);
+ for (int i = 1; i < numHorizontalSections; ++i) {
+ line.translate(rect().width() / numHorizontalSections, 0);
painter.drawLine(line);
}
}
@@ -141,8 +94,8 @@ void Spectrograph::paintEvent(QPaintEvent *event)
// Draw horizontal lines
const int numVerticalSections = 10;
QLine line(rect().topLeft(), rect().topRight());
- for (int i=1; i<numVerticalSections; ++i) {
- line.translate(0, rect().height()/numVerticalSections);
+ for (int i = 1; i < numVerticalSections; ++i) {
+ line.translate(0, rect().height() / numVerticalSections);
painter.drawLine(line);
}
@@ -161,7 +114,7 @@ void Spectrograph::paintEvent(QPaintEvent *event)
const int leftPaddingWidth = (paddingWidth + gapWidth) / 2;
const int barHeight = rect().height() - 2 * gapWidth;
- for (int i=0; i<numBars; ++i) {
+ for (int i = 0; i < numBars; ++i) {
const qreal value = m_bars[i].value;
Q_ASSERT(value >= 0.0 && value <= 1.0);
QRect bar = rect();
@@ -203,7 +156,7 @@ int Spectrograph::barIndex(qreal frequency) const
Q_ASSERT(frequency >= m_lowFreq && frequency < m_highFreq);
const qreal bandWidth = (m_highFreq - m_lowFreq) / m_bars.count();
const int index = (frequency - m_lowFreq) / bandWidth;
- if (index <0 || index >= m_bars.count())
+ if (index < 0 || index >= m_bars.count())
Q_ASSERT(false);
return index;
}
@@ -212,7 +165,7 @@ QPair<qreal, qreal> Spectrograph::barRange(int index) const
{
Q_ASSERT(index >= 0 && index < m_bars.count());
const qreal bandWidth = (m_highFreq - m_lowFreq) / m_bars.count();
- return QPair<qreal, qreal>(index * bandWidth, (index+1) * bandWidth);
+ return QPair<qreal, qreal>(index * bandWidth, (index + 1) * bandWidth);
}
void Spectrograph::updateBars()
@@ -220,7 +173,7 @@ void Spectrograph::updateBars()
m_bars.fill(Bar());
FrequencySpectrum::const_iterator i = m_spectrum.begin();
const FrequencySpectrum::const_iterator end = m_spectrum.end();
- for ( ; i != end; ++i) {
+ for (; i != end; ++i) {
const FrequencySpectrum::Element e = *i;
if (e.frequency >= m_lowFreq && e.frequency < m_highFreq) {
Bar &bar = m_bars[barIndex(e.frequency)];
@@ -231,11 +184,11 @@ void Spectrograph::updateBars()
update();
}
-void Spectrograph::selectBar(int index) {
+void Spectrograph::selectBar(int index)
+{
const QPair<qreal, qreal> frequencyRange = barRange(index);
- const QString message = QString("%1 - %2 Hz")
- .arg(frequencyRange.first)
- .arg(frequencyRange.second);
+ const QString message =
+ QStringLiteral("%1 - %2 Hz").arg(frequencyRange.first).arg(frequencyRange.second);
emit infoMessage(message, BarSelectionInterval);
if (NullTimerId != m_timerId)
@@ -246,4 +199,4 @@ void Spectrograph::selectBar(int index) {
update();
}
-
+#include "moc_spectrograph.cpp"