SpikeStream Application Library  0.2
AnalysisSpectrogram.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "AnalysisSpectrogram.h"
00003 using namespace spikestream;
00004 
00005 //Qt includes
00006 #include <QDebug>
00007 
00008 
00010 AnalysisSpectrogram::AnalysisSpectrogram (QWidget* parent, QwtRasterData* data) : QwtPlot( parent ){
00011         // Show a title
00012         //setTitle( "This is an Example" );
00013         d_spectrogram = new QwtPlotSpectrogram();
00014 
00015         QwtLinearColorMap colorMap(Qt::darkCyan, Qt::red);
00016         colorMap.addColorStop(0.1, Qt::cyan);
00017         colorMap.addColorStop(0.6, Qt::green);
00018         colorMap.addColorStop(0.95, Qt::yellow);
00019 
00020         d_spectrogram->setColorMap(colorMap);
00021 
00022         d_spectrogram->setData(*data);
00023         d_spectrogram->attach(this);
00024 
00025         QwtValueList contourLevels;
00026         for ( double level = 0.5; level < 10.0; level += 1.0 )
00027                 contourLevels += level;
00028         d_spectrogram->setContourLevels(contourLevels);
00029 
00030         // A color bar on the right axis
00031         QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight);
00032         rightAxis->setColorBarEnabled(true);
00033         rightAxis->setColorMap(d_spectrogram->data().range(), d_spectrogram->colorMap());
00034 
00035         setAxisScale(QwtPlot::yRight, d_spectrogram->data().range().minValue(), d_spectrogram->data().range().maxValue() );
00036         enableAxis(QwtPlot::yRight);
00037 
00038         //Rescale to match data
00039         setAxisMaxMinor( QwtPlot::yLeft, 0);
00040         setAxisMaxMinor( QwtPlot::xBottom, 0);
00041         rescale();
00042 
00043         //Change canvas background
00044         setCanvasBackground(Qt::white);
00045 
00046         //Set titles
00047         //setAxisTitle(QwtPlot::yRight, "Information Integration");
00048 
00049         //Change fonts
00050         QFont axisFont("Arial", 12, QFont::Normal);
00051         setAxisFont(QwtPlot::yLeft, axisFont);
00052         setAxisFont(QwtPlot::yRight, axisFont);
00053         setAxisFont(QwtPlot::xBottom, axisFont);
00054 
00055         plotLayout()->setAlignCanvasToScales(true);
00056         replot();
00057 
00058         // LeftButton for the zooming
00059         // MidButton for the panning
00060         // RightButton: zoom out by 1
00061         // Ctrl+RighButton: zoom out to full size
00062 
00063         QwtPlotZoomer* zoomer = new MyZoomer(canvas());
00064         zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
00065         zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
00066 
00067         QwtPlotPanner *panner = new QwtPlotPanner(canvas());
00068         panner->setAxisEnabled(QwtPlot::yRight, false);
00069         panner->setMouseButton(Qt::MidButton);
00070 
00071         // Avoid jumping when labels with more/less digits
00072         // appear/disappear when scrolling vertically
00073 
00074         const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font());
00075         QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
00076         sd->setMinimumExtent( fm.width("100.00") );
00077 
00078         const QColor c(Qt::darkBlue);
00079         zoomer->setRubberBandPen(c);
00080         zoomer->setTrackerPen(c);
00081 
00082         // Show the plots
00083         replot();
00084 }
00085 
00086 
00088 AnalysisSpectrogram::~AnalysisSpectrogram(){
00089 }
00090 
00091 
00092 /*----------------------------------------------------------*/
00093 /*-----                 PUBLIC METHODS                 -----*/
00094 /*----------------------------------------------------------*/
00095 
00097 void AnalysisSpectrogram::rescale(){
00098         setAxisScale(QwtPlot::yLeft, d_spectrogram->data().boundingRect().y(),d_spectrogram->data().boundingRect().y() + d_spectrogram->data().boundingRect().height(), 1);
00099         setAxisScale(QwtPlot::xBottom, d_spectrogram->data().boundingRect().x(),d_spectrogram->data().boundingRect().x() + d_spectrogram->data().boundingRect().width(), 1);
00100 }
00101 
00102 
00104 void AnalysisSpectrogram::showContour(bool on){
00105         d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ContourMode, on);
00106         replot();
00107 }
00108 
00109 
00111 void AnalysisSpectrogram::showSpectrogram(bool on){
00112         d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ImageMode, on);
00113         d_spectrogram->setDefaultContourPen(on ? QPen() : QPen(Qt::NoPen));
00114         replot();
00115 }
00116 
00117 
00120 void AnalysisSpectrogram::printPlot() {
00121         QPrinter printer;
00122         printer.setOrientation(QPrinter::Landscape);
00123         printer.setOutputFileName("/tmp/spectrogram.pdf");
00124         QPrintDialog dialog(&printer);
00125         if ( dialog.exec() ){
00126                 print(printer);
00127         }
00128 }
 All Classes Files Functions Variables Typedefs Friends Defines