Add files from zip
This commit is contained in:
206
examples/radio/AmplifierBox.cpp
Normal file
206
examples/radio/AmplifierBox.cpp
Normal file
@@ -0,0 +1,206 @@
|
||||
/******************************************************************************
|
||||
* Qwt Widget Library
|
||||
* Copyright (C) 1997 Josef Wilgen
|
||||
* Copyright (C) 2002 Uwe Rathmann
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Qwt License, Version 1.0
|
||||
*****************************************************************************/
|
||||
|
||||
#include "AmplifierBox.h"
|
||||
|
||||
#include <QwtKnob>
|
||||
#include <QwtThermo>
|
||||
#include <QwtRoundScaleDraw>
|
||||
#include <QwtMath>
|
||||
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include <QResizeEvent>
|
||||
#include <qmath.h>
|
||||
|
||||
class Knob : public QWidget
|
||||
{
|
||||
public:
|
||||
Knob( const QString& title, double min, double max, QWidget* parent = NULL )
|
||||
: QWidget( parent )
|
||||
{
|
||||
m_knob = new QwtKnob( this );
|
||||
m_knob->setScale( min, max );
|
||||
m_knob->setTotalSteps( 0 ); // disable
|
||||
m_knob->setScaleMaxMajor( 10 );
|
||||
|
||||
m_knob->setKnobStyle( QwtKnob::Raised );
|
||||
m_knob->setKnobWidth( 50 );
|
||||
m_knob->setBorderWidth( 2 );
|
||||
m_knob->setMarkerStyle( QwtKnob::Notch );
|
||||
m_knob->setMarkerSize( 8 );
|
||||
|
||||
m_knob->scaleDraw()->setTickLength( QwtScaleDiv::MinorTick, 4 );
|
||||
m_knob->scaleDraw()->setTickLength( QwtScaleDiv::MediumTick, 4 );
|
||||
m_knob->scaleDraw()->setTickLength( QwtScaleDiv::MajorTick, 6 );
|
||||
|
||||
m_label = new QLabel( title, this );
|
||||
m_label->setAlignment( Qt::AlignTop | Qt::AlignHCenter );
|
||||
|
||||
setSizePolicy( QSizePolicy::MinimumExpanding,
|
||||
QSizePolicy::MinimumExpanding );
|
||||
}
|
||||
|
||||
virtual QSize sizeHint() const QWT_OVERRIDE
|
||||
{
|
||||
QSize sz1 = m_knob->sizeHint();
|
||||
QSize sz2 = m_label->sizeHint();
|
||||
|
||||
const int w = qMax( sz1.width(), sz2.width() );
|
||||
const int h = sz1.height() + sz2.height();
|
||||
|
||||
int off = qCeil( m_knob->scaleDraw()->extent( m_knob->font() ) );
|
||||
off -= 10; // spacing
|
||||
|
||||
return QSize( w, h - off );
|
||||
}
|
||||
|
||||
void setValue( double value )
|
||||
{
|
||||
m_knob->setValue( value );
|
||||
}
|
||||
|
||||
double value() const
|
||||
{
|
||||
return m_knob->value();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent( QResizeEvent* event ) QWT_OVERRIDE
|
||||
{
|
||||
const QSize sz = event->size();
|
||||
|
||||
int h = m_label->sizeHint().height();
|
||||
|
||||
m_label->setGeometry( 0, sz.height() - h, sz.width(), h );
|
||||
|
||||
h = m_knob->sizeHint().height();
|
||||
int off = qCeil( m_knob->scaleDraw()->extent( m_knob->font() ) );
|
||||
off -= 10; // spacing
|
||||
|
||||
m_knob->setGeometry( 0, m_label->pos().y() - h + off,
|
||||
sz.width(), h );
|
||||
}
|
||||
|
||||
private:
|
||||
QwtKnob* m_knob;
|
||||
QLabel* m_label;
|
||||
};
|
||||
|
||||
class Thermo : public QWidget
|
||||
{
|
||||
public:
|
||||
Thermo( const QString& title, QWidget* parent = NULL )
|
||||
: QWidget( parent )
|
||||
{
|
||||
m_thermo = new QwtThermo( this );
|
||||
m_thermo->setPipeWidth( 6 );
|
||||
m_thermo->setScale( -40, 10 );
|
||||
m_thermo->setFillBrush( Qt::green );
|
||||
m_thermo->setAlarmBrush( Qt::red );
|
||||
m_thermo->setAlarmLevel( 0.0 );
|
||||
m_thermo->setAlarmEnabled( true );
|
||||
|
||||
QLabel* label = new QLabel( title, this );
|
||||
label->setAlignment( Qt::AlignTop | Qt::AlignLeft );
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout( this );
|
||||
layout->setContentsMargins( QMargins() );
|
||||
layout->setSpacing( 0 );
|
||||
layout->addWidget( m_thermo, 10 );
|
||||
layout->addWidget( label );
|
||||
}
|
||||
|
||||
void setValue( double value )
|
||||
{
|
||||
m_thermo->setValue( value );
|
||||
}
|
||||
|
||||
private:
|
||||
QwtThermo* m_thermo;
|
||||
};
|
||||
|
||||
AmplifierBox::AmplifierBox( QWidget* p )
|
||||
: QFrame( p )
|
||||
{
|
||||
m_knobVolume = new Knob( "Volume", 0, 10 );
|
||||
m_knobBalance = new Knob( "Balance", -10, 10 );
|
||||
m_knobTreble = new Knob( "Treble", -10, 10 );
|
||||
m_knobBass = new Knob( "Bass", -10, 10 );
|
||||
|
||||
m_gaugeLeft = new Thermo( "Left [dB]" );
|
||||
m_gaugeRight = new Thermo( "Right [dB]" );
|
||||
|
||||
QHBoxLayout* layout = new QHBoxLayout( this );
|
||||
layout->setSpacing( 0 );
|
||||
layout->setContentsMargins( 10, 10, 10, 10 );
|
||||
layout->addWidget( m_knobVolume );
|
||||
layout->addWidget( m_knobBalance);
|
||||
layout->addWidget( m_knobTreble);
|
||||
layout->addWidget( m_knobBass );
|
||||
layout->addSpacing( 20 );
|
||||
layout->addStretch( 10 );
|
||||
layout->addWidget( m_gaugeLeft );
|
||||
layout->addSpacing( 10 );
|
||||
layout->addWidget( m_gaugeRight );
|
||||
|
||||
m_knobVolume->setValue( 7.0 );
|
||||
( void )startTimer( 50 );
|
||||
}
|
||||
|
||||
void AmplifierBox::timerEvent( QTimerEvent* )
|
||||
{
|
||||
static double phase = 0;
|
||||
|
||||
// This amplifier generates its own input signal...
|
||||
|
||||
const double sig_bass = ( 1.0 + 0.1 * m_knobBass->value() )
|
||||
* std::sin( 13.0 * phase );
|
||||
const double sig_mim_l = std::sin( 17.0 * phase );
|
||||
const double sig_mim_r = std::cos( 17.5 * phase );
|
||||
const double sig_trbl_l = 0.5 * ( 1.0 + 0.1 * m_knobTreble->value() )
|
||||
* std::sin( 35.0 * phase );
|
||||
const double sig_trbl_r = 0.5 * ( 1.0 + 0.1 * m_knobTreble->value() )
|
||||
* std::sin( 34.0 * phase );
|
||||
|
||||
double sig_l = 0.05 * m_master * m_knobVolume->value()
|
||||
* qwtSqr( sig_bass + sig_mim_l + sig_trbl_l );
|
||||
double sig_r = 0.05 * m_master * m_knobVolume->value()
|
||||
* qwtSqr( sig_bass + sig_mim_r + sig_trbl_r );
|
||||
|
||||
double balance = 0.1 * m_knobBalance->value();
|
||||
if ( balance > 0 )
|
||||
sig_l *= ( 1.0 - balance );
|
||||
else
|
||||
sig_r *= ( 1.0 + balance );
|
||||
|
||||
if ( sig_l > 0.01 )
|
||||
sig_l = 20.0 * log10( sig_l );
|
||||
else
|
||||
sig_l = -40.0;
|
||||
|
||||
if ( sig_r > 0.01 )
|
||||
sig_r = 20.0 * log10( sig_r );
|
||||
else
|
||||
sig_r = -40.0;
|
||||
|
||||
m_gaugeLeft->setValue( sig_l );
|
||||
m_gaugeRight->setValue( sig_r );
|
||||
|
||||
phase += M_PI / 100;
|
||||
if ( phase > M_PI )
|
||||
phase = 0;
|
||||
}
|
||||
|
||||
void AmplifierBox::setMaster( double v )
|
||||
{
|
||||
m_master = v;
|
||||
}
|
||||
|
||||
#include "moc_AmplifierBox.cpp"
|
||||
41
examples/radio/AmplifierBox.h
Normal file
41
examples/radio/AmplifierBox.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Widget Library
|
||||
* Copyright (C) 1997 Josef Wilgen
|
||||
* Copyright (C) 2002 Uwe Rathmann
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Qwt License, Version 1.0
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QwtGlobal>
|
||||
#include <QFrame>
|
||||
|
||||
class Knob;
|
||||
class Thermo;
|
||||
|
||||
class AmplifierBox : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AmplifierBox( QWidget* = NULL );
|
||||
|
||||
public Q_SLOTS:
|
||||
void setMaster( double v );
|
||||
|
||||
protected:
|
||||
virtual void timerEvent( QTimerEvent* ) QWT_OVERRIDE;
|
||||
|
||||
private:
|
||||
Knob* m_knobVolume;
|
||||
Knob* m_knobBalance;
|
||||
Knob* m_knobTreble;
|
||||
Knob* m_knobBass;
|
||||
|
||||
Thermo* m_gaugeLeft;
|
||||
Thermo* m_gaugeRight;
|
||||
|
||||
double m_master;
|
||||
};
|
||||
121
examples/radio/TunerBox.cpp
Normal file
121
examples/radio/TunerBox.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/******************************************************************************
|
||||
* Qwt Widget Library
|
||||
* Copyright (C) 1997 Josef Wilgen
|
||||
* Copyright (C) 2002 Uwe Rathmann
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Qwt License, Version 1.0
|
||||
*****************************************************************************/
|
||||
|
||||
#include "TunerBox.h"
|
||||
|
||||
#include <QwtWheel>
|
||||
#include <QwtSlider>
|
||||
#include <QwtThermo>
|
||||
#include <QwtMath>
|
||||
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
|
||||
class TuningThermo : public QWidget
|
||||
{
|
||||
public:
|
||||
TuningThermo( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
m_thermo = new QwtThermo( this );
|
||||
m_thermo->setOrientation( Qt::Horizontal );
|
||||
m_thermo->setScalePosition( QwtThermo::NoScale );
|
||||
m_thermo->setScale( 0.0, 1.0 );
|
||||
m_thermo->setFillBrush( Qt::green );
|
||||
|
||||
QLabel* label = new QLabel( "Tuning", this );
|
||||
label->setAlignment( Qt::AlignCenter );
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout( this );
|
||||
layout->setContentsMargins( QMargins() );
|
||||
layout->addWidget( m_thermo );
|
||||
layout->addWidget( label );
|
||||
|
||||
setFixedWidth( 3 * label->sizeHint().width() );
|
||||
}
|
||||
|
||||
void setValue( double value )
|
||||
{
|
||||
m_thermo->setValue( value );
|
||||
}
|
||||
|
||||
private:
|
||||
QwtThermo* m_thermo;
|
||||
};
|
||||
|
||||
TunerBox::TunerBox( QWidget* parent ):
|
||||
QFrame( parent )
|
||||
{
|
||||
const double freqMin = 87.5;
|
||||
const double freqMax = 108;
|
||||
|
||||
m_sliderFrequency = new QwtSlider( this );
|
||||
m_sliderFrequency->setOrientation( Qt::Horizontal );
|
||||
m_sliderFrequency->setScalePosition( QwtSlider::TrailingScale );
|
||||
m_sliderFrequency->setScale( freqMin, freqMax );
|
||||
m_sliderFrequency->setTotalSteps(
|
||||
qRound( ( freqMax - freqMin ) / 0.01 ) );
|
||||
m_sliderFrequency->setSingleSteps( 1 );
|
||||
m_sliderFrequency->setPageSteps( 10 );
|
||||
m_sliderFrequency->setScaleMaxMinor( 5 );
|
||||
m_sliderFrequency->setScaleMaxMajor( 12 );
|
||||
m_sliderFrequency->setHandleSize( QSize( 80, 20 ) );
|
||||
m_sliderFrequency->setBorderWidth( 1 );
|
||||
|
||||
m_thermoTune = new TuningThermo( this );
|
||||
|
||||
m_wheelFrequency = new QwtWheel( this );
|
||||
m_wheelFrequency->setMass( 0.5 );
|
||||
m_wheelFrequency->setRange( 87.5, 108 );
|
||||
m_wheelFrequency->setSingleStep( 0.01 );
|
||||
m_wheelFrequency->setPageStepCount( 10 );
|
||||
m_wheelFrequency->setTotalAngle( 3600.0 );
|
||||
m_wheelFrequency->setFixedHeight( 30 );
|
||||
|
||||
|
||||
connect( m_wheelFrequency, SIGNAL(valueChanged(double)), SLOT(adjustFreq(double)) );
|
||||
connect( m_sliderFrequency, SIGNAL(valueChanged(double)), SLOT(adjustFreq(double)) );
|
||||
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout( this );
|
||||
mainLayout->setContentsMargins( 10, 10, 10, 10 );
|
||||
mainLayout->setSpacing( 5 );
|
||||
mainLayout->addWidget( m_sliderFrequency );
|
||||
|
||||
QHBoxLayout* hLayout = new QHBoxLayout;
|
||||
hLayout->setContentsMargins( QMargins() );
|
||||
hLayout->addWidget( m_thermoTune, 0 );
|
||||
hLayout->addStretch( 5 );
|
||||
hLayout->addWidget( m_wheelFrequency, 2 );
|
||||
|
||||
mainLayout->addLayout( hLayout );
|
||||
}
|
||||
|
||||
void TunerBox::adjustFreq( double frq )
|
||||
{
|
||||
const double factor = 13.0 / ( 108 - 87.5 );
|
||||
|
||||
const double x = ( frq - 87.5 ) * factor;
|
||||
const double field = qwtSqr( std::sin( x ) * std::cos( 4.0 * x ) );
|
||||
|
||||
m_thermoTune->setValue( field );
|
||||
|
||||
if ( m_sliderFrequency->value() != frq )
|
||||
m_sliderFrequency->setValue( frq );
|
||||
if ( m_wheelFrequency->value() != frq )
|
||||
m_wheelFrequency->setValue( frq );
|
||||
|
||||
Q_EMIT fieldChanged( field );
|
||||
}
|
||||
|
||||
void TunerBox::setFreq( double frq )
|
||||
{
|
||||
m_wheelFrequency->setValue( frq );
|
||||
}
|
||||
|
||||
#include "moc_TunerBox.cpp"
|
||||
38
examples/radio/TunerBox.h
Normal file
38
examples/radio/TunerBox.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Widget Library
|
||||
* Copyright (C) 1997 Josef Wilgen
|
||||
* Copyright (C) 2002 Uwe Rathmann
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Qwt License, Version 1.0
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
class QwtWheel;
|
||||
class QwtSlider;
|
||||
class TuningThermo;
|
||||
|
||||
class TunerBox : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TunerBox( QWidget* = NULL );
|
||||
|
||||
Q_SIGNALS:
|
||||
void fieldChanged( double f );
|
||||
|
||||
public Q_SLOTS:
|
||||
void setFreq( double frq );
|
||||
|
||||
private Q_SLOTS:
|
||||
void adjustFreq( double frq );
|
||||
|
||||
private:
|
||||
QwtWheel* m_wheelFrequency;
|
||||
TuningThermo* m_thermoTune;
|
||||
QwtSlider* m_sliderFrequency;
|
||||
};
|
||||
74
examples/radio/main.cpp
Normal file
74
examples/radio/main.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/******************************************************************************
|
||||
* Qwt Widget Library
|
||||
* Copyright (C) 1997 Josef Wilgen
|
||||
* Copyright (C) 2002 Uwe Rathmann
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Qwt License, Version 1.0
|
||||
*****************************************************************************/
|
||||
|
||||
#include "TunerBox.h"
|
||||
#include "AmplifierBox.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include <QwtGlobal>
|
||||
#include <QWidget>
|
||||
#include <QLayout>
|
||||
|
||||
namespace
|
||||
{
|
||||
class MainWindow : public QWidget
|
||||
{
|
||||
public:
|
||||
MainWindow()
|
||||
{
|
||||
TunerBox* tunerBox = new TunerBox();
|
||||
tunerBox->setFrameStyle( QFrame::Panel | QFrame::Raised );
|
||||
|
||||
AmplifierBox* amplifierBox = new AmplifierBox();
|
||||
amplifierBox->setFrameStyle( QFrame::Panel | QFrame::Raised );
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout( this );
|
||||
layout->setContentsMargins( QMargins() );
|
||||
layout->setSpacing( 0 );
|
||||
layout->addWidget( tunerBox );
|
||||
layout->addWidget( amplifierBox );
|
||||
|
||||
connect( tunerBox, SIGNAL(fieldChanged(double)),
|
||||
amplifierBox, SLOT(setMaster(double)) );
|
||||
|
||||
tunerBox->setFreq( 90.0 );
|
||||
|
||||
setPalette( QPalette( QColor( 192, 192, 192 ) ) );
|
||||
}
|
||||
|
||||
virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE
|
||||
{
|
||||
// Qt 4.7.1: QGradient::StretchToDeviceMode is buggy on X11
|
||||
|
||||
QPalette pal = palette();
|
||||
|
||||
const QColor buttonColor = pal.color( QPalette::Button );
|
||||
const QColor midLightColor = pal.color( QPalette::Midlight );
|
||||
|
||||
QLinearGradient gradient( rect().topLeft(), rect().topRight() );
|
||||
gradient.setColorAt( 0.0, midLightColor );
|
||||
gradient.setColorAt( 0.7, buttonColor );
|
||||
gradient.setColorAt( 1.0, buttonColor );
|
||||
|
||||
pal.setBrush( QPalette::Window, gradient );
|
||||
setPalette( pal );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
|
||||
MainWindow window;
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
21
examples/radio/radio.pro
Normal file
21
examples/radio/radio.pro
Normal file
@@ -0,0 +1,21 @@
|
||||
################################################################
|
||||
# Qwt Examples
|
||||
# Copyright (C) 1997 Josef Wilgen
|
||||
# Copyright (C) 2002 Uwe Rathmann
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the Qwt License, Version 1.0
|
||||
################################################################
|
||||
|
||||
include( $${PWD}/../examples.pri )
|
||||
|
||||
TARGET = radio
|
||||
|
||||
HEADERS = \
|
||||
AmplifierBox.h \
|
||||
TunerBox.h
|
||||
|
||||
SOURCES = \
|
||||
AmplifierBox.cpp \
|
||||
TunerBox.cpp \
|
||||
main.cpp
|
||||
Reference in New Issue
Block a user