/* MSHV EditRadInfo
 * Copyright 2015 Hrisimir Hristov, LZ2HV
 * (Edited by Harper Innes, VK1TTY - to remove Gendered Language and Replace with Non-Gendered language)  NOTE:May be used under the terms of the GNU General Public License (GPL)
 */
#include "editradinfo.h"

#define _MODESTRFORFREQ_H_
#include "../../config_band_all.h"

//#include <QtGui>
EditRadInfo::EditRadInfo(QWidget * parent )
        : QDialog(parent)
{
    //setMinimumSize(300,100);
    setWindowTitle(tr("Edit Radio And Frequencies"));
    setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);

    QLabel *l_lband = new QLabel(tr("Band")+": ");
    l_band = new QLabel("0 MHz");
    QHBoxLayout *hba = new QHBoxLayout();
    hba->setContentsMargins (0,0,0,0);
    hba->setSpacing(5);
    hba->addWidget(l_lband);
    hba->addWidget(l_band);
    hba->setAlignment(Qt::AlignCenter);

    QLabel *l_ant = new QLabel(tr("Antenna")+": ");
    ant = new QLineEdit();
    QHBoxLayout *v_ha = new QHBoxLayout();
    v_ha->setContentsMargins ( 0, 0, 0, 0);
    v_ha->setSpacing(5);
    v_ha->addWidget(l_ant);
    v_ha->addWidget(ant);

    VB_Freq = new QVBoxLayout();
    for (int i = 0; i<COUNT_FREQ_MODES; i++) 
    {
        if (i==0)//"MSK144","MSKMS" 
        {
            HvInLeFreq *le_frq  = new HvInLeFreq("MSK144,MSKMS "+tr("Frequency In")+" Hz:");
            VB_Freq->addWidget(le_frq);
        }
        else if (i==1)//"JTMS","FSK441","FSK315","ISCAT-A","ISCAT-B","JT6M"
        {
            HvInLeFreq *le_frq  = new HvInLeFreq("JTMS,FSK,ISCAT,JT6M "+tr("Frequency In")+" Hz:");
            VB_Freq->addWidget(le_frq);
        }
        else
        {
            HvInLeFreq *le_frq  = new HvInLeFreq(ModeStrForFerq[i]+" "+tr("Frequency In")+" Hz:");
            VB_Freq->addWidget(le_frq);
        }
    }

    pb_applay_info = new QPushButton(tr("Apply Changes"));//Apply
    pb_cancel_info = new QPushButton(tr("Cancel")) ;
    QHBoxLayout *h_b = new QHBoxLayout();
    h_b->setContentsMargins(0, 0, 0, 0);
    h_b->setSpacing(5);
    h_b->addWidget(pb_applay_info);
    h_b->addWidget(pb_cancel_info);
    connect(pb_cancel_info, SIGNAL(clicked(bool)), this, SLOT(close()));
    connect(pb_applay_info, SIGNAL(clicked(bool)), this, SLOT(ApplayInfo()));

    QVBoxLayout *v_b = new QVBoxLayout(this);
    v_b->setContentsMargins(5, 5, 5, 5);
    v_b->setSpacing(5);
    v_b->addLayout(hba);
    v_b->addLayout(v_ha);
    v_b->addLayout(VB_Freq);
    //v_b->addWidget(frq);

    v_b->addLayout(h_b);

    s_edit_index = -1;

    setLayout(v_b);
    setMinimumSize(350,215);
}
EditRadInfo::~EditRadInfo()
{}
void EditRadInfo::ApplayInfo()
{
    QStringList list;
    QString freqs;
    for (int i = 0; i<COUNT_FREQ_MODES; i++)
    {
        HvInLeFreq *le_frq = (HvInLeFreq*)VB_Freq->itemAt(i)->widget();
        freqs.append(le_frq->Text());
        if (i<COUNT_FREQ_MODES-1)
            freqs.append("\n");
    }
    list <<l_band->text() << ant->text() << freqs;
    emit EmitSetInfo(list ,s_edit_index);
}
void EditRadInfo::SetEditStInfo(QStringList list, int index)
{
    ant->setText(list.at(1));

    QString tfreq = list.at(2);
    QStringList ltfreq = tfreq.split("\n");
    for (int i = 0; i<COUNT_FREQ_MODES; i++)
    {
        HvInLeFreq *le_frq = (HvInLeFreq*)VB_Freq->itemAt(i)->widget();
        le_frq->SetText(ltfreq.at(i));
    }

    l_band->setText(list.at(0));
    s_edit_index = index;
    exec();
}



