/*************************************************************************** * Copyright (C) 2004 by Johan Maes - ON4QZ * * on4qz@telenet.be * * http://users.telenet.be/on4qz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "rxmainwindow.h" #include "rxform.h" #include #include #include #include #include #include "utils.h" #include "qsstvglobal.h" #include "configform.h" #include "configdialog.h" #include "dspfunctions.h" #include "rxfunctions.h" #include "wavio.h" #include #include "helper.h" #include "txmainwindow.h" #include "galerymainwindow.h" #include "imageview.h" #include "syncproc.h" #include "zoomwindow.h" #include rxMainWindow::rxMainWindow():QMainWindow() { initView(); printer= new QPrinter; rxf=new rxFunctions(); dsp=new dspFunctions(cv->fftDisplayFrame); readSettings(); initActions(); initToolbar(); initMenubar(); permText=new QLabel(statusBar(),""); statusBar()->addWidget(permText,1,TRUE); statusBar()->message("Starting .."); rxf->setoffsetMeterFrame(cv->offsetMeterFrame); rxf->setvuMeterFrame(cv->vuMeterFrame); rxf->setSyncDisplayFrame(cv->syncDisplayFrame); connect(rxf,SIGNAL(statusMessage(QString)),SLOT(slotDisplayStatusMessage(QString))); connect(cv->imager,SIGNAL(newSize(unsigned int,unsigned int)),SLOT(slotNewSize(unsigned int,unsigned int))); connect(cv->useVISCheckBox,SIGNAL(toggled(bool)),SLOT(slotGetParams())); connect(cv->slantAdjustCheckBox,SIGNAL(toggled(bool)),SLOT(slotGetParams())); connect(cv->autosaveCheckBox,SIGNAL(toggled(bool)),SLOT(slotGetParams())); connect(cv->dxModeCheckBox,SIGNAL(toggled(bool)),SLOT(slotGetParams())); connect(cv->sensitivityButtonGroup,SIGNAL(clicked (int)),SLOT(slotGetParams())); connect(dsp,SIGNAL(signalEndOfInput()),SLOT(slotStopRX())); connect(&syncProcessor,SIGNAL(setOffset(int,int)),rxf,SLOT(slotUpdateOffset(int,int))); rxf->process(STARTA); } rxMainWindow::~rxMainWindow() { } void rxMainWindow::init() { } void rxMainWindow::readSettings() { QSettings qSettings(QSettings::Ini); qSettings.beginGroup(APP_KEY+"/RX/"); int windowWidth = qSettings.readNumEntry("rxWindowWidth", 460 ); int windowHeight = qSettings.readNumEntry("rxWindowHeight", 530 ); int windowX = qSettings.readNumEntry( "rxWindowX", -1 ); int windowY = qSettings.readNumEntry( "rxWindowY", -1 ); resize( windowWidth, windowHeight ); if ( windowX != -1 || windowY != -1 ) move( windowX, windowY ); rxf->useVIS=qSettings.readBoolEntry("useVIS",FALSE); rxf->slantAdjust=qSettings.readBoolEntry("slantAdjust",FALSE); rxf->autoSave=qSettings.readBoolEntry("autoSave",TRUE); rxf->dxMode=qSettings.readBoolEntry("dxMode",FALSE); rxf->sensitivity=qSettings.readNumEntry("sensitivity",1); qSettings.endGroup(); setParams(); } void rxMainWindow::writeSettings() { QSettings qSettings(QSettings::Ini); slotGetParams(); qSettings.beginGroup(APP_KEY+"/RX/"); qSettings.writeEntry( "rxWindowWidth", width() ); qSettings.writeEntry( "rxWindowHeight", height() ); qSettings.writeEntry( "rxWindowX", x() ); qSettings.writeEntry( "rxWindowY", y() ); qSettings.writeEntry( "useVIS",rxf->useVIS); qSettings.writeEntry( "slantAdjust",rxf->slantAdjust); qSettings.writeEntry( "autoSave",rxf->autoSave); qSettings.writeEntry( "dxMode",rxf->dxMode); qSettings.writeEntry( "sensitivity",rxf->sensitivity); qSettings.endGroup(); } void rxMainWindow::slotGetParams() { getValue(rxf->useVIS,cv->useVISCheckBox); getValue(rxf->slantAdjust,cv->slantAdjustCheckBox); getValue(rxf->autoSave,cv->autosaveCheckBox); getValue(rxf->dxMode,cv->dxModeCheckBox); getValue(rxf->sensitivity,cv->sensitivityButtonGroup); rxf->updateParams(); } void rxMainWindow::setParams() { setValue(rxf->useVIS,cv->useVISCheckBox); setValue(rxf->slantAdjust,cv->slantAdjustCheckBox); setValue(rxf->autoSave,cv->autosaveCheckBox); setValue(rxf->dxMode,cv->dxModeCheckBox); setValue(rxf->sensitivity,cv->sensitivityButtonGroup); } void rxMainWindow::initView() { cv= new rxForm(this); setCentralWidget(cv); cv->imager->clearBackground(); } void rxMainWindow::initActions() { printRX = new QAction(tr("Print Image"),QPixmap::fromMimeSource("fileprint.png"),tr("Print Image"),QAccel::stringToKey(tr("Ctrl+P")), this); printRX->setStatusTip(tr("Print Image")); printRX->setWhatsThis(tr("Print Image\nPrint Image currently in the reeceive window\n")); connect(printRX, SIGNAL(activated()), this, SLOT(slotPrintRX())); startRX = new QAction(tr("Start Receiving"),QPixmap::fromMimeSource("start.png"),tr("Start Receiving"),QAccel::stringToKey(tr("Ctrl+A")), this); startRX->setStatusTip(tr("Start Receiving")); startRX->setWhatsThis(tr("Start Receiving\nProgram goes into receive mode\n")); connect(startRX, SIGNAL(activated()), this, SLOT(slotStartRX())); stopRX = new QAction(tr("Stop Receiving"),QPixmap::fromMimeSource("stop.png"),tr("Stop Receiving"),QAccel::stringToKey(tr("Ctrl+C")), this); stopRX->setStatusTip(tr("Stop Receiving")); stopRX->setWhatsThis(tr("Stop Receiving\nProgram goes into idle mode\n")); connect(stopRX, SIGNAL(activated()), this, SLOT(slotStopRX())); fileSave = new QAction(tr("Save File"),QPixmap::fromMimeSource("filesave.png"),tr("&Save File"),QAccel::stringToKey(tr("Ctrl+S")), this); fileSave->setStatusTip(tr("Save File")); fileSave->setWhatsThis(tr("Save File\nSave current image to file")); connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); erase = new QAction(tr("Clear Screen"),QPixmap::fromMimeSource("eraser.png"),tr("&Clear Screen"),QAccel::stringToKey(tr("Ctrl+E")), this); erase->setStatusTip(tr("Clear screen")); erase->setWhatsThis(tr("Clear Screen")); connect(erase, SIGNAL(activated()), this, SLOT(slotErase())); zoom = new QAction(tr("Zoom"),QPixmap::fromMimeSource("zoom.png"),tr("&Zoom"),QAccel::stringToKey(tr("Ctrl+Z")), this); zoom->setStatusTip(tr("Zoom image")); zoom->setWhatsThis(tr("Zoom current image")); connect(zoom, SIGNAL(activated()), this, SLOT(slotZoom())); #ifdef DEBUGQSSTV readFile = new QAction(tr("Receive from file"),tr("&RX from file"),0, this); readFile->setStatusTip(tr("Receive from file")); readFile->setWhatsThis(tr("Receive from file\nShow a pre-recorded SSTV image\n")); connect(readFile, SIGNAL(activated()), this, SLOT(slotRXFromFile())); #endif configure = new QAction(tr("Configure"), tr("&Configure"), 0, this); configure->setStatusTip(tr("Configuration")); configure->setWhatsThis(tr("Configuration\n\nConfiguartion parameters")); connect(configure, SIGNAL(activated()), this, SLOT(slotConfigure())); fileQuit = new QAction(tr("Exit"), tr("Exit"), QAccel::stringToKey(tr("Ctrl+X")), this); fileQuit->setStatusTip(tr("Quits the application")); fileQuit->setWhatsThis(tr("Exit\n\nQuits the application")); connect(fileQuit, SIGNAL(activated()), this, SLOT(slotFileQuit())); #ifdef DEBUGQSSTV outputRaw=new QAction(tr("Raw"), tr("&Raw"), QAccel::stringToKey(tr("Ctrl+R")), this); outputRaw->setStatusTip(tr("Reads a file and converts it to a raw stream")); outputRaw->setWhatsThis(tr("Raw\n\nReads a file and converts it to a raw stream")); connect(outputRaw, SIGNAL(activated()), this, SLOT(slotFileRaw())); #endif calibrate=new QAction(tr("Calibrate"), tr("&Calibrate"), 0, this); calibrate->setStatusTip(tr("Calibrates the soundcard clock")); calibrate->setWhatsThis(tr("Calibrate\n\nCalibrates the soundcard clock")); connect(calibrate, SIGNAL(activated()), this, SLOT(slotCalibrate())); #ifdef DEBUGQSSTV showPlot=new QAction(tr("Show plot"), tr("&Show plot"), QAccel::stringToKey(tr("Ctrl+G")), this); showPlot->setStatusTip(tr("Show plot (debug info)")); showPlot->setWhatsThis(tr("Show plot\n\nShow plot (debug info)")); connect(showPlot, SIGNAL(activated()), this, SLOT(slotShowPlot())); #endif helpAboutApp = new QAction(tr("About"), tr("&About..."), 0, this); helpAboutApp->setStatusTip(tr("About the application")); helpAboutApp->setWhatsThis(tr("About\n\nAbout the application")); connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout())); userGuide = new QAction(tr("QSSTV Handbook"), tr("&QSSTV Handbook"), QAccel::stringToKey(tr("F1")), this); userGuide->setStatusTip(tr("QSSTV Handbook")); userGuide->setWhatsThis(tr("QSSTV Handbook")); connect(userGuide, SIGNAL(activated()), this, SLOT(slotUserGuide())); } void rxMainWindow::initToolbar() { toolBar = new QToolBar(this, "toolbar RX"); fileSave->addTo(toolBar); startRX->addTo(toolBar); stopRX->addTo(toolBar); printRX->addTo(toolBar); erase->addTo(toolBar); zoom->addTo(toolBar); QWhatsThis::whatsThisButton( toolBar ); } void rxMainWindow::initMenubar() { fileMenu=new QPopupMenu(); optionMenu=new QPopupMenu(); actionMenu=new QPopupMenu(); helpMenu=new QPopupMenu(); fileSave->addTo(fileMenu); printRX->addTo(fileMenu); fileQuit->addTo(fileMenu); startRX->addTo(actionMenu); stopRX->addTo(actionMenu); erase->addTo(actionMenu); zoom->addTo(actionMenu); #ifdef DEBUGQSSTV showPlot->addTo(actionMenu); readFile->addTo(fileMenu); outputRaw->addTo(fileMenu); #endif configure->addTo(optionMenu); calibrate->addTo(optionMenu); userGuide->addTo(helpMenu); helpAboutApp->addTo(helpMenu); menuBar()->insertItem(tr("&File"), fileMenu); menuBar()->insertItem(tr("&Actions"), actionMenu); menuBar()->insertItem(tr("&Options"), optionMenu); menuBar()->insertItem(tr("&Help"), helpMenu); } void rxMainWindow::slotConfigure() { confDiag->exec(); } void rxMainWindow::slotDisplayStatusMessage(QString s) { permText->setText(s); permText->repaint(FALSE); } void rxMainWindow::slotStartRX() { slotGetParams(); dsp->setCaptureSource(TRUE); debug("startRx"); rxf->process(IDLE); } void rxMainWindow::restartAfterAck() { dsp->setCaptureSource(TRUE); debug("start After Ack"); rxf->process(STARTB); } bool rxMainWindow::isBusy() { return rxf->isBusy(); } void rxMainWindow::slotStopRX() { debug("stopRx"); rxf->slotStop(); dsp->stop(); } void rxMainWindow::slotFileRaw() { #ifdef DEBUGQSSTV wavIO wv(samplingrate); wv.dumpData("",TRUE); #endif } void rxMainWindow::slotRXFromFile() { slotGetParams(); dsp->setCaptureSource(FALSE); rxf->process(IDLE); } void rxMainWindow::slotCalibrate() { slotGetParams(); dsp->setCaptureSource(TRUE); rxf->calibrate(); } void rxMainWindow::closeEvent(QCloseEvent *e) { slotFileQuit(); e->accept(); } void rxMainWindow::slotFileQuit() { dsp->stop(); debug("closing qsstv"); writeSettings(); confDiag->writeSettings(); txMW->writeSettings(); galMW->writeSettings(); qApp->quit(); } void rxMainWindow::slotHelpAbout() { QMessageBox::about(this,tr("About..."), tr("QSSTV\nVersion " VERSION "\n http://users.telenet.be/on4qz" "\n(c) 2004 by Johan Maes - ON4QZ" ) ); } imageView *rxMainWindow::getImagePtr() { return cv->imager; } void rxMainWindow::slotNewSize(unsigned int w,unsigned int h) { setMinimumSize(w,h); } void rxMainWindow::slotPrintRX() { if ( printer->setup(this) ) { QPixmap t; t=cv->imager->image; QPainter paint( printer ); paint.drawPixmap(30,30,t); } } void rxMainWindow::slotFileSave() { dirDialog d(this,0,TRUE); QString s=d.saveFileName(rxImagePath,"*",defaultImageFormat); if (s==QString::null) return ; if (s.isEmpty()) return ; getImagePtr()->image.save(s,defaultImageFormat.upper()); } void rxMainWindow::slotErase() { cv->imager->clearBackground(); } void rxMainWindow::slotZoom() { zoomWindow zm(0); zm.zoom(&(getImagePtr()->image)); zm.exec(); } void rxMainWindow::slotUserGuide() { QFileInfo finfo; finfo.setFile(docPath,"index.html"); if (finfo.isReadable()) { HelpWindow *help = new HelpWindow(finfo.absFilePath(), ".", 0, "help viewer"); if ( QApplication::desktop()->width() > 400 && QApplication::desktop()->height() > 500 ) { help->show(); } else { help->showMaximized(); } } else { QMessageBox::warning(this,"User Guide file locations", "the file:\n" + finfo.absFilePath() + "\ncould not be opened.\n" +"Check if the file exist and you have read access" +"The file could be in another location\n" +"You can change this location in the configuration tables\n" +"Menu->Options->Configuration"); } } /*! \fn rxMainWindow::slotShowPlot() */ void rxMainWindow::slotShowPlot() { #ifdef DEBUGQSSTV debugPtr->show(); #endif }