/*************************************************************************** * 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 "txmainwindow.h" #include #include #include #include "utils.h" #include "qsstvglobal.h" #include "sstvparam.h" #include "txform.h" #include "txfunctions.h" #include "rxmainwindow.h" #include "freqform.h" #include "editor.h" #include "configdialog.h" #include "dspfunctions.h" #include #include #include #include "mcanvas.h" txMainWindow::txMainWindow(): QMainWindow() { initView(); txf=new txFunctions(cv->txProgressBar); repeaterIndex=0; repeaterTimer=new QTimer(this); connect(repeaterTimer,SIGNAL(timeout()),SLOT(slotRepeaterTimer())); repeaterTimer->start(60000*repeaterImageInterval,TRUE); } txMainWindow::~txMainWindow() { writeSettings(); if (ed!=NULL) delete ed; } void txMainWindow::init() { readSettings(); initActions(); initToolbar(); initMenubar(); statusBar()->message("Starting .."); connect(cv->modeComboBox,SIGNAL(activated(int)),SLOT(slotModeChanged(int ))); connect(cv->templateSpinBox,SIGNAL(valueChanged(int)),SLOT(slotTemplateChanged(int ))); connect(cv->templateCheckBox,SIGNAL(toggled(bool)),SLOT(slotTemplateCBChanged(bool ))); connect(cv->cwCheckBox,SIGNAL(toggled(bool)),SLOT(slotGetParams())); connect(cv->voxCheckBox,SIGNAL(toggled(bool)),SLOT(slotGetParams())); ed=NULL; } void txMainWindow::readSettings() { QSettings qSettings(QSettings::Ini); qSettings.beginGroup(APP_KEY+"/TX/"); int windowWidth = qSettings.readNumEntry("txWindowWidth", 460 ); int windowHeight = qSettings.readNumEntry("txWindowHeight", 530 ); int windowX = qSettings.readNumEntry("txWindowX", -1 ); int windowY = qSettings.readNumEntry("txWindowY", -1 ); resize( windowWidth, windowHeight ); if ( windowX != -1 || windowY != -1 ) move( windowX, windowY ); txf->setModeIndex((sstvMode)qSettings.readNumEntry("modeIndex",0)); txf->templateIndex=qSettings.readNumEntry("templateIndex",1); txf->useTemplate=qSettings.readBoolEntry("useTemplate",FALSE); txf->useCW=qSettings.readBoolEntry("useCW",FALSE); txf->useVOX=qSettings.readBoolEntry("useVOX",FALSE); connect(txf,SIGNAL(statusMessage(QString)),SLOT(slotDisplayStatusMessage(QString))); qSettings.endGroup(); setParams(); } void txMainWindow::writeSettings() { QSettings qSettings(QSettings::Ini); slotGetParams(); qSettings.beginGroup(APP_KEY+"/TX/"); qSettings.writeEntry( "txWindowWidth", width() ); qSettings.writeEntry( "txWindowHeight", height() ); qSettings.writeEntry( "txWindowX", x() ); qSettings.writeEntry( "txWindowY", y() ); qSettings.writeEntry( "modeIndex", txf->getModeIndex()); qSettings.writeEntry( "templateIndex", txf->templateIndex); qSettings.writeEntry( "useTemplate", txf->useTemplate); qSettings.writeEntry( "useVOX", txf->useVOX); qSettings.writeEntry( "useCW", txf->useCW); qSettings.endGroup(); } void txMainWindow::slotGetParams() { int t; getValue(t,cv->modeComboBox); // txf->setModeIndex((sstvMode)t); getValue(txf->templateIndex,cv->templateSpinBox); getValue(txf->useTemplate,cv->templateCheckBox); getValue(txf->useVOX,cv->voxCheckBox); getValue(txf->useCW,cv->cwCheckBox); txf->updateParams(); } void txMainWindow::setParams() { setValue((int)txf->getModeIndex(),cv->modeComboBox); setValue(txf->templateIndex,cv->templateSpinBox); setValue(txf->useTemplate,cv->templateCheckBox); setValue(txf->useVOX,cv->voxCheckBox); setValue(txf->useCW,cv->cwCheckBox); txf->updateParams(); } void txMainWindow::initView() { int i; cv= new txForm(this); setCentralWidget(cv); for(i=0;imodeComboBox->insertItem(getMode(i)); } connect(cv->toCallLineEdit,SIGNAL(textChanged(const QString &)),SLOT(slotCallChanged(const QString &))); connect(cv->operatorLineEdit,SIGNAL(textChanged(const QString &)),SLOT(slotOperatorChanged(const QString &))); connect(cv->rstLineEdit,SIGNAL(textChanged(const QString &)),SLOT(slotRSTChanged(const QString &))); cv->txProgressBar->setProgress(0,100); } void txMainWindow::initActions() { startTX = new QAction(tr("Start Transmitting"),QPixmap::fromMimeSource("start.png"),tr("&Start Transmitting"),QAccel::stringToKey(tr("Ctrl+A")), this); startTX->setStatusTip(tr("Start Transmitting")); startTX->setWhatsThis(tr("Start Transmitting\nProgram goes into transmit mode\n")); connect(startTX, SIGNAL(activated()), this, SLOT(slotStartTX())); #ifdef DEBUGQSSTV startTXFile = new QAction(tr("Start Transmitting To File"),tr("&Start Transmitting To File"),0, this); startTXFile->setStatusTip(tr("Start Transmitting To File")); startTXFile->setWhatsThis(tr("Start Transmitting To File\nProgram sends audio to file\n")); connect(startTXFile, SIGNAL(activated()), this, SLOT(slotStartTXFile())); #endif stopTX = new QAction(tr("Stop Transmitting"),QPixmap::fromMimeSource("stop.png"),tr("&Stop Transmitting"),QAccel::stringToKey(tr("Ctrl+C")), this); stopTX->setStatusTip(tr("Stop Transmitting")); stopTX->setWhatsThis(tr("Stop Transmitting\nProgram goes back to RX mode\n")); connect(stopTX, SIGNAL(activated()), this, SLOT(slotStopTX())); generateSignal = new QAction(tr("Generate Test Signal"), tr("&Test signal"), QAccel::stringToKey(tr("Ctrl+F")), this); generateSignal->setStatusTip(tr("Generate Test Tone")); generateSignal->setWhatsThis(tr("Generate Test Tone\n\nGenerate a test signal")); connect(generateSignal, SIGNAL(activated()), this, SLOT(slotGenerateSignal())); repeaterTone = new QAction(tr("Repeater Tone"), QPixmap::fromMimeSource("tone.png"),tr("&Repeater Tone"), QAccel::stringToKey(tr("Ctrl+R")), this); repeaterTone->setStatusTip(tr("Repeater Tone")); repeaterTone->setWhatsThis(tr("Repeater Tone\n\nSend 1750 Hz tone to open repeaters")); connect(repeaterTone, SIGNAL(activated()), this, SLOT(slotGenerateRepeaterTone())); fileOpen = new QAction(tr("Open file"),QPixmap::fromMimeSource("fileopen.png"),tr("&Open"),QAccel::stringToKey(tr("Ctrl+O")), this); fileOpen->setStatusTip(tr("Open an existing file")); fileOpen->setWhatsThis(tr("Open file\nOpen an existing file\n")); connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); alignement = new QAction(tr("Alignement"), tr("&Alignement Test"), 0, this); alignement->setStatusTip(tr("Alignement Test Signal")); alignement->setWhatsThis(tr("Alignement Test Signal\n\nGenerate an alignement signal (seconds beep)")); connect(alignement, SIGNAL(activated()), this, SLOT(slotAlignementSignal())); edit = new QAction(tr("Edit current image"),QPixmap::fromMimeSource("edit.png"),tr("&Edit"),QAccel::stringToKey(tr("Ctrl+E")), this); edit->setStatusTip(tr("Edit current Image")); edit->setWhatsThis(tr("Edit\n\nEdit current Image")); connect(edit, SIGNAL(activated()), this, SLOT(slotEdit())); } void txMainWindow::initToolbar() { toolBar = new QToolBar(this, "toolbarTX"); fileOpen->addTo(toolBar); startTX->addTo(toolBar); stopTX->addTo(toolBar); edit->addTo(toolBar); repeaterTone->addTo(toolBar); QWhatsThis::whatsThisButton( toolBar ); } void txMainWindow::initMenubar() { fileMenu=new QPopupMenu(); fileOpen->addTo(fileMenu); edit->addTo(fileMenu); menuBar()->insertItem(tr("&File"), fileMenu); actionMenu=new QPopupMenu(); startTX->addTo(actionMenu); stopTX->addTo(actionMenu); #ifdef DEBUGQSSTV startTXFile->addTo(actionMenu); #endif generateSignal->addTo(actionMenu); repeaterTone->addTo(actionMenu); alignement->addTo(actionMenu); menuBar()->insertItem(tr("&Actions"), actionMenu); // menuBar()->insertItem(tr("&Options"), optionMenu); // menuBar()->insertItem(tr("&Help"), helpMenu); } void txMainWindow::slotStartTX() { // we need to stop the receiver first rxMW->slotStopRX(); dsp->setCaptureSource(TRUE,NULL,FALSE); txf->process(); } void txMainWindow::slotStartTXFile() { #ifdef DEBUGQSSTV // we need to stop the receiver first rxMW->slotStopRX(); dsp->setCaptureSource(FALSE,NULL,FALSE); txf->process(); #endif } void txMainWindow::slotStopTX() { // we will restart the receiver txf->stop(); cv->txProgressBar->setProgress(0); rxMW->slotStartRX(); } void txMainWindow::slotDisplayStatusMessage(QString s) { statusBar()->message(s); } void txMainWindow::slotModeChanged(int m ) { logfile.add("slotModeChange"); if(txf->busy) return; txf->setModeIndex((sstvMode) m); } void txMainWindow::slotTemplateChanged(int t) { if(txf->busy) return; slotGetParams(); txf->addTemplate(t); } void txMainWindow::slotTemplateCBChanged(bool ) { if(txf->busy) return; slotGetParams(); txf->applyTemplate(); } void txMainWindow::slotFileOpen() { dirDialog d(this,0,TRUE); QString s=d.openFileName(txImagePath,"*"); if (s.isEmpty()) return; QFile f(s); mcanvas mCanvas(340,256); if(!mCanvas.load(f)) { QMessageBox::warning(this,"Image Properties","Error while loading\n" + s); return; } setImage(mCanvas.getImage(QSize(0,0))); } imageView *txMainWindow::getImagePtr() { return cv->imager; } void txMainWindow::setImage(QString fn) { QImage im; im.load(fn); txf->setImage(&im); } void txMainWindow::setImage(QImage *ima) { logfile.add("setting image"); slotGetParams(); toCall=cv->toCallLineEdit->text(); txf->setImage(ima); } void txMainWindow::slotCallChanged(const QString &str) { toCall=str; txf->addTemplate(txf->templateIndex); } void txMainWindow::slotOperatorChanged(const QString &str) { toOperator=str; txf->addTemplate(txf->templateIndex); } void txMainWindow::slotRSTChanged(const QString &str) { rst=str; txf->addTemplate(txf->templateIndex); } void txMainWindow::slotGenerateSignal() { freqForm ff; int freq; int duration; if(ff.exec()) { getValue(freq,ff.frequencySpinBox); getValue(duration,ff.durationSpinBox); txf->sendTone((float)freq,(float)duration); } } void txMainWindow::slotGenerateRepeaterTone() { txf->sendTone(1750.,3.); } void txMainWindow::slotAlignementSignal() { txf->sendAlignement(); } void txMainWindow::slotEdit() { if (ed!=NULL) delete ed; ed=new editor(this); connect(ed,SIGNAL(imageAvailable(QImage *)),SLOT(setImage(QImage *))); ed->setImage(txf->getImage()); ed->show(); } void txMainWindow::sendCW(QString &st) { txf->sendCW(st); } void txMainWindow::repeat(QImage *im,sstvMode sm) { setValue((int)sm,cv->modeComboBox); txf->setModeIndex((sstvMode)sm); // slotModeChanged(sm); txf->setImage(im); dsp->setCaptureSource(TRUE,NULL,FALSE); txf->process(); } void txMainWindow::slotRepeaterTimer() { QString fn; QFile fi; if ((rxMW->isBusy()) || (!repeaterEnable)) { // wait 10 seconds and check if busy or repeaterEnable has changed repeaterTimer->start(10000,TRUE); } else { switch(repeaterIndex) { case 0: fn=repeaterImage1; break; case 1: fn=repeaterImage2; break; case 2: fn=repeaterImage3; break; case 3: fn=repeaterImage4; break; default: fn=repeaterImage1; break; } fi.setName(fn); if (fi.exists()) { slotModeChanged(repeaterTxMode); setImage(fn); } repeaterIndex++; if(repeaterIndex>3) repeaterIndex=0; repeaterTimer->start(60000*repeaterImageInterval,TRUE); } }