#include "echogram.h" /* Function: Echogram * Params In * PlotOptions p: Structure containing the options used for plotting. * int chanSize: The number of radar channels. * QWidget* parent: Pointer to the parent window. * MatrixData* data: Pointer to the shared data container. * Return * N/A * Purpose * Default constructor. Sets up the Echogram window, creates the menu, and connects * signals to slots. */ Echogram::Echogram( PlotOptions* p, int chanSize, QWidget *parent, MatrixData* data ):QMainWindow( parent ) { plot = p; setWindowTitle( "Echogram Window" ); createMenus(); QVBoxLayout* mainLayout = new QVBoxLayout; echoPlot = new Plot( p, this, data ); mainLayout->addWidget( buttonBox ); mainLayout->addWidget( echoPlot ); setCentralWidget( new QWidget() ); centralWidget()->setLayout( mainLayout ); setStatusBarText(); connect( this, SIGNAL( windowClosed( QObject* ) ), parent, SLOT( deleteEWindow( QObject* ) ) ); connect( this, SIGNAL( updateWin( PlotOptions* ) ), parent, SLOT( updateWinOptions( PlotOptions* ) ) ); } Echogram::~Echogram() { //delete [] echoPlot; //delete [] plot; //delete [] buttons[ numButtons ]; //delete [] buttonBox; } /* Function: redraw * Params In * N/A * Return * N/A * Purpose * Calls the plot window's redraw function. */ void Echogram::redraw() { echoPlot->redraw(); } void Echogram::setStatusBarText() { QString statusText; statusText = "Depth: "; if( plot->depthType == 0 ) { statusText.append( "Air" ); } else if( plot->depthType == 1 ) { statusText.append( "Ice" ); } else { statusText.append( "Time" ); } statusText.append( " - Data: " ); if( plot->dataType == 0 ) { statusText.append( "Raw" ); } else if( plot->dataType == 1 ) { statusText.append( "Freq." ); } else { statusText.append( "Compressed" ); } statusText.append( " - Mag: " ); if( plot->dataScale == 0 ) { statusText.append( "Linear" ); } else { statusText.append( "Log" ); } statusText.append( " - Time Offset: " ); QString time; time.setNum( plot->timeOffset ); statusText.append( time ); statusBar()->showMessage( statusText ); } /* Function: closeEvent * Params In * QCloseEvent* event * Return * N/A * Purpose * Redefinition of the closeEvent function. Instead of just exiting the window, emits the * windowClosed signal, which will call a function in the parent to cleanup the list of * open windows, as this window is not open. */ void Echogram::closeEvent( QCloseEvent* event ) { emit windowClosed( this ); } /* Function: createMenus * Params In * N/A * Return * N/A * Purpose * Creates the menu system for the window. As of now, only includes the 'Update' button. */ void Echogram::createMenus() { buttonBox = new QGroupBox( tr( "Update Window Parameters" ) ); QHBoxLayout *layout = new QHBoxLayout; //Create the update button, then add connections for the event //when it is clicked. buttons[0] = new QPushButton( tr( "Update" ) ); buttons[1] = new QPushButton( tr( "Print" ) ); layout->addWidget( buttons[0] ); layout->addWidget( buttons[1] ); connect( buttons[0], SIGNAL( clicked() ), this, SLOT( updateWindow() ) ); connect( buttons[1], SIGNAL( clicked() ), this, SLOT( printWindow() ) ); buttonBox->setLayout( layout ); } /* Function: updateWindow * Params In * N/A * Return * N/A * Purpose * Emits the updateWin signal which calls a function in the parent to copy the newest * options to the DataOptions structure for the window. */ void Echogram::updateWindow() { emit updateWin( plot ); reset(); } void Echogram::reset() { echoPlot->clear(); //echoPlot->reset(); setStatusBarText(); } void Echogram::printWindow() { QPrinter printer; printer.setOutputFileName("/tmp/echogram.pdf"); QString docName = echoPlot->title().text(); if ( !docName.isEmpty() ) { docName.replace (QRegExp (QString::fromLatin1 ("\n")), tr (" -- ")); printer.setDocName (docName); } printer.setCreator("Bode example"); printer.setOrientation(QPrinter::Landscape); QPrintDialog dialog(&printer); if ( dialog.exec() ) { QwtPlotPrintFilter filter; if ( printer.colorMode() == QPrinter::GrayScale ) { int options = QwtPlotPrintFilter::PrintAll; options &= ~QwtPlotPrintFilter::PrintBackground; options |= QwtPlotPrintFilter::PrintFrameWithScales; filter.setOptions(options); } echoPlot->print(printer, filter); } }