mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 00:28:42 +00:00
QT5 -- Add Qwt 6.1-multiaxes
This commit is contained in:
75
qwt/examples/spectrogram/main.cpp
Normal file
75
qwt/examples/spectrogram/main.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <qapplication.h>
|
||||
#include <qmainwindow.h>
|
||||
#include <qtoolbar.h>
|
||||
#include <qtoolbutton.h>
|
||||
#include <qslider.h>
|
||||
#include "plot.h"
|
||||
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
public:
|
||||
MainWindow( QWidget * = NULL );
|
||||
|
||||
private:
|
||||
Plot *d_plot;
|
||||
};
|
||||
|
||||
MainWindow::MainWindow( QWidget *parent ):
|
||||
QMainWindow( parent )
|
||||
{
|
||||
d_plot = new Plot( this );
|
||||
|
||||
setCentralWidget( d_plot );
|
||||
|
||||
QToolBar *toolBar = new QToolBar( this );
|
||||
|
||||
QToolButton *btnSpectrogram = new QToolButton( toolBar );
|
||||
btnSpectrogram->setText( "Spectrogram" );
|
||||
btnSpectrogram->setCheckable( true );
|
||||
btnSpectrogram->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
toolBar->addWidget( btnSpectrogram );
|
||||
connect( btnSpectrogram, SIGNAL( toggled( bool ) ),
|
||||
d_plot, SLOT( showSpectrogram( bool ) ) );
|
||||
|
||||
QToolButton *btnContour = new QToolButton( toolBar );
|
||||
btnContour->setText( "Contour" );
|
||||
btnContour->setCheckable( true );
|
||||
btnContour->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
toolBar->addWidget( btnContour );
|
||||
connect( btnContour, SIGNAL( toggled( bool ) ),
|
||||
d_plot, SLOT( showContour( bool ) ) );
|
||||
|
||||
#ifndef QT_NO_PRINTER
|
||||
QToolButton *btnPrint = new QToolButton( toolBar );
|
||||
btnPrint->setText( "Print" );
|
||||
btnPrint->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
toolBar->addWidget( btnPrint );
|
||||
connect( btnPrint, SIGNAL( clicked() ),
|
||||
d_plot, SLOT( printPlot() ) );
|
||||
#endif
|
||||
|
||||
QSlider *slider = new QSlider( Qt::Horizontal );
|
||||
slider->setRange( 0, 255 );
|
||||
slider->setValue( 255 );
|
||||
connect( slider, SIGNAL( valueChanged( int ) ),
|
||||
d_plot, SLOT( setAlpha( int ) ) );
|
||||
|
||||
toolBar->addWidget( slider );
|
||||
|
||||
addToolBar( toolBar );
|
||||
|
||||
btnSpectrogram->setChecked( true );
|
||||
btnContour->setChecked( false );
|
||||
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
MainWindow mainWindow;
|
||||
mainWindow.resize( 600, 400 );
|
||||
mainWindow.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
169
qwt/examples/spectrogram/plot.cpp
Normal file
169
qwt/examples/spectrogram/plot.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
#include <qprinter.h>
|
||||
#include <qprintdialog.h>
|
||||
#include <qwt_color_map.h>
|
||||
#include <qwt_plot_spectrogram.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
#include <qwt_scale_draw.h>
|
||||
#include <qwt_plot_zoomer.h>
|
||||
#include <qwt_plot_panner.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
#include <qwt_plot_renderer.h>
|
||||
#include "plot.h"
|
||||
|
||||
class MyZoomer: public QwtPlotZoomer
|
||||
{
|
||||
public:
|
||||
MyZoomer( QWidget *canvas ):
|
||||
QwtPlotZoomer( canvas )
|
||||
{
|
||||
setTrackerMode( AlwaysOn );
|
||||
}
|
||||
|
||||
virtual QwtText trackerTextF( const QPointF &pos ) const
|
||||
{
|
||||
QColor bg( Qt::white );
|
||||
bg.setAlpha( 200 );
|
||||
|
||||
QwtText text = QwtPlotZoomer::trackerTextF( pos );
|
||||
text.setBackgroundBrush( QBrush( bg ) );
|
||||
return text;
|
||||
}
|
||||
};
|
||||
|
||||
class SpectrogramData: public QwtRasterData
|
||||
{
|
||||
public:
|
||||
SpectrogramData()
|
||||
{
|
||||
setInterval( Qt::XAxis, QwtInterval( -1.5, 1.5 ) );
|
||||
setInterval( Qt::YAxis, QwtInterval( -1.5, 1.5 ) );
|
||||
setInterval( Qt::ZAxis, QwtInterval( 0.0, 10.0 ) );
|
||||
}
|
||||
|
||||
virtual double value( double x, double y ) const
|
||||
{
|
||||
const double c = 0.842;
|
||||
|
||||
const double v1 = x * x + ( y - c ) * ( y + c );
|
||||
const double v2 = x * ( y + c ) + x * ( y + c );
|
||||
|
||||
return 1.0 / ( v1 * v1 + v2 * v2 );
|
||||
}
|
||||
};
|
||||
|
||||
class ColorMap: public QwtLinearColorMap
|
||||
{
|
||||
public:
|
||||
ColorMap():
|
||||
QwtLinearColorMap( Qt::darkCyan, Qt::red )
|
||||
{
|
||||
addColorStop( 0.1, Qt::cyan );
|
||||
addColorStop( 0.6, Qt::green );
|
||||
addColorStop( 0.95, Qt::yellow );
|
||||
}
|
||||
};
|
||||
|
||||
Plot::Plot( QWidget *parent ):
|
||||
QwtPlot( parent )
|
||||
{
|
||||
d_spectrogram = new QwtPlotSpectrogram();
|
||||
d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
|
||||
|
||||
d_spectrogram->setColorMap( new ColorMap() );
|
||||
d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache );
|
||||
|
||||
d_spectrogram->setData( new SpectrogramData() );
|
||||
d_spectrogram->attach( this );
|
||||
|
||||
QList<double> contourLevels;
|
||||
for ( double level = 0.5; level < 10.0; level += 1.0 )
|
||||
contourLevels += level;
|
||||
d_spectrogram->setContourLevels( contourLevels );
|
||||
|
||||
const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
|
||||
// A color bar on the right axis
|
||||
QwtScaleWidget *rightAxis = axisWidget( QwtAxis::yRight );
|
||||
rightAxis->setTitle( "Intensity" );
|
||||
rightAxis->setColorBarEnabled( true );
|
||||
rightAxis->setColorMap( zInterval, new ColorMap() );
|
||||
|
||||
setAxisScale( QwtAxis::yRight, zInterval.minValue(), zInterval.maxValue() );
|
||||
setAxisVisible( QwtAxis::yRight );
|
||||
|
||||
plotLayout()->setAlignCanvasToScales( true );
|
||||
replot();
|
||||
|
||||
// LeftButton for the zooming
|
||||
// MidButton for the panning
|
||||
// RightButton: zoom out by 1
|
||||
// Ctrl+RighButton: zoom out to full size
|
||||
|
||||
QwtPlotZoomer* zoomer = new MyZoomer( canvas() );
|
||||
zoomer->setMousePattern( QwtEventPattern::MouseSelect2,
|
||||
Qt::RightButton, Qt::ControlModifier );
|
||||
zoomer->setMousePattern( QwtEventPattern::MouseSelect3,
|
||||
Qt::RightButton );
|
||||
|
||||
QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
|
||||
panner->setAxisEnabled( QwtAxis::yRight, false );
|
||||
panner->setMouseButton( Qt::MidButton );
|
||||
|
||||
// Avoid jumping when labels with more/less digits
|
||||
// appear/disappear when scrolling vertically
|
||||
|
||||
const QFontMetrics fm( axisWidget( QwtAxis::yLeft )->font() );
|
||||
QwtScaleDraw *sd = axisScaleDraw( QwtAxis::yLeft );
|
||||
sd->setMinimumExtent( fm.width( "100.00" ) );
|
||||
|
||||
const QColor c( Qt::darkBlue );
|
||||
zoomer->setRubberBandPen( c );
|
||||
zoomer->setTrackerPen( c );
|
||||
}
|
||||
|
||||
void Plot::showContour( bool on )
|
||||
{
|
||||
d_spectrogram->setDisplayMode( QwtPlotSpectrogram::ContourMode, on );
|
||||
replot();
|
||||
}
|
||||
|
||||
void Plot::showSpectrogram( bool on )
|
||||
{
|
||||
d_spectrogram->setDisplayMode( QwtPlotSpectrogram::ImageMode, on );
|
||||
d_spectrogram->setDefaultContourPen(
|
||||
on ? QPen( Qt::black, 0 ) : QPen( Qt::NoPen ) );
|
||||
|
||||
replot();
|
||||
}
|
||||
|
||||
void Plot::setAlpha( int alpha )
|
||||
{
|
||||
d_spectrogram->setAlpha( alpha );
|
||||
replot();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_PRINTER
|
||||
|
||||
void Plot::printPlot()
|
||||
{
|
||||
QPrinter printer( QPrinter::HighResolution );
|
||||
printer.setOrientation( QPrinter::Landscape );
|
||||
printer.setOutputFileName( "spectrogram.pdf" );
|
||||
|
||||
QPrintDialog dialog( &printer );
|
||||
if ( dialog.exec() )
|
||||
{
|
||||
QwtPlotRenderer renderer;
|
||||
|
||||
if ( printer.colorMode() == QPrinter::GrayScale )
|
||||
{
|
||||
renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground );
|
||||
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
|
||||
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame );
|
||||
renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );
|
||||
}
|
||||
|
||||
renderer.renderTo( this, printer );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
22
qwt/examples/spectrogram/plot.h
Normal file
22
qwt/examples/spectrogram/plot.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_plot_spectrogram.h>
|
||||
|
||||
class Plot: public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget * = NULL );
|
||||
|
||||
public Q_SLOTS:
|
||||
void showContour( bool on );
|
||||
void showSpectrogram( bool on );
|
||||
void setAlpha( int );
|
||||
|
||||
#ifndef QT_NO_PRINTER
|
||||
void printPlot();
|
||||
#endif
|
||||
|
||||
private:
|
||||
QwtPlotSpectrogram *d_spectrogram;
|
||||
};
|
||||
19
qwt/examples/spectrogram/spectrogram.pro
Normal file
19
qwt/examples/spectrogram/spectrogram.pro
Normal file
@@ -0,0 +1,19 @@
|
||||
################################################################
|
||||
# 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( $${PWD}/../examples.pri )
|
||||
|
||||
TARGET = spectrogram
|
||||
|
||||
HEADERS = \
|
||||
plot.h
|
||||
|
||||
SOURCES = \
|
||||
plot.cpp \
|
||||
main.cpp
|
||||
Reference in New Issue
Block a user