/* MSHV MultiAnswerModW
 * Copyright 2018 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 "hvmultianswermodw.h"
#include "../config.h"
#include <QVBoxLayout>
#include <QPainter>
#include <QDateTime>
#include "../config_str_color.h"
//#include <QtGui>

ListA::ListA(int ident,bool f,QWidget *parent)
        : QTreeView(parent)
{
    dsty = f;
    f_auto_sort = false;
    setMinimumSize(50,50);
    this->setMaximumWidth(440);
    //setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Ignored);
    //qDebug()<<this->sizePolicy().horizontalPolicy()<<this->sizePolicy().verticalPolicy();

    setRootIsDecorated(false);

    setModel(&model);
    THvHeader = new QHeaderView(Qt::Horizontal);
    //connect(THvHeader, SIGNAL(sectionPressed(int)),this,SIGNAL(SortClicked(int)));

    setHeader(THvHeader);
    setAllColumnsShowFocus(true);  // za da o4ertae delia row

    //setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    if (ident==0)//Queue   for LNow 5 slots no need scrollbar
        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

    setSelectionBehavior(QAbstractItemView::SelectRows);

    setDragDropMode(QAbstractItemView::NoDragDrop);//QAbstractItemView::InternalMove
    setDragEnabled (false);
    // setAcceptDrops(true);
    setVerticalScrollMode(QAbstractItemView::ScrollPerItem);// tova e za na mi6kata whella i dragdrop QAbstractItemView::ScrollPerPixel
    setAutoScroll(false); // s tova tarsi samo v 1 colona i za scroll pri drag

    QPalette PaletteL = palette();
    PaletteL.setColor(QPalette::Shadow, QColor(120,120,120));// zaradi bordera okantovaneto na lista
    setPalette(PaletteL);

    QStringList list_A;
    if (ident==0)//Queue
        list_A <<tr("Call")<<"dB"<<"Rx dB"<<tr("Dist")<<"Grid"<<"Freq"<<"Time"<<"IDrpt"<<"TTry"<<"GinTxT"<<"s"<<"e";
    else
        list_A <<tr("Call")<<"dB"<<"Rx dB"<<"Dist"<<"Grid"<<"Freq"<<"Time"<<"IDrpt"<<"TTry"<<"GinTxT"<<"s"<<"e";

    model.setHorizontalHeaderLabels(list_A);

    THvHeader->setSectionResizeMode(QHeaderView::Fixed);//qt5

    //THvHeader->setResizeMode(2, QHeaderView::Fixed);
    THvHeader->resizeSection(0, 50);//call
    THvHeader->resizeSection(1, 40);//Tx db
    THvHeader->resizeSection(2, 35);//Rx db
    THvHeader->resizeSection(3, 60);//Dist
    THvHeader->resizeSection(4, 50);//Grid

    if (ident==0)//Queue
        THvHeader->resizeSection(5, 55);//Freq
    else  // Now
        THvHeader->resizeSection(5, 60);//Freq

    THvHeader->resizeSection(6, 50);//Time
    THvHeader->resizeSection(7, 25);//Nrpt
    THvHeader->resizeSection(8, 40);//TTry
    THvHeader->resizeSection(9, 20);//GinTxT
    THvHeader->resizeSection(10, 20);//s
    THvHeader->resizeSection(11, 20);//e

    if (ident==0)//Queue
    {
        //THvHeader->resizeSection(0, 50);//call
        THvHeader->hideSection(1);//Tx db
        THvHeader->hideSection(2);//Rx db
        //THvHeader->hideSection(3);//Dist
        THvHeader->hideSection(4);//Grid
        THvHeader->hideSection(5);//Freq
        THvHeader->hideSection(6);//Time
        THvHeader->hideSection(7);//Nrpt
        THvHeader->hideSection(8);//TTry
        THvHeader->hideSection(9);//GinTxT
        THvHeader->hideSection(10);//s
        THvHeader->hideSection(11);//e
    }
    else
    {
        //THvHeader->resizeSection(0, 50);//call
        THvHeader->hideSection(1);//Tx db
        THvHeader->hideSection(2);//Rx db
        THvHeader->hideSection(3);//Dist
        THvHeader->hideSection(4);//Grid
        //THvHeader->hideSection(5);//Freq
        THvHeader->hideSection(6);//Time
        THvHeader->hideSection(7);//Nrpt
        THvHeader->hideSection(8);//TTry
        THvHeader->hideSection(9);//GinTxT
        THvHeader->hideSection(10);//s
        THvHeader->hideSection(11);//e
    }

    THvHeader->setSectionResizeMode(0, QHeaderView::Stretch);//qt5

    m_right_c = new QMenu(this);
    //QAction *ac_spot = new QAction(QPixmap(":pic/spot_dx.png"),"Spot Receiving Text", this);//"Spot DX Cluster" Spot Receiving Text

    QAction *ac_clrall = new QAction(QPixmap(":pic/clr_all.png"),tr("CLR All"), this);
    if (ident==0)//ls Queue
    {
        QAction *ac_clrsel = new QAction(QPixmap(":pic/clr_sel.png"),tr("CLR Selected"), this);
        m_right_c->addAction(ac_clrsel);
        m_right_c->addAction(ac_clrall);
        connect(ac_clrsel, SIGNAL(triggered()), this, SLOT(DeleteSel()));
    }
    if (ident==1)//ls Now
        m_right_c->addAction(ac_clrall);
    connect(ac_clrall, SIGNAL(triggered()), this, SIGNAL(EmitClear_List()));
    //connect(ac_clrall, SIGNAL(triggered()), this, SLOT(Clear_List()));

    if (ident==0)//ls Queue
    {
        setSelectionMode(QAbstractItemView::ExtendedSelection);
        setSortingEnabled(true);
    }
    else         //ls Now
    {
        setSelectionMode(QAbstractItemView::NoSelection);
    }
    //2.31 false for "\n" jt6m=6 jtms=1
    setUniformRowHeights(true);//2.30 fast wiev
    //qDebug()<<"BBBAutoSortDist="<<f_auto_sort;
}
ListA::~ListA()
{}
void ListA::SetAutoSort(bool f)
{
    f_auto_sort = f; //qDebug()<<"BBBAutoSortDist="<<f;
    if (f_auto_sort)
    {
        sortByColumn(3,Qt::DescendingOrder);
        model.sort(3,Qt::DescendingOrder); //2.60
    }
}
void ListA::SetFont(QFont f)
{
    setFont(f);
    THvHeader->setFont(f);
}
void ListA::AutoSortDist()
{
    //qDebug()<<"AutoSortDist="<<THvHeader->sortIndicatorOrder();
    model.sort(3,THvHeader->sortIndicatorOrder());//2.60 sortByColumn(3,THvHeader->sortIndicatorOrder());
}
void ListA::SetItem(int row,int col,QString str)//2.57 remove new QStandardItem
{
    // end bug qt5.7 if setItem 0 row show hiden columns
    bool isHidenCol = THvHeader->isSectionHidden(col);
    //QStandardItem *item = new QStandardItem(str);
    QStandardItem *item = model.itemFromIndex(model.index(row,col));
    item->setText(str);

    if (col==3 || col==5)//freq and dist
        item->setTextAlignment(Qt::AlignCenter);

    model.setItem(row,col,item);
    // end bug qt5.7 if setItem 0 row show hiden columns
    if (isHidenCol) THvHeader->hideSection(col);

    if (f_auto_sort && THvHeader->sortIndicatorSection()==3 && col==3)//only LsQueue and distance
        AutoSortDist();
}
void ListA::InsertItem_hv(QStringList list)
{
    if (!list.isEmpty())
    {
        QList<QStandardItem *> qlsi;
        int k = 0;
        for (QStringList::iterator it =  list.begin(); it != list.end(); ++it)
        {
            QStandardItem *item = new QStandardItem(QString(*it));

            if (k==3 || k==5)//freq and dist
                item->setTextAlignment(Qt::AlignCenter);
            item->setEditable(false);

            /*if (!f_row_color)
                item->setBackground(QColor(255,255,255));
            else
                item->setBackground(QColor(212,222,242)); //rgb*/
            qlsi.append(item);

            k++;
        }
        //model.insertRow(model.rowCount(), qlsi);
        model.appendRow(qlsi);

        emit ListCountChange(model.rowCount());

        if (f_auto_sort && THvHeader->sortIndicatorSection()==3)//only LsQueue and distance
            AutoSortDist();
    }
    //this->setCurrentIndex(model.index(model.rowCount(), 1, QModelIndex()));
}
int ListA::FindCallOrBaseCallRow(QString c)
{
    int row = -1;
    for (int i = 0; i < model.rowCount(); ++i)
    {
        QString call = model.item(i, 0)->text();
        QStringList	calls = call.split("/");
        for (int j = 0; j < calls.count(); ++j)
        {
            if (c==calls.at(j))
            {
                row = i;
                return row;//break;
            }
        }
    }
    return row;
}
void ListA::RemoveRow(int i)
{
    model.removeRow(i);
    emit ListCountChange(model.rowCount());
}
void ListA::RemoveRows(int pos,int cou)// no need to save temp all go to Now List
{
    model.removeRows(pos,cou);
    emit ListCountChange(model.rowCount());
}
void ListA::Clear_List()
{
    for (int i = model.rowCount()-1; i >= 0; --i)
        model.removeRow(i);
    emit ListCountChange(model.rowCount());
}
void ListA::DeleteSel()
{
    if (!selectionModel()->selection().empty())
    {
        //setAutoScroll(false); // za da ne skrolira pri iztrivane kam poslednia markiran
        QItemSelection selection( selectionModel()->selection() );

        QList<int> rows;
        foreach( const QModelIndex & index, selection.indexes() )
        {
            rows.append( index.row() );
        }
        //q_Sort( rows );
        std::sort(rows.begin(),rows.end());
        int prev = -1;
        for ( int i = rows.count() - 1; i >= 0; i -= 1 )
        {
            int current = rows[i];
            if ( current != prev )
            {
                model.removeRows(current,1);
                prev = current;
            }
        }
        //setAutoScroll(true);  // za da ne skrolira pri iztrivane kam poslednia markiran
        emit ListCountChange(model.rowCount());
    }
}
void ListA::paintEvent(QPaintEvent *event)
{
    QPainter painter(viewport());
    //QModelIndex index = model.index(ActiveIndex, 1, QModelIndex());
    //painter.fillRect(QRect(0,visualRect(index).y(),width(),visualRect(index).height()), ActiveRowBackg);
    QTreeView::paintEvent(event);

    painter.save();
    QColor cc = QColor(200,200,200);
    if (dsty) cc = QColor(80,80,80);
    painter.setPen(QPen(cc, 1, Qt::DashLine));

    //qDebug()<<model.columnCount();
    for (int i = 1; i<model.columnCount(); ++i)
        painter.drawLine(header()->sectionPosition(i),1,header()->sectionPosition(i),height());

    painter.restore();
}
void ListA::mousePressEvent(QMouseEvent * event)
{
    QTreeView::mousePressEvent(event);
    //if (event->button() == Qt::RightButton)
    //SendRightClick();

    //if (s_ident==0)//ls Queue
    //{
    QModelIndex index = indexAt(event->pos());
    if (event->button() == Qt::RightButton && !(index.row() == -1))
        m_right_c->exec(QCursor::pos());
    //}
    /*if (s_ident==1)//ls now
    {
        QModelIndex index = indexAt(event->pos());
        if (event->button() == Qt::RightButton && !(index.row() == -1))
            m_right_cn->exec(QCursor::pos());
    }*/
}

HvSpinLE::HvSpinLE(QWidget * parent )
        : QLineEdit(parent)
{}
HvSpinLE::~HvSpinLE()
{}
void HvSpinLE::mouseDoubleClickEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        emit EmitDoubleClick();
        return;
    }
    QLineEdit::mouseDoubleClickEvent(event);
}
HvSpinBoxMTP::HvSpinBoxMTP(QWidget * parent )
        : QSpinBox(parent)
{
	f_sb_mtp = false;
	HvSpinLE *le = new HvSpinLE();
	setLineEdit(le);
	le->setReadOnly(true);
	setContextMenuPolicy(Qt::NoContextMenu);	
	setSingleStep(1);
    setValue(2);
    setRange(1,10);
    setPrefix(tr("Max Time")+":  ");
    setSuffix("  "+tr("min"));
    setStyleSheet("QSpinBox {selection-color: black; selection-background-color: white;}");
    setToolTip(tr("Double Click for changing to\nMax Time or Max Periods"));
    connect(le, SIGNAL(EmitDoubleClick()), this, SLOT(SetDoubleClick()));
}
HvSpinBoxMTP::~HvSpinBoxMTP()
{}
void HvSpinBoxMTP::SetDoubleClick()
{
	if (f_sb_mtp)
	{
		f_sb_mtp = false;
    	setPrefix(tr("Max Time")+":  ");
    	setSuffix("  "+tr("min"));		
	}
	else
	{
		f_sb_mtp = true;
    	setPrefix(tr("Max Periods")+":  ");
    	setSuffix(" ");		
	}
}

#define _CONT_NAME_
#include "../config_str_con.h"

#include "config_rpt_all.h"

#define MAXB_DB 20
static int backup_db_pos_write;
static QString backup_db_[MAXB_DB+2][6+2];
static QString str_macros_mam_[7];//2.47 for win10
MultiAnswerModW::MultiAnswerModW(bool f,QWidget * parent )
        : QTabWidget(parent)
{
    dsty = f;
    g_block_stop_auto = false;//2.52
    f_auto_on = false;
    gg_frest = false;
    for (int i = 0; i<MAXB_DB; ++i)
    {
        for (int j = 0; j<6; ++j)
            backup_db_[i][j] = "";
    }
    backup_db_pos_write = 0;
    current_msg = "";

    s_qrg = "237";
    s_last_bccall_tolog_excp = "NONE_";
    f_cfm73 = true;
    s_le_their_call = "";
    //this->setFixedHeight(160);
    //this->setFixedHeight(158);
    setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Ignored);// inportent 1.81
    //setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Ignored);
    this->setStyleSheet("QTabBar::tab {height: 22px}");
    s_co_type = 0;
    s_co_id = 0;
    //lis_macros_mam_<<"%T %M %G4"<<"%T %M %R"<<"%T %M R%R"<<"%T %M RR73"<<"%T %M RR73"<<"CQ %M %G4";
    str_macros_mam_[0]="%T %M %G4";//2.47
    str_macros_mam_[1]="%T %M %R";
    str_macros_mam_[2]="%T %M R%R";
    str_macros_mam_[3]="%T %M RR73";
    str_macros_mam_[4]="%T %M RR73";
    str_macros_mam_[5]="CQ %M %G4";
    s_txsn_v2 = 1;
    QWidget *queue =new QWidget();
    LsQueue = new ListA(0,dsty);
    QVBoxLayout *V_lq = new QVBoxLayout();
    V_lq->setContentsMargins (0, 0, 0, 0);
    V_lq->setSpacing(0);
    queue->setLayout(V_lq);
    V_lq->addWidget(LsQueue);

    QWidget *now_work =new QWidget();
    LsNow = new ListA(1,dsty);
    QVBoxLayout *V_ln = new QVBoxLayout();
    V_ln->setContentsMargins (0, 0, 0, 0);
    V_ln->setSpacing(0);
    now_work->setLayout(V_ln);
    V_ln->addWidget(LsNow);

    QWidget *settings =new QWidget();

    SBqueueLimit = new QSpinBox();
    SBqueueLimit->setSingleStep(1);
    SBqueueLimit->setValue(5);
    //SBqueueLimit->setRange(1,50);//1.78 100
    SBqueueLimit->setRange(0,50);//2.39 0
    SBqueueLimit->setPrefix(tr("Queue Limit")+":  ");
    //SBqueueLimit->setReadOnly(true);
    SBqueueLimit->findChild<QLineEdit*>()->setReadOnly(true);
    SBqueueLimit->setContextMenuPolicy(Qt::NoContextMenu);
    SBqueueLimit->setStyleSheet("QSpinBox {selection-color: black; selection-background-color: white;}");

    SBslots = new QSpinBox();
    SBslots->setSingleStep(1);
    SBslots->setValue(1);
    SBslots->setRange(1,5);
    SBslots->setPrefix(tr("TX Slots")+":  ");
    //SBslots->setReadOnly(true);
    SBslots->findChild<QLineEdit*>()->setReadOnly(true);
    SBslots->setContextMenuPolicy(Qt::NoContextMenu);
    SBslots->setStyleSheet("QSpinBox {selection-color: black; selection-background-color: white;}");
        
    /*SBmaxtime = new QSpinBox();
    SBmaxtime->setSingleStep(1);
    SBmaxtime->setValue(2);
    SBmaxtime->setRange(1,10);
    SBmaxtime->setPrefix(tr("Max Time")+":  ");
    SBmaxtime->setSuffix("  "+tr("min"));
    SBmaxtime->findChild<QLineEdit*>()->setReadOnly(true);
    SBmaxtime->setStyleSheet("QSpinBox {selection-color: black; selection-background-color: white;}");*/
    period_time_sec = 15.0;
    SBmaxTP = new HvSpinBoxMTP();

    QVBoxLayout *V_sb = new QVBoxLayout();
    V_sb->setContentsMargins(0, 0, 0, 0);
    V_sb->setSpacing(1);
    V_sb->addWidget(SBqueueLimit);
    V_sb->addWidget(SBslots);
    V_sb->addWidget(SBmaxTP);

    Cbcqtype = new QComboBox();
    QStringList lst_m;  //2.68 "CQ MDX" = MADX
    lst_m<<"CQ"<<"CQ MDX"<<"CQ DX"<<"CQ UP"<<"CQ AF"<<"CQ AN"<<"CQ AS"<<"CQ EU"<<"CQ NA"<<"CQ OC"
    <<"CQ SA"<<"CQ JA"/*<<"CQ 0"<<"CQ 1"<<"CQ 2"<<"CQ 3"<<"CQ 4"<<"CQ 5"<<"CQ 6"<<"CQ 7"
                        <<"CQ 8"<<"CQ 9"<<"CQ MACQ"*/<<"CQ QRG"<<"CQ END"<<"TIME"<<"Free Msg";

    Cbcqtype->setFocusPolicy(Qt::NoFocus);
    int fHeight = 21;
    Cbcqtype->setFixedHeight(fHeight);

    LeFreeCQ = new HvLeWithSpace();
    //LeFreeCQ->setMaximumWidth(165);
    //LeFreeCQ->setMinimumWidth(165);
    //LeFreeCQ->setFixedWidth(165);
    LeFreeCQ->setFixedHeight(fHeight);
    LeFreeCQ->setMaxLength(26);
    //LeFreeCQ->setText("CQ");
    LeFreeCQ->setEnabled(false);
    //LeFreeCQ->setContentsMargins(1, 1, 0, 1);
    //LeFreeCQ->setFocusPolicy(Qt::TabFocus);
    //LeFreeCQ->setFocusPolicy(Qt::NoFocus);
    //Cbcqtype->setEditable(true);
    f_block_free_cq = false;
    pb_use_free_cq =new QPushButton(tr("USE"));
    QHBoxLayout *H_fmsg = new QHBoxLayout();
    H_fmsg->setContentsMargins(1, 0, 0, 0);
    H_fmsg->setSpacing(2);
    H_fmsg->addWidget(LeFreeCQ);
    H_fmsg->addWidget(pb_use_free_cq);
    pb_use_free_cq->setEnabled(false);
    pb_use_free_cq->setFixedSize(45,20);

    Cbcqtype->addItems(lst_m);
    Cbcqtype->setCurrentIndex(0);
    QString tip1 = "CQ MDX, MSHV "+tr("recommended\nidentification for DXpeditions");    
    Cbcqtype->setItemData(1,tip1,Qt::ToolTipRole);
    tip1.prepend(tr("CQ Type")+":\n");
    Cbcqtype->setToolTip(tip1);

    cb_tx_cq_on_free_slot = new QCheckBox(tr("CQ on free slot"));
    cb_tx_cq_on_free_slot->setToolTip(tr("TX CQ on free slot"));//2.13 special msg
    cb_tx_cq_on_free_slot->setChecked(false);
    QHBoxLayout *H_l4 = new QHBoxLayout();
    H_l4->setContentsMargins(1, 0, 1, 0);
    H_l4->setSpacing(2);
    H_l4->addWidget(Cbcqtype);
    H_l4->addWidget(cb_tx_cq_on_free_slot);

    //cb_no_dupes = new QCheckBox(tr("No Dupe"));
    Cb_dupes = new QComboBox();
    Cb_dupes->setFixedHeight(fHeight);
    //Cb_dupes->setToolTip(tr("Dupe function\nMax QSOs per Call in Log"));
    //Cb_dupes->setToolTip(tr("Maximum QSOs per Call in the log"));
    //Cb_dupes->setToolTip(tr("Maximum QSOs per Call\nFiltered by Call, Band, Mode"));
    s_txt_mark_b = true;//2.66 inportet default all is marked HV 1.26 here and in hvtxtcolor.cpp
    s_txt_mark_m = true;//2.66 inportet default all is marked HV 1.26 here and in hvtxtcolor.cpp
    SetTextMark(s_txt_mark_b,s_txt_mark_m);
    QStringList lst_d;
    //lst_d<<tr("No Dupe")<<tr("No Dupe")<<tr("One Dupe")<<tr("Two Dupe");
    lst_d<<tr("No Limit")<<tr("1 QSO")<<tr("2 QSOs")<<tr("3 QSOs");
    Cb_dupes->addItems(lst_d);
    /*Cb_dupes->addItem("No Limit");
    Cb_dupes->addItem("1 QSO");
    Cb_dupes->addItem("2 QSOs");
    Cb_dupes->addItem("3 QSOs");*/

    cb_tx_sm = new QCheckBox("SMsg");//2.10 special msg
    cb_cont_ns = new QCheckBox(tr("CNS"));
    //cb_cont_ns->setToolTip("Continue non-stop");
    cb_cont_ns->setHidden(true);

    //cb_tx_sm->setToolTip("No TX special msgs");//2.10 special msg
    cb_tx_sm->setToolTip(tr("TX Special MSG:\nA2AA RR73; B2BB <C2CC> +05"));//2.10 special msg
    cb_tx_sm->setChecked(false);//default no emit
    cb_a_sort = new QCheckBox(tr("Auto Sort"));
    cb_a_sort->setToolTip(tr("Auto sorting of Queued is activated\nif Dist column header is marked"));//2.10 special msg
    cb_a_sort->setChecked(false);//default no emit

    QVBoxLayout *V_cb = new QVBoxLayout();
    V_cb->setContentsMargins(0, 0, 0, 0);
    V_cb->setSpacing(2);
    //V_cb->addWidget(cb_no_dupes);
    V_cb->addWidget(Cb_dupes);
    V_cb->addWidget(cb_tx_sm);
    V_cb->addWidget(cb_cont_ns);
    V_cb->addWidget(cb_a_sort);

    QHBoxLayout *H_l2 = new QHBoxLayout();
    H_l2->setContentsMargins(1, 0, 1, 0);
    H_l2->setSpacing(4);
    H_l2->addLayout(V_sb);
    H_l2->addLayout(V_cb);

    pb_clr_queue = new QPushButton(tr("CLR QUEUE"));
    pb_clr_queue->setFixedHeight(fHeight);
    pb_clr_now = new QPushButton(tr("CLR NOW"));
    pb_clr_now->setFixedHeight(fHeight);
    QHBoxLayout *H_lb = new QHBoxLayout();
    H_lb->setContentsMargins(1, 0, 0, 0);
    //H_lb->setContentsMargins(0, 0, 0, 0);
    H_lb->setSpacing(4);
    H_lb->addWidget(pb_clr_queue);
    H_lb->addWidget(pb_clr_now);
    //H_lb->setAlignment(Qt::AlignCenter);

    QVBoxLayout *V_ls = new QVBoxLayout();
    V_ls->setContentsMargins(2, 2, 2, 2);
    //V_ls->setContentsMargins(0, 0, 0, 0);
    V_ls->setSpacing(1);
    settings->setLayout(V_ls);

    V_ls->addLayout(H_l2);
    //V_ls->addWidget(Cbcqtype);
    V_ls->addLayout(H_l4);

    V_ls->addLayout(H_fmsg);
    //V_ls->setAlignment(LeFreeCQ,Qt::AlignCenter);
    V_ls->addLayout(H_lb);
    //V_ls->setAlignment(H_lb,Qt::AlignCenter);
    V_ls->setAlignment(Qt::AlignTop | Qt::AlignHCenter); //setAlignment(Box_dt,Qt::AlignRight);

    addTab(queue, tr("Queue")+" 0");
    addTab(now_work, tr("Now")+" 0");
    addTab(settings, tr("Settings"));//Settings
    setCurrentIndex(1);//2.11

    /*QString tabStyle = "QTabBar::tab:top:!selected{margin-top:2px;}"
    				   "QTabBar::tab:top:selected{margin-top:2px;}"
    				   "QTabBar::tab:left:!selected{margin-right:2px;}"
    				   "QTabBar::tab:left:selected{margin-right:2px;}";
    setStyleSheet(tabStyle);*/
    allq65 = false;
    s_mode = 2;
    info_dupe_qso = true;//2.51 default
    //s_txt_mark_b = true;//2.66 inportet default all is marked HV 1.26 here and in hvtxtcolor.cpp
    //s_txt_mark_m = true;//2.66 inportet default all is marked HV 1.26 here and in hvtxtcolor.cpp
    f_multi_answer_mod_std = false;
    s_start_qso_from_tx2 = false;

    list_macros<<""<<""<<""<<""<<""<<""<<""<<""<<""<<""<<""<<""<<""<<""<<""<<"";
    s_my_base_call = "_NONE_";
    //s_my_call_is_std = true;
    f_con_only_sdtc = false;
    my_call_have_slash = false;
    f_km_mi = false;//km

    f_tx_rx = false;
    s_count_nw_i3b = 0;
    for (int i = 0; i <5; ++i)
        t_list_i3b[i]="";
    s_pos_nw_i3b = 0;
    gen_in_tx_time = "0";//1tx 0rx
    
    f_aseqmaxdist = false;//2.66
    is_LastTxRptCq = false;//2.66
    s_dist_points = -1;//2.66

    connect(pb_clr_queue, SIGNAL(clicked(bool)), this, SLOT(ClrQueue()));
    connect(pb_clr_now, SIGNAL(clicked(bool)), this, SLOT(ClrNow()));
    connect(LsQueue, SIGNAL(ListCountChange(int)), this, SLOT(LQueueCountChange(int)));
    connect(LsNow, SIGNAL(ListCountChange(int)), this, SLOT(LNowCountChange(int)));
    connect(Cbcqtype, SIGNAL(currentIndexChanged(QString)), this, SLOT(CbCQChanged(QString)));
    connect(LsQueue, SIGNAL(EmitClear_List()), this, SLOT(ClrQueue()));
    connect(LsNow, SIGNAL(EmitClear_List()), this, SLOT(ClrNow()));
    connect(SBslots, SIGNAL(valueChanged(int)), this, SLOT(SBslotsValueChanged(int)));
    connect(LeFreeCQ, SIGNAL(textChanged(QString)), this, SLOT(LeFreeCQtextChanged(QString)));
    connect(pb_use_free_cq, SIGNAL(clicked(bool)), this, SLOT(UseFreeCq()));
    connect(cb_a_sort, SIGNAL(toggled(bool)), LsQueue, SLOT(SetAutoSort(bool)));
    connect(cb_tx_cq_on_free_slot, SIGNAL(toggled(bool)), this, SLOT(CbTxCqOnFreeSlotChanged(bool)));

    //SetDefaultMacros();
}
MultiAnswerModW::~MultiAnswerModW()
{
    // destroy
}
void MultiAnswerModW::SetFont(QFont f)
{
    setFont(f);
    LsNow->SetFont(f);
    LsQueue->SetFont(f);
    SBqueueLimit->setFont(f);
    SBslots->setFont(f);
    SBmaxTP->setFont(f);
    Cbcqtype->setFont(f);
    //2.16 no need for the moment
    //for (int i = 0; i < Cbcqtype->count(); ++i)
    //Cbcqtype->setItemData(i,f,Qt::FontRole);
    //qDebug()<<Cbcqtype->count();
    //cb_no_dupes->setFont(f);
    Cb_dupes->setFont(f);
    cb_tx_sm->setFont(f);
    cb_cont_ns->setFont(f);
    cb_a_sort->setFont(f);
    cb_tx_cq_on_free_slot->setFont(f);
    LeFreeCQ->setFont(f);
    pb_use_free_cq->setFont(f);
    pb_clr_queue->setFont(f);
    pb_clr_now->setFont(f);
    //LsQueue->setFixedHeight(height());
    //LsNow->setFixedHeight(height());
}
void MultiAnswerModW::SetReriodTime(float d)
{
	period_time_sec = d;
}
void MultiAnswerModW::SetSettings(QString s)
{
    QStringList ls = s.split("#");
    if (ls.count()<8) return;
    ls<<"0"<<"0"; //support for old ver
    SBqueueLimit->setValue(ls.at(0).toInt());
    SBslots->setValue(ls.at(1).toInt());
    SBmaxTP->setValue(ls.at(2).toInt());
    Cb_dupes->setCurrentIndex(ls.at(3).toInt());
    if (ls.at(4)=="1") cb_tx_sm->setChecked(true);
    else cb_tx_sm->setChecked(false);
    if (ls.at(5)=="1") cb_a_sort->setChecked(true);
    else cb_a_sort->setChecked(false);
    if (ls.at(6)=="1") cb_tx_cq_on_free_slot->setChecked(true);
    else cb_tx_cq_on_free_slot->setChecked(false);
    if (ls.at(7)=="1") cb_cont_ns->setChecked(true);
    else cb_cont_ns->setChecked(false);       
    if (ls.at(8)=="1") SBmaxTP->SetDoubleClick();    
}
void MultiAnswerModW::LQueueCountChange(int n)
{
    setTabText(0,tr("Queue")+" "+QString("%1").arg(n));
}
void MultiAnswerModW::LNowCountChange(int n)
{
    setTabText(1,tr("Now")+" "+QString("%1").arg(n));
}
#include "../pfx_sfx.h"
bool MultiAnswerModW::is_pfx(QString s)
{
    bool res = false;
    for (int i = 0; i < NZ; i++)
    {
        if (s==pfx[i])
        {
            res = true;
            break;
        }
    }
    return res;
}
bool MultiAnswerModW::is_sfx(QString s)
{
    bool res = false;
    for (int i = 0; i < NZ2; i++)
    {
        if (s==(QString)sfx[i])
        {
            res = true;
            break;
        }
    }
    return res;
}
bool MultiAnswerModW::FormatTxIfSlash6CharCall(QString &s,int tx_id,bool &f_pfx_sfx)
{
    bool have_slash = false;
    f_pfx_sfx = false;
    if (s.contains("/"))
    {
        bool call_0 = false;
        bool call_1 = false;
        bool fpfx   = false;
        QStringList l_s = s.split("/"); //qDebug()<<l_my.count();

        if (is_pfx(l_s.at(0)))
            fpfx   = true;
        if (!is_pfx(l_s.at(0)) && THvQthLoc.isValidCallsign(l_s.at(0)))
            call_0 = true;
        if (!is_pfx(l_s.at(1)) && THvQthLoc.isValidCallsign(l_s.at(1)))
            call_1 = true;

        if (call_0 && call_1)
            s = l_s.at(1).mid(0,6);
        else if (call_0 && !call_1)
        {
            if (tx_id==0 || tx_id==6)
            {
                if (is_sfx(l_s.at(1)))
                {
                    have_slash= true;
                    s = l_s.at(0).mid(0,6)+"/"+l_s.at(1);
                }
                else
                    s = l_s.at(0).mid(0,6);
            }
            else
            {
                if (is_sfx(l_s.at(1)))
                    f_pfx_sfx = true;

                have_slash= true;
                s = l_s.at(0).mid(0,6)+"/"+l_s.at(1).mid(0,6);
            }
        }
        else if (fpfx && !call_0 && call_1)
        {
            f_pfx_sfx = true;
            have_slash= true;
            s = l_s.at(0).mid(0,6)+"/"+l_s.at(1).mid(0,6);
        }
        else if (!call_0 && call_1)//1.74 w1/kh7z corr
        {
            //s = s;
            s = l_s.at(1).mid(0,6);
            //have_slash= true;
        }
        else
            s = l_s.at(0).mid(0,6);
    }
    else
        s = s.mid(0,6);

    return have_slash;
}
QString MultiAnswerModW::FindBase6CharCallRemAllSlash(QString str)// nay be need flag only 6
{
    QString res = str.mid(0,6);
    if (str.contains("/"))
    {
        QStringList list_str = str.split("/");

        if (list_str.count() >= 3) //more then 2 shlashes SP9/LZ2HV/QRP
            res = list_str.at(1).mid(0,6);//2.00
        else
        {// only 2 count
            bool call_0 = false;
            bool call_1 = false;

            if (!is_pfx(list_str.at(0)) && THvQthLoc.isValidCallsign(list_str.at(0)))
                call_0 = true;
            if (!is_pfx(list_str.at(1)) && THvQthLoc.isValidCallsign(list_str.at(1)))
                call_1 = true;

            if (call_0 && call_1)       //bin=11 int=3
                res = list_str.at(1).mid(0,6);
            else if (call_0 && !call_1) //bin=10 int=2
                res = list_str.at(0).mid(0,6);
            else if (!call_0 && call_1) //bin=01 int=1
                res = list_str.at(1).mid(0,6);
            else
                res = list_str.at(0).mid(0,6);   //bin=00 int=0
        }
    }
    return res;
}
QString MultiAnswerModW::FindBaseFullCallRemAllSlash(QString str)
{
    QString res = str;
    if (str.contains("/"))
    {
        QStringList list_str = str.split("/");

        if (list_str.count() >= 3) //more then 2 shlashes SP9/LZ2HV/QRP
            res = list_str.at(1);
        else
        {// only 2 count
            bool call_0 = false;
            bool call_1 = false;

            if (THvQthLoc.isValidCallsign(list_str.at(0)))//if (!is_pfx(list_str.at(0)) && isValidCallsign(list_str.at(0)))
                call_0 = true;
            if (THvQthLoc.isValidCallsign(list_str.at(1)))//if (!is_pfx(list_str.at(1)) && isValidCallsign(list_str.at(1)))
                call_1 = true;

            if (call_0 && call_1)    //bin=11 int=3
                res = list_str.at(1);//res = list_str.at(1).mid(0,6);
            else if (call_0 && !call_1) //bin=10 int=2
                res = list_str.at(0);//res = list_str.at(0).mid(0,6);
            else if (!call_0 && call_1) //bin=01 int=1
                res = list_str.at(1);//res = list_str.at(1).mid(0,6);
            else
                res = list_str.at(0);//res = list_str.at(0).mid(0,6);   //bin=00 int=0
        }
    }
    return res;
}
void MultiAnswerModW::SetTheirCallChanged(QString s)
{
    s_le_their_call = s; //qDebug()<<"e="<<s_le_their_call;
}
void MultiAnswerModW::DetectTextInMsg(QString str, QString &theirCall_inmsg,QString &theirLoc_inmsg,QString &myCall_inmsg,
                                      QString &rpt_inmsg,QString &cont_r_inmsg,QString &rr73_inmsg,
                                      int &row_queue,int &row_now,//2.27=   QString theirCallFromLe,
                                      QString &sn_inmsg,QString &arrl_exch_imsg)//v.2.01
{
    //str="LZ2HVG RR73; LZ2HVV <...> +06"; //fox exception
    //str="TU; <...> LZ2HV R 589 NY";      //RU exception
    //str="TU; LZ2HV <...> R 589 0041";    //RU exception
    //str="<...> LZ33MM +05";              //v2 exception
    //str="LZ33MM <...> +07";              //v2 exception
    //2.27
    QString theirCallFromLe = "";//inportent only one slot needed     nowcall,//"" <- corr for eu VHF
    if (f_multi_answer_mod_std)//no problem bez tova-> && s_id_con==3
    {
        if (LsNow->GetRowCount()>0)// <- importent
            theirCallFromLe = LsNow->model.item(0,0)->text();
    }
    else // || f_multi_answer_mod is a problem for eu vhf contest
        theirCallFromLe = s_le_their_call;
    //qDebug()<<"e="<<str<<theirCallFromLe;

    bool is_fox_msg_for_me_as2call_ft8 = false;
    //??? We're in RTTY contest and have "nextCall" queued up: send a "TU; ..." message
    //QString tu_inmsg;
    if (str.mid(0,4)=="TU; ") str.remove("TU; ");
    str.remove("<");
    str.remove(">");
    str.remove(";");

    //QString my_base_call = FindBaseCallRemAllSlash(list_macros.at(0));

    bool some_digits = false;
    //QString sn_inmsg;
    //QString arrl_cat_inmsg;
    //QString arrl_sec_inmsg;
    int pos_loc_call_as_grig = 100;  //2.13 exeprion call_as_grig PA70, PA70X, PA70XX

    QStringList ls_text = str.split(" ");
    for (int i = ls_text.count()-1; i>=0; --i)
    {
        //"TA2NC RR73 SP9HWY <...> +00"
        //<...> LZ33MM +00              v2 exception
        //LZ33MM <...> +00              v2 exception
        //"TU; LZ2HV <...> R 589 NY"    TU;<-removed
        //"TU; <...> LZ2HV R 589 0001"  TU;<-removed
        //str="<...> +07";              msk144 +sh
        //ft8+msk144 + fox exeption for call no exist and v2 non-standard calls
        if ((s_mode==11 || s_mode==0 || s_mode==13 || allq65) && i>0 && ls_text.at(i)=="...")//ft4
            theirCall_inmsg="...";

        if (theirLoc_inmsg.isEmpty() && THvQthLoc.isValidLocator(ls_text.at(i)))
        {
            theirLoc_inmsg = ls_text.at(i);
            pos_loc_call_as_grig = i;   //2.13 exeprion call_as_grig PA70, PA70X, PA70XX
        }
        else if (theirCall_inmsg.isEmpty() && THvQthLoc.isValidCallsign(ls_text.at(i)))
        {
            theirCall_inmsg = ls_text.at(i);

            if (!theirCall_inmsg.isEmpty())
            {   // my be all is digits
                bool all_dig = true;
                for (int j = 0; j < theirCall_inmsg.count(); ++j)
                {
                    if (theirCall_inmsg.at(j).isLetter())
                    {
                        all_dig = false;
                        break;
                    }
                }
                if (all_dig)// all is digits
                {
                    int rptsn = theirCall_inmsg.toInt(); //qDebug()<<theirCall_inmsg<<theirCall_inmsg.count()<<rptsn;
                    //2.39 old if (rptsn>=520001 && rptsn<=594095)//4095  sn_inmsg.isEmpty() &&
                    if (rptsn>=520001 && rptsn<=592047)//new ->2047  sn_inmsg.isEmpty() &&
                    {
                        rpt_inmsg = theirCall_inmsg.mid(0,2);
                        sn_inmsg = theirCall_inmsg.mid(2,4);
                        //2.39 old EU VHF -> theirCall_inmsg = theirCallFromLe;
                        theirCall_inmsg = "";//2.39 new EU VHF
                    }
                    else if (rptsn>=1000 && rptsn<=7999)//1000-4095  RU DX SN     theirCall_inmsg.count() == 4 &&
                    {
                        sn_inmsg = theirCall_inmsg;
                        theirCall_inmsg = "";
                    }
                    else if (rptsn>=529 && rptsn<=599)//theirCall_inmsg.count() == 3 &&
                    {
                        rpt_inmsg = theirCall_inmsg;
                        theirCall_inmsg = "";
                    }
                    else
                    {
                        some_digits = true;//100-10000000000 exception
                        theirCall_inmsg = "";
                    }
                }
                else //2.01 exception no call frm to 10A-32A ARRL Field Day category
                {
                    if (theirCall_inmsg.count() == 3)//10A-32F  t1>="A" and t1<="F"
                    {
                        int t1 = (int)theirCall_inmsg.at(2).toLatin1();
                        int dg = theirCall_inmsg.midRef(0,2).toInt();
                        if (t1>=(int)'A' && t1<=(int)'F' && dg>=10 && dg<=32)//no need 01a-nocall -> && theirCall_inmsg.mid(0,2).toInt()>0
                        {
                            arrl_exch_imsg = theirCall_inmsg;
                            theirCall_inmsg = "";
                        }
                    }
                }
            }

            if (i==0 && !theirCall_inmsg.isEmpty())//1.73 exception lz2hv/qrp 73
            {
                if (FindBaseFullCallRemAllSlash(theirCall_inmsg)==s_my_base_call)
                {
                    if (my_call_have_slash)//no_pfx_sfx_have_slash problem is-> no pfx no sfx but have slash     && !theirCallFromLe.isEmpty()
                        theirCall_inmsg = theirCallFromLe;
                    else
                        theirCall_inmsg = "";
                    myCall_inmsg = ls_text.at(i);//or list_macros.at(0)
                    //qDebug()<<"1.73 exception lz2hv/qrp 73"<<"myCall_inmsg="<<myCall_inmsg<<"theirCall_inmsg="<<theirCall_inmsg;
                }
            }//end 1.73 exception lz2hv/qrp 73
            if (s_mode==12)// rpt_ms theirCall exception //////////////////// new MSK144MS //////////////////
            {
                bool is_rpt_ms = false;
                for (int x = 0; x < COUNT_RPT_MS; ++x)
                {
                    QString r_rpt = "R"+rpt_ms_p[x];
                    if (r_rpt == theirCall_inmsg)
                    {
                        is_rpt_ms = true;
                        break;
                    }
                }
                if (is_rpt_ms)
                {
                    rpt_inmsg = theirCall_inmsg;// no needed
                    theirCall_inmsg = "";
                }
            }////////////////////end new MSK144MS //////////////////
        }
        else if (myCall_inmsg.isEmpty() &&  THvQthLoc.isValidCallsign(ls_text.at(i)) &&
                 //ls_text.at(i)==list_macros.at(0))//list_macros.at(0)<-mycall  FindBaseCallRemAllSlash(my_call);
                 FindBaseFullCallRemAllSlash(ls_text.at(i))==s_my_base_call)//1.70
        {
            myCall_inmsg = ls_text.at(i);
            if ((s_mode==11 || s_mode==13 || allq65) && i>0)//ft8 ft4 + fox exeption my call no first 1.69
                is_fox_msg_for_me_as2call_ft8 = true;
        }
        else if (cont_r_inmsg.isEmpty() && ls_text.at(i)=="R") //msk144 ft8 contest mode
            cont_r_inmsg = ls_text.at(i);
        else if (/*i>1 && i<4 && */ls_text.at(i).count()==2)//ARRL Field Day category 1A-9F  t1>="A" and t1<="F"
        {
            QString s0 = ls_text.at(i);
            int t1 = (int)s0.at(1).toLatin1();
            int dg = s0.midRef(0,1).toInt();
            if (t1>=(int)'A' && t1<=(int)'F' && dg>=1 && dg<=9)//(int)s0.at(0).toLatin1()>0
                arrl_exch_imsg = s0;
        }
        else if (ls_text.at(i).count()==4)//RU DX SN 0001-0999
        {
            int rptsn = ls_text.at(i).toInt();
            if (rptsn>=1 && rptsn<=999)
                sn_inmsg = ls_text.at(i);
        }
        /*else if (ls_text.at(i)=="DE" && myCall_inmsg.isEmpty())//exeption DE SP9HWY/QRP R-09 and DE SP9HWY/QRP 73
             myCall_inmsg = list_macros.at(0);*/
    }

    //2.13 exeprion call_as_grig PA70, PA70X, PA70XX
    if (pos_loc_call_as_grig==1)//2.14 exeption fox to me as 1 call msg
    {
        if (theirLoc_inmsg!="RR73")
        {
            theirCall_inmsg = theirLoc_inmsg;
            theirLoc_inmsg = "";
        }
    }
    else if (pos_loc_call_as_grig==0)//2.14 exeption fox to me as 1 call msg
    {
        if (theirLoc_inmsg!="RR73")
        {
            if (FindBaseFullCallRemAllSlash(theirLoc_inmsg)==s_my_base_call)
                myCall_inmsg = theirLoc_inmsg;
            theirLoc_inmsg = "";
        }
    }
    //2.13 END exeprion call_as_grig PA70, PA70X, PA70XX

    //1.73 exeption DE SP9HWY/QRP R-09 and DE SP9HWY/QRP 73
    if (row_queue==-1)// -1=ident find mam   -2=no find mam
    {
        QString their_base_call = FindBaseFullCallRemAllSlash(theirCall_inmsg);
        row_queue = LsQueue->FindCallOrBaseCallRow(their_base_call);
        row_now   = LsNow->FindCallOrBaseCallRow(their_base_call);
        //qDebug()<<"MAMP== FIND"<<theirCall_inmsg<<row_queue<<row_now;
    }
    if (ls_text.at(0)=="DE" && myCall_inmsg.isEmpty() && !theirCall_inmsg.isEmpty())
    {
        if (row_queue==-2)// -1=ident find mam   -2=no find mam
        {
            if (FindBaseFullCallRemAllSlash(theirCall_inmsg)==FindBaseFullCallRemAllSlash(theirCallFromLe))
                myCall_inmsg = list_macros.at(0);
            //qDebug()<<"NORM== exeption DE SP9HWY/QRP R-09 and DE SP9HWY/QRP 73";
        }
        else if (row_queue>-1 || row_now>-1)
        {
            myCall_inmsg = list_macros.at(0);
            //qDebug()<<"MAMP== exeption DE SP9HWY/QRP R-09 and DE SP9HWY/QRP 73";
        }
    }
    //qDebug()<<"EEE xeption DE SP9HWY/QRP R-09 and DE SP9HWY/QRP 73"<<row_queue<<row_now;
    //end 1.73 exeption DE SP9HWY/QRP R-09 and DE SP9HWY/QRP 73

    //qDebug()<<"1111="<<rpt_inmsg<<str<<myCall_inmsg<<theirCall_inmsg;
    QString trpt = ls_text.at(ls_text.count()-1);
    if (theirLoc_inmsg.isEmpty() && trpt!=theirCall_inmsg && trpt!=myCall_inmsg && !some_digits)// && //1.70 for slash only calls
        //rpt_inmsg.isEmpty())// 2.01
    {
        // rpt= +12,-12,R+12,R-12,R26,26,73,RRR ,599,59    no from here -> RR73, from valid locator
        bool arrl_sec = false;
        if (trpt!="RRR" && trpt!="73" && trpt.count()>1 && trpt.count()<4)
        {
            arrl_sec = true;
            for (int j = 0; j < trpt.count(); ++j)
            {
                if (trpt.at(j).isDigit())
                {
                    arrl_sec = false;
                    break;
                }
            }
            if (arrl_sec)//arrl cection
            {
                if (arrl_exch_imsg.isEmpty())//arrl cection Roundup
                    arrl_exch_imsg = trpt;
                else
                    arrl_exch_imsg.append(" "+trpt);//arrl cection Field Day
            }
        }
        if (!arrl_sec && rpt_inmsg.isEmpty())
            rpt_inmsg = trpt;
    }

    if (!theirLoc_inmsg.isEmpty() && theirLoc_inmsg=="RR73")                    //1.54=RR73
    {
        rr73_inmsg = theirLoc_inmsg;
        theirLoc_inmsg = "";
    }
    if (s_mode==11 || s_mode==0 || s_mode==13 || allq65)//ft4 ft8+msk144 + fox exeption for call no exist and v2 non-standard calls
    {
        //"TA2NC RR73 SP9HWY <...> +00"
        //<...> LZ2HV +00    v2 exception
        //LZ33MM <...> +00   v2 exception
        if (is_fox_msg_for_me_as2call_ft8)
        {
            rpt_inmsg = ls_text.at(ls_text.count()-1);
            rr73_inmsg = "";//rpt no for me
        }
        if (theirCall_inmsg=="...")//big exeption for fox msg 1.69
            theirCall_inmsg="";
    }
    /*qDebug()<<"theirCall="<<theirCall_inmsg<<"theirLoc="<<theirLoc_inmsg<<"myCall="<<myCall_inmsg<<
    "rpt="<<rpt_inmsg<<"contest_mode="<<cont_r_inmsg<<"rr73="<<rr73_inmsg<<"sn_inmsg="<<sn_inmsg<<
    "arrl_exch_imsg="<<arrl_exch_imsg; */
}
QString MultiAnswerModW::format_rpt_ma(QString s)
{
    QString ss;
    if (s_mode == 0 || s_mode == 11 || s_mode==13 || allq65)//msk144 ft8 ft4
    {
        if (f_multi_answer_mod_std && s_co_type==3)////52-59 for  v2
        {
            if (s[0].toLatin1()=='-' || s[0].toLatin1()=='+')
                ss="59";
            else
                ss=s;
        }
        else if (f_multi_answer_mod_std && s_co_type==5)//529-599
        {
            if (s[0].toLatin1()=='-' || s[0].toLatin1()=='+')
                ss="599";
            else
                ss=s;
        }
        else
        {
            if (s[0].toLatin1()!='-' && s[0].toLatin1()!='+')
            {
                s="+"+s;
            }
            if (s.toInt()==0)
                s.replace('-','+');
            ss=s[0];
            ss.append(QString("%1").arg(abs(s.toInt()),2,10,QChar('0')));
        }
    }
    else
        ss=s;
    return ss;
}
void MultiAnswerModW::SetDistUnit(bool f_)
{
    f_km_mi = f_;
}
QString MultiAnswerModW::CalcDistance(QString h, bool fkmmi)
{
    QString dist;
    QString c_test_loc = THvQthLoc.CorrectLocator(h);
    QString c_my_loc = THvQthLoc.CorrectLocator(list_macros.at(1));
    double dlong1 = THvQthLoc.getLon(c_my_loc);
    double dlat1  = THvQthLoc.getLat(c_my_loc);
    double dlong2 = THvQthLoc.getLon(c_test_loc);
    double dlat2 = THvQthLoc.getLat(c_test_loc);
    int dist_km = THvQthLoc.getDistanceKilometres(dlong1,dlat1,dlong2,dlat2);
    if (!fkmmi) dist = QString("%1").arg(dist_km,5,10,QChar(' '));//for sorting
    else dist = QString("%1").arg(THvQthLoc.getDistanceMilles(dlong1,dlat1,dlong2,dlat2),4,10,QChar(' '));//for sorting
    return dist;
}
bool MultiAnswerModW::isStandardCall(QString w)
{
    //static QRegularExpression standard_call_re {
    //  R"(
    //      ^\s*				# optional leading spaces
    //      ( [A-Z]{0,2} | [A-Z][0-9] | [0-9][A-Z] )  # part 1
    //      ( [0-9][A-Z]{0,3} )                       # part 2
    //      (/R | /P)?			# optional suffix
    //      \s*$				# optional trailing spaces
    //  )", QRegularExpression::CaseInsensitiveOption | QRegularExpression::ExtendedPatternSyntaxOption};
    //return standard_call_re.match (w).hasMatch ();
    QRegExp rx("^\\s*([A-Z]{0,2}|[A-Z][0-9]|[0-9][A-Z])([0-9][A-Z]{0,3})(/R|/P)?\\s*$");
    rx.setCaseSensitivity(Qt::CaseInsensitive);
    bool res0 = rx.exactMatch(w); //qDebug()<<w<<res0;
    return res0;
    //return pomAll.isStandardCall(w);
}
void MultiAnswerModW::isStandardCalls(QString c1,QString c2,bool &fc1,bool &fc2,bool &noQSO)
{
    fc1 = isStandardCall(c1);
    fc2 = isStandardCall(c2); //qDebug()<<"MyC="<<fc1<<c1<<"TheirC="<<fc2<<c2;
    noQSO = false;
    if (s_co_type==0)
    {
        int c1c = c1.count();
        int c2c = c2.count();
        QString c1end = c1.mid(c1c-2,2);
        QString c2end = c2.mid(c2c-2,2);
        if (fc1 && fc2)// lz2hv/r  (lz2020hv lz2hv/p)
        {
            if ((c1end=="/P" && c2end=="/R") || (c1end=="/R" && c2end=="/P"))
            {
                fc1 = false;
                fc2 = false;
            }
        }
        else if (fc1 && !fc2)// LZ2HV LZ2HV/P  NOSTD->  LZ2HV/QRP LZ2020HV LZ2020HV/P
        {
            // R5WM/R LZ2HV/QRP
            // R5WM/R LZ2222HV
            // R5WM LZ2HV/QRP
            if (c1end=="/P" || c1end=="/R")
            {
                QString bc2 = FindBaseFullCallRemAllSlash(c2);
                if (!isStandardCall(bc2))
                    noQSO = true;
                else
                    fc1 = false;
            }
        }
        else if (!fc1 && fc2)
        {
            // LZ2HV/QRP R5WM/R
            // LZ2222HV  R5WM/R
            // LZ2HV/QRP R5WM
            if (c2end=="/P" || c2end=="/R")
            {
                QString bc1 = FindBaseFullCallRemAllSlash(c1);
                if (!isStandardCall(bc1))
                    noQSO = true;
                else
                    fc2 = false;
            }
        }
        else if (!fc1 && !fc2)// NOSTD->  LZ2HV/QRP LZ2020HV LZ2020HV/P
        {
            QString bc1 = FindBaseFullCallRemAllSlash(c1);
            QString bc2 = FindBaseFullCallRemAllSlash(c2);
            if (isStandardCall(bc1) && isStandardCall(bc2))
                noQSO = false;
            else
                noQSO = true;
        }
    }
    else
    {
        // if (!fc1 && !fc2) // for contests no use new logic eventual exception  //2.39 old EU VHF
        if (!fc1 && !fc2 && s_co_type!=3) //2.39 for new EU VHF
            noQSO = true;
    }
    /*
    // variant 1
    if((s_id_con==4 || s_id_con==5) && (s_mode==0 || s_mode==11 || s_mode == 13))
    {
    if (c1end=="/P" || c1end=="/R")
    fc1 = false;
    if (c2end=="/P" || c2end=="/R")	
    fc2 = false;
    }    
    else if ((c1end=="/P" && c2end=="/R") || (c1end=="/R" && c2end=="/P"))
    // end variant 1
    */
    //qDebug()<<"isStdMy="<<fc1<<"IsStdTheir="<<fc2<<"BlockQSO="<<noQSO;
}
void MultiAnswerModW::SetTxSnV2(int v)
{
    s_txsn_v2 = v;
    //qDebug()<<"s_txsn_v2"<<s_txsn_v2;
}
QString MultiAnswerModW::DecodeMacros(int row, QString id)//row from listNow id msg id
{
    //"Call"<<"dB"<<"Rx dB"<<"Dist"<<"Grid"<<"Freq"<<"Time"<<"IDrpt"<<"TTry"<<"GinTxT";
    int tx_id = id.toInt();
    QString str_out = str_macros_mam_[tx_id];
    //V2
    //9 click to someone else             %H %M %G4   //2.22
    //0 SP9HWY LZ2HV +00                  %H %M %R
    //1 SP9HWY LZ2HV R+00                 %H %M R%R   5b4aif
    //2 SP9HWY LZ2HV RR73                 %H %M RR73
    //3 "TA2NC RR73;" SP9HWY <LZ2HV> +00
    //4 CQ +??+ LZ2HV KN23				  CQ %M %G4
    QString my_call = list_macros.at(0);
    QString their_call = LsNow->model.item(row,0)->text();
    //bool their_call_is_std = true;//isStandardCall(their_call);
    bool my_call_is_std,their_call_is_std,noQSO;
    isStandardCalls(my_call,their_call,my_call_is_std,their_call_is_std,noQSO);

    if (tx_id==0) //click to someone else
    {
        /*if (!their_call_is_std)
            their_call = "<"+their_call+">";
        else if (!my_call_is_std)
            str_out ="<"+their_call+"> "+my_call;*/
        if (!their_call_is_std && !my_call_is_std && !noQSO)
            str_out ="<"+their_call+"> "+my_call;
        else if (!their_call_is_std)
            their_call = "<"+their_call+">";
        else if (!my_call_is_std)
            str_out ="<"+their_call+"> "+my_call;
    }
    else if (tx_id==1 || tx_id==2) //1=rpt 2=R+rpt
    {
        /*if ((!their_call_is_std && !my_call_is_std) || (!their_call_is_std && my_call_is_std))
            their_call = "<"+their_call+">";
        else if (their_call_is_std && !my_call_is_std)
            my_call  = "<"+my_call+">";*/
        if (s_co_type==3)//2.39
        {
            //their_call = "<"+FindBaseFullCallRemAllSlash(their_call)+">";
            //my_call  = "<"+s_my_base_call+">";
            //2.41 new new EU Contest, no base calls
            their_call = "<"+their_call+">";
            my_call  = "<"+my_call+">";
        }
        else if (!their_call_is_std && !my_call_is_std)
        {
            their_call = "<"+their_call+">";
            if (!noQSO)
                my_call = s_my_base_call;
        }
        else if (!their_call_is_std && my_call_is_std)
            their_call = "<"+their_call+">";
        else if (their_call_is_std && !my_call_is_std)
            my_call  = "<"+my_call+">";
    }
    else if (tx_id==3 || tx_id==4) //3=RR73    id=="4" <- importent need to be here
    {
        QString next_queued = "";
        QString next_queued_tx_id = "";
        if (LsQueue->GetRowCount()>0)
        {
            next_queued = LsQueue->model.item(0,0)->text();
            next_queued_tx_id = LsQueue->model.item(0,7)->text();//2.69       	
       	} //qDebug()<<next_queued<<next_queued_tx_id;
        if (cb_tx_sm->isChecked() && !f_tx_rx && !next_queued.isEmpty() && their_call_is_std && //SBslots->value()>1 &&
                isStandardCall(next_queued) && LsNow->GetRowCount()>=SBslots->value() &&
                (next_queued_tx_id == "1" || next_queued_tx_id == "2")) //not a good idea-> || next_queued_tx_id == "2"
        {
            bool exist = false;
            for (int i = 0; i<5; ++i)
            {
                if (t_list_i3b[i]==their_call)
                {
                    exist = true;
                    break;
                }
            }
            if (!exist)
            {
                t_list_i3b[s_count_nw_i3b]=their_call;
                s_count_nw_i3b++;
                RefreshLists(s_count_nw_i3b);
            }
            int nw_i3b = LsNow->GetRowCount()-s_count_nw_i3b+s_pos_nw_i3b;
            QString rptt = LsNow->model.item(nw_i3b,1)->text();
            if (rptt.isEmpty()) rptt = "-10";//2.69 protection
            str_out = their_call+" RR73; "+LsNow->model.item(nw_i3b,0)->text()+" <"+my_call+"> "+rptt;
            //str_out = their_call+" RR73; "+LsNow->model.item(nw_i3b,0)->text()+" <"+my_call+"> "+LsNow->model.item(nw_i3b,1)->text();
			//qDebug()<<"2="<<s_count_nw_i3b<<LsNow->GetRowCount()<<nw_i3b<<next_queued<<str_out;
            s_pos_nw_i3b++;
        }//else if (LsNow->GetRowCount()-s_count_nw_i3b+s_pos_nw_i3b<LsNow->GetRowCount())
        else if (s_pos_nw_i3b-s_count_nw_i3b<0)
        {
            int nw_i3b = LsNow->GetRowCount()-s_count_nw_i3b+s_pos_nw_i3b;
            QString rptt = LsNow->model.item(nw_i3b,1)->text();
            if (rptt.isEmpty()) rptt = "-10";//2.69 protection
            str_out = their_call+" RR73; "+LsNow->model.item(nw_i3b,0)->text()+" <"+my_call+"> "+rptt;
            //str_out = their_call+" RR73; "+LsNow->model.item(nw_i3b,0)->text()+" <"+my_call+"> "+LsNow->model.item(nw_i3b,1)->text();
			//qDebug()<<"several more"<<s_count_nw_i3b<<LsNow->GetRowCount()<<nw_i3b;
            s_pos_nw_i3b++;
        }
        /*else if (their_call_is_std && s_my_call_is_std)
            res = their_call+" "+s_my_base_call+" RR73";*/
        /*else if (!their_call_is_std && !my_call_is_std)
        {
            their_call = FindBaseFullCallRemAllSlash(their_call);
            my_call = s_my_base_call;
        }
        else if (!their_call_is_std && my_call_is_std)
            my_call  = "<"+my_call+">";
        else if (their_call_is_std && !my_call_is_std)
            their_call  = "<"+their_call+">";*/
        else if (!their_call_is_std && !my_call_is_std)
        {
            if (!noQSO)
                my_call  = "<"+my_call+">";
            else
            {
                their_call = FindBaseFullCallRemAllSlash(their_call);
                my_call = s_my_base_call;
            }
        }
        else if (!their_call_is_std && my_call_is_std)
            my_call  = "<"+my_call+">";
        else if (their_call_is_std && !my_call_is_std)
            their_call  = "<"+their_call+">";

        //gen_in_tx_time->find decoded in tx period,and gen in tx period and no emited yet,important for RR73 removing msgs
        if (LsNow->model.item(row, 9)->text().isEmpty())
            LsNow->SetItem(row,9,gen_in_tx_time);
    }

    str_out.replace(QString("%T"), their_call);
    str_out.replace(QString("%M"), my_call);
    /* ???
    str_out.replace(QString("%H"), DetectSufix(their_call,false));
    str_out.replace(QString("%O"), DetectSufix(my_call,false));
    str_out.replace(QString("%SH"), DetectSufix(their_call,true));
    str_out.replace(QString("%SO"), DetectSufix(my_call,true));
    */
    str_out.replace(QString("%R"), LsNow->model.item(row,1)->text());//my tx rpt
    str_out.replace(QString("%G4"), list_macros.at(1).mid(0,4));//my loc4
    str_out.replace(QString("%G6"), list_macros.at(1));//my loc6
    str_out.replace(QString("%N"), QString("%1").arg(s_txsn_v2,4,10,QChar('0')));//new s 0001

    //qDebug()<<"2222_V"<<res<<their_call<<their_call_is_std<<my_call<<my_call_is_std;
    return str_out;
}
void MultiAnswerModW::SetAuto(bool f) //2.35
{
    f_auto_on = f;
}
void MultiAnswerModW::gen_msg()
{
    int rwc = LsNow->GetRowCount() - s_count_nw_i3b;
    if (SBslots->value()==1 && rwc>1) rwc = 1;//2.69 ? protection for exeption 1-slot but emitting 2 
    if (rwc>5) rwc = 5;//2.69 protection never emit more than 5 slots 
    QString prev_current_msg = current_msg; //qDebug()<<SBslots->value();
    current_msg = "";
    s_pos_nw_i3b = 0;

    if (rwc<=0)//start cq
    {
        if (!g_block_stop_auto && f_multi_answer_mod_std && !cb_cont_ns->isChecked())//2.52 ->!g_block_stop_auto eventual->!f_tx_rx &&
            emit EmitStopAuto(); // from set_macros stop auto and clar lists
        if (f_block_free_cq)
        {
            QString Myloc4 = list_macros.at(1).mid(0,4);
            current_msg = "CQ "+list_macros.at(0)+" "+Myloc4;
        }
        else 
			current_msg = LeFreeCQ->text();
        emit EmitQSOProgressMAM(5,true);//2.51
    }
    else
    {
        for (int i = 0; i < rwc; ++i)
        {
            current_msg.append(DecodeMacros(i,LsNow->model.item(i,7)->text()));
            if (i<rwc-1) current_msg.append("#");
            if (i==0) // only first  "Call"<<"dB"<<"Rx dB"<<"Dist"<<"Grid"<<"Freq"<<"Time"<<"IDrpt"<<"TTry"<<"GinTxT";
                emit EmitDxParm(LsNow->model.item(i,0)->text(),LsNow->model.item(i,1)->text(),LsNow->model.item(i,4)->text());
        }
        if (cb_tx_cq_on_free_slot->isChecked() && rwc < 2 && rwc < SBslots->value())//add cq if have place and only one candidat in LsNow
        {
            current_msg.append("#");
            //QString Myloc4 = list_macros.at(1).mid(0,4);
            if (f_block_free_cq)
            {
                QString Myloc4 = list_macros.at(1).mid(0,4);
                current_msg.append("CQ "+list_macros.at(0)+" "+Myloc4);
            }
            else
                current_msg.append(LeFreeCQ->text());
        }
        int identif = LsNow->model.item(0,7)->text().toInt();//2.51
        emit EmitQSOProgressMAM(identif,true);//2.51
    }

    //V1
    //0 SP9HWY LZ2HV +00                  %H %M %R
    //1 SP9HWY LZ2HV R+00                 %H %M R%R   5b4aif
    //2 SP9HWY LZ2HV RR73                 %H %M RR73
    //3 "TA2NC RR73;" SP9HWY <LZ2HV> +00
    //4 CQ +??+ LZ2HV KN23				  CQ %M %G4
    if (prev_current_msg != current_msg)//2.35
    {
        if ((s_mode==11 || s_mode==13 || allq65) && f_auto_on && SBslots->value()==1)//2.59 +ft4 f_tx_rx &&
            emit MamEmitMessage(current_msg,false,true,true);
        else
            emit MamEmitMessage(current_msg,false,false,true);
    }
}
void MultiAnswerModW::CbTxCqOnFreeSlotChanged(bool)
{
    //if (LsNow->GetRowCount()>1)//need to upd CQ on free slot
    if (SBslots->value()>1)//need to upd CQ on free slot`1
        gen_msg();
}
void MultiAnswerModW::GetCurrentMsg()
{
    emit MamEmitMessage(current_msg,false,false,true);
}
void MultiAnswerModW::SBslotsValueChanged(int)
{
    RefreshLists(0);
}
int MultiAnswerModW::FindCallBackupDB(QString call)
{
    int res = -1;
    if (call.isEmpty()) return res;

    for (int i = 0; i<MAXB_DB; ++i)
    {
        if (backup_db_[i][0] == call)
        {
            res = i;
            break;
        }
    }
    return res;
}
void MultiAnswerModW::SetBackupDB(QString call,QString txr,QString rxr,QString g,QString s,QString e)
{
    //"Call"<<"Tx dB"<<"Rx dB"<<"Dist"<<"Grid"<<"Freq"<<"Time"<<"IDrpt"<<"TTry"<<"GinTxT"<<"s"<<"e";
    //"Call"<<"Tx dB"<<"Rx dB"        <<"Grid"                                           <<"s"<<"e";
    //"Call"=0
    //"Tx dB"=1
    //"Rx dB"=2
    //"Grid"=3
    //"s"=4
    //"e"=5
    if (call.isEmpty()) return;
    if (s_mode == 0 || s_mode == 11 || s_mode == 13 || allq65)
    {
        if (txr.isEmpty() && rxr.isEmpty() && g.isEmpty() && s.isEmpty() && e.isEmpty()) return;
    }
    else
    {
        if (g.isEmpty()) return;
    }

    int pos_c = FindCallBackupDB(call);
    if (!s.isEmpty())
    {
        int sn = s.toInt();
        s = QString("%1").arg(sn);
    }
    if (pos_c != -1)
    {		// existing call
        if (!g.isEmpty()) backup_db_[pos_c][3] = g;
        if (s_mode == 0 || s_mode == 11 || s_mode == 13 || allq65)
        {
            if (!txr.isEmpty()) backup_db_[pos_c][1] = txr;
            if (!rxr.isEmpty()) backup_db_[pos_c][2] = rxr;
            if (!s.isEmpty())   backup_db_[pos_c][4] = s;
            if (!e.isEmpty())   backup_db_[pos_c][5] = e;
        }
    }
    else
    {		// new call
        backup_db_[backup_db_pos_write][0] = call;
        backup_db_[backup_db_pos_write][3] = g;
        if (s_mode == 0 || s_mode == 11 || s_mode == 13 || allq65)
        {
            backup_db_[backup_db_pos_write][1] = txr;
            backup_db_[backup_db_pos_write][2] = rxr;
            backup_db_[backup_db_pos_write][4] = s;
            backup_db_[backup_db_pos_write][5] = e;
        }
        else
        {   //overwrite some existing call (reset)
            backup_db_[backup_db_pos_write][1] = "";
            backup_db_[backup_db_pos_write][2] = "";
            backup_db_[backup_db_pos_write][4] = "";
            backup_db_[backup_db_pos_write][5] = "";
        }
        backup_db_pos_write++;
        if (backup_db_pos_write > (MAXB_DB-1))
            backup_db_pos_write = 0;
    }

    /*for (int i = 0; i<MAXB_DB; ++i)
    {
        QString sss;
        for (int j = 0; j<6; ++j)
        {
            if (j==0)
                sss.append(" "+backup_db_[i][j].leftJustified(10,' '));
            else if (j==3)
                sss.append(" "+backup_db_[i][j].leftJustified(6,' '));
            else
                sss.append(" "+backup_db_[i][j].leftJustified(4,' '));
            if (j<5)sss.append("|");
        }
        qDebug()<<sss;
    }
    qDebug()<<"---------------------------------------------";*/
}
void MultiAnswerModW::GetBackupDB(int pos,QString &txr,QString &rxr,QString &g,QString &s,QString &e)
{
    g = backup_db_[pos][3];
    if (s_mode == 0 || s_mode == 11 || s_mode == 13 || allq65)
    {
        txr = backup_db_[pos][1];
        rxr = backup_db_[pos][2];
        s   = backup_db_[pos][4];
        e   = backup_db_[pos][5];
    }
    else
    {
        txr = "";
        rxr = "";
        s   = "";
        e   = "";
    }
}
void MultiAnswerModW::ClrQueue()
{
    LsQueue->Clear_List();
}
void MultiAnswerModW::RefreshBackupDbAll()//2.59
{
    for (int i = LsNow->model.rowCount()-1; i >= 0; --i)
    {
        SetBackupDB(LsNow->model.item(i,0)->text(),
                    LsNow->model.item(i,1)->text(),
                    LsNow->model.item(i,2)->text(),
                    LsNow->model.item(i,4)->text(),
                    LsNow->model.item(i,10)->text(),
                    LsNow->model.item(i,11)->text());
    }
}
void MultiAnswerModW::ClrNow()
{
    RefreshBackupDbAll();
    LsNow->Clear_List();
    if (LsQueue->GetRowCount()<=0)//need to upd CQ
        gen_msg();
    else
        RefreshLists(0);
}
void MultiAnswerModW::ClrNowUserDoubleClick()
{
    RefreshBackupDbAll();
    LsNow->Clear_List();
}
void MultiAnswerModW::BlockFrreCq(bool f)
{
    f_block_free_cq = f;

    if (f_block_free_cq)
    {
        if (dsty)
        {
            LeFreeCQ->setStyleSheet("QLineEdit {background-color :rgb(55, 55, 55);color: rgb(255, 200, 0)}");
            pb_use_free_cq->setStyleSheet("QPushButton {color: rgb(255, 200, 0)}");
        }
        else
        {
            LeFreeCQ->setStyleSheet("QLineEdit {background-color :"+ColorStr_[3]+";color: "+ColorStr_[1]+"}");
            pb_use_free_cq->setStyleSheet("QPushButton {color: "+ColorStr_[1]+"}");
        }
    }
    else
    {
        LeFreeCQ->setStyleSheet("QLineEdit {background-color :palette(Base);}");
        pb_use_free_cq->setStyleSheet("QPushButton{background-color :palette(Button);}");
    }
}
void MultiAnswerModW::SetStartFromTx2Tx1(bool f)
{
    s_start_qso_from_tx2 = f;
}
void MultiAnswerModW::ConfigRestrictW()
{
    if (f_multi_answer_mod_std)//(s_mode==11 || s_mode==13) &&
    {
        if (gg_frest || allq65) SBslots->setRange(1,1);
        else
        {
            if (s_co_type==0) SBslots->setRange(1,2);
            else SBslots->setRange(1,1);//<- importent eu vhf only 1 slot needed
        }
        if (cb_tx_sm->isChecked()) cb_tx_sm->setChecked(false);
        cb_tx_sm->setHidden(true);
        cb_cont_ns->setHidden(false);
    }
    else
    {
        if (gg_frest || allq65) SBslots->setRange(1,1);
        else
        {
            if (s_mode==13) SBslots->setRange(1,3);
            else SBslots->setRange(1,5);
        }
        cb_cont_ns->setHidden(true);
        cb_tx_sm->setHidden(false);
    }
    if (SBslots->maximum()==1) SBslots->setEnabled(false);
    else SBslots->setEnabled(true);
}
void MultiAnswerModW::RefreshLRestrict_pub(bool f)
{
    gg_frest = f;
    if (f)
    {
        bool f_msg = false;
        if (SBslots->value()>1) f_msg = true;
        ConfigRestrictW();
        if (f_msg && !isHidden())
        {
            QMessageBox msgBox(this);
            msgBox.setWindowTitle("MSHV");
            msgBox.setIcon(QMessageBox::Information);
            msgBox.setText(tr("In Settings MA, TX Slots: It Is Set To ONE.\n"
                              "Please choose another dial frequency.\n"
                              "MSHV will not operate on more than one slot\n"
                              "in the standard FT8 and FT4 HF sub-bands."));
            msgBox.setStandardButtons(QMessageBox::Ok);
            msgBox.button(QMessageBox::Ok)->animateClick(10000);//after 15sec auto close
            msgBox.button(QMessageBox::Ok)->setFixedWidth(85);
            msgBox.exec();
        }
    }
    else ConfigRestrictW();
}
void MultiAnswerModW::RefreshLRestrict()//2.23
{
    if (s_mode==11 || s_mode==13 || allq65)//clr for ft8 ft4
    {
        ClrQueue();
        ClrNow();
        ConfigRestrictW();
        s_last_bccall_tolog_excp = "_NONE_";//reset
    }
}
void MultiAnswerModW::SetMAStd(bool f)
{
    f_multi_answer_mod_std = f;  //qDebug()<<f_multi_answer_mod_std<<cb_cont_ns->isChecked();
    RefreshLRestrict();
    CbCQChanged("");
}
void MultiAnswerModW::SetBand()//for reset
{
    RefreshLRestrict();
}
void MultiAnswerModW::SetMode(int m)
{
    if (m == 14 || m == 15 || m == 16 || m == 17) allq65 = true;
    else allq65 = false;
    s_mode = m;
    RefreshLRestrict();
}
void MultiAnswerModW::SetMacros(QStringList listm,int id_c0,int type_c0)
{
    //2.65 if Makros and RadioAndNet is closed and no changes
    //2.65 problem is if I TXing msg will be resetted
    if (list_macros==listm && s_co_type==type_c0 && s_co_id==id_c0) return;

    g_block_stop_auto = true;//2.52
    s_co_type = type_c0;
    s_co_id = id_c0;
    RefreshLRestrict();
    list_macros = listm; //qDebug()<<list_macros;

    QString my_c = list_macros.at(0);
    s_my_base_call = FindBaseFullCallRemAllSlash(my_c);
    //s_my_call_is_std = true;//isStandardCall(my_c);
    if (my_c.contains("/"))
    {
        my_call_have_slash = true;
    }
    else
    {
        //list_macros.replace(0, my_c.mid(0,6));//2.00 strip to 6char
        my_call_have_slash = false;
    }//qDebug()<<"TX RX ====="<<s_my_base_call<<my_call_have_slash;

    CbCQChanged("");
    BlockFrreCq(false);
    gen_msg();
    g_block_stop_auto = false;//2.52
}
void MultiAnswerModW::SetQRG(QString s)
{
    if (s.isEmpty() || s.at(0).isLetter() || s.at(1).isLetter() || s.at(2).isLetter())
        s_qrg = s;
    else
        s_qrg = QString("%1").arg(s.toInt(),3,10,QChar('0'));

    CbCQChanged("");
}
void MultiAnswerModW::CbCQChanged(QString)
{
    if (s_co_type > 0 && f_multi_answer_mod_std)
    {
        /*str_macros_mam_[0]=list_macros.at(2);
        str_macros_mam_[1]=list_macros.at(3);
        str_macros_mam_[2]=list_macros.at(4);
        str_macros_mam_[3]="%T %M RR73";
        str_macros_mam_[4]=list_macros.at(6);
        str_macros_mam_[5]=list_macros.at(7);*/
        for (int i = 0; i <6; ++i)
        {
            if (i==3) str_macros_mam_[i]="%T %M RR73";
            else
            {	//2.66 protection from sufix Macros
                QString s = list_macros.at(i+2);
                s.replace(QString("%H"),"%T");
                s.replace(QString("%O"),"%M");
                s.replace(QString("%SH"),"%T");
                s.replace(QString("%SO"),"%M");
                str_macros_mam_[i]=s;
            }
        }
    }
    else
    {
        str_macros_mam_[0]="%T %M %G4";//2.47
        str_macros_mam_[1]="%T %M %R";
        str_macros_mam_[2]="%T %M R%R";
        str_macros_mam_[3]="%T %M RR73";
        str_macros_mam_[4]="%T %M RR73";
        str_macros_mam_[5]="CQ %M %G4";
    }
    //qDebug()<<list_macros[2]<<list_macros[3]<<list_macros[4]<<list_macros[5]<<list_macros[6]<<list_macros[7]<<list_macros.count();
    //qDebug()<<str_macros_mam_[0]<<str_macros_mam_[1]<<str_macros_mam_[2]<<str_macros_mam_[3]<<str_macros_mam_[4]<<str_macros_mam_[5];

    if (s_co_type == 0 || !f_multi_answer_mod_std)//2.34 no problem remove this -> s_id_con == 0 ||
    {
    	Cbcqtype->setItemText(0,"CQ");
   	}
    else
    { 
        //QString Myloc4 = list_macros.at(1).mid(0,4);
        QString cqq = str_macros_mam_[5];
        int mci = cqq.indexOf(" %M"); // my call
        if (cqq.mid(0,3)=="CQ " && mci > 3 && mci < 8)
        {
            bool islet = true;
            for (int i = 3; i < mci; ++i)
            {
                if (!cqq.at(i).isLetter()) islet = false;
            }
            if (islet) cqq = cqq.mid(0,mci);
            else cqq = "CQ";
        }
        else cqq = "CQ";

        Cbcqtype->setItemText(0,cqq);  
    }

    QString sc = Cbcqtype->currentText();
    QString sr = Cbcqtype->itemText(0);//reset
    if (sc=="Free Msg")
    {
        LeFreeCQ->setEnabled(true);
        pb_use_free_cq->setEnabled(true);
        if (LeFreeCQ->text()=="PSE SYNC TIME")
        {
            QString Myloc4 = list_macros.at(1).mid(0,4);
            LeFreeCQ->setText(sr+" "+list_macros.at(0)+" "+Myloc4);//reset
            BlockFrreCq(false);
        }
    }
    else
    {
        LeFreeCQ->setEnabled(false);
        pb_use_free_cq->setEnabled(false);
        QString Myloc4 = list_macros.at(1).mid(0,4);

        if (sc=="TIME")
            LeFreeCQ->setText("PSE SYNC TIME");
        else if (!isStandardCall(list_macros.at(0))) //else if (!s_my_call_is_std)
            LeFreeCQ->setText("CQ "+list_macros.at(0));
        else
        {
            sc.replace(QString("QRG"),s_qrg);//2.33
            LeFreeCQ->setText(sc+" "+list_macros.at(0)+" "+Myloc4);
        }
    }
    //ok Cbcqtype->clearFocus(); //ok->Qt::NoFocus if cq box noting happend Ctrl+` kyboard shortcut
    //setFocus();//if cq box noting happend Ctrl+` kyboard shortcut
}
void MultiAnswerModW::LeFreeCQtextChanged(QString)
{
    if (Cbcqtype->currentText()=="Free Msg")
        BlockFrreCq(true);
    else
        BlockFrreCq(false);

    if (LsNow->GetRowCount()<=0)//need to upd CQ
        gen_msg();
}
QString MultiAnswerModW::RemWSpacesInsideAndBegEnd(QString str)
{
    QString s;
    //int msg_count = 0;
    //RemWSpacesInside
    for (int i = 0; i<str.count(); i++)
        str.replace("  "," ");
    //RemBegEndWSpaces //2.64 stop
    /*for (msg_count = str.count()-1; msg_count>=0; msg_count--)
    {
        if (str.at(msg_count)!=' ')
            break;
    }
    s = str.mid(0,msg_count+1);
    msg_count = 0;
    for (msg_count = 0; msg_count<s.count(); msg_count++)
    {
        if (s.at(msg_count)!=' ')
            break;
    }
    s = s.mid(msg_count,(s.count()-msg_count));*/
    s = str.trimmed();
    return s;
}
/*bool MultiAnswerModW::IsMsgHaveValidCall(QString s)
{
    QStringList	msg = s.split(" ");
    bool loc_once = false;
    for (int i = msg.count()-1; i >= 0; --i)
    {
        if (!loc_once && THvQthLoc.isValidLocator(msg.at(i)))
        {
            loc_once = true;
        }
        else if (THvQthLoc.isValidCallsign(msg.at(i)))
            return true;
    }

    return false;
}*/
void MultiAnswerModW::UseFreeCq()
{
    /*if (!IsMsgHaveValidCall(LeFreeCQ->text()))//no emit empty text
    {
        QString text = "Message does not contains with valid call sign";
        QMessageBox::critical(this, "  Warning  ", text, QMessageBox::Ok);
        return;
    }*/

    QString str = LeFreeCQ->text();
    str = RemWSpacesInsideAndBegEnd(str);
    LeFreeCQ->setText(str);

    BlockFrreCq(false);
    if (LsNow->GetRowCount()<=0)//need to upd CQ
        gen_msg();
}
void MultiAnswerModW::SetTxRxMsg(bool f)
{
    f_tx_rx = f;
    if (f)
    {
        gen_in_tx_time = "1";//1 tx 0 rx
        bool is_change = false;
        unsigned int ttry_now = QDateTime::currentDateTimeUtc().toTime_t();
        for (int i = LsNow->GetRowCount()-1; i >=0; --i)
        {
            unsigned int ttry = LsNow->model.item(i,8)->text().toUInt();
            /*bool res = false;
            if (!SBmaxTP->GetMTP()) res = (ttry_now-ttry)>=(unsigned int)SBmaxTP->value()*60;
            else res = (ttry_now-ttry)>=(unsigned int)((period_time_sec*2.0)*(float)SBmaxTP->value());
            if (res)*/
            unsigned int res = 0;	
            if (!SBmaxTP->GetMTP()) res = (unsigned int)SBmaxTP->value()*60;
            else res = (unsigned int)((period_time_sec*2.0)*(float)SBmaxTP->value());
            if ((ttry_now-ttry)>=res)	            	
            {
                SetBackupDB(LsNow->model.item(i,0)->text(),
                            LsNow->model.item(i,1)->text(),
                            LsNow->model.item(i,2)->text(),
                            LsNow->model.item(i,4)->text(),
                            LsNow->model.item(i,10)->text(),
                            LsNow->model.item(i,11)->text());
                LsNow->RemoveRow(i);
                is_change = true;
            }
        }
        if (is_change) RefreshLists(0);
    }
    else
    {
        gen_in_tx_time = "0";
        SetTxMsgEnd();
    }
}
void MultiAnswerModW::SetLastBcCallToLog(QString call)
{
    s_last_bccall_tolog_excp = call;
}
void MultiAnswerModW::SetTxMsgEnd()
{
    bool is_change = false;
    
	//qDebug()<<"TXing END====="<<f_tx_rx<<f_cfm73;
    //if (!f_tx_rx)//2.69 ???
    //{
    s_count_nw_i3b = 0;
    for (int i = 0; i <5; ++i) t_list_i3b[i]="";    	
   	//}

    for (int i = LsNow->GetRowCount()-1; i >=0; --i)
    {
        QString id_rpt = LsNow->model.item(i,7)->text();
        QString g_tx_t = LsNow->model.item(i,9)->text();
        //QString wait_for = "3";
        //if (f_multi_answer_mod_std) wait_for = "4";//old
        //if (id_rpt==wait_for && g_tx_t=="0")
        //qDebug()<<id_rpt<<g_tx_t<<s_last_bccall_tolog_excp;
        if (id_rpt=="3" && g_tx_t=="0")
        {
            //gen_in_tx_time->find decoded in tx period,and gen in tx period and no emited yet,important for RR73 removing msgs
            //log_data_start & log_time_start, their_call, their_loc, rst_tx,  rst_rx
            //"Call"<<"dB"<<"Rx dB"<<"Dist"<<"Grid"<<"Freq"<<"Time"<<"IDrpt"<<"TTry"<<"GinTxT"
            QString comm = "MADX QSO";
            QString cont_id = "0";
            QString rxsn = "";
            QString rxex = "";
            bool f_addtolog = true;
            if (f_multi_answer_mod_std)
            {
                QString theirBaseCall_inmsg = FindBaseFullCallRemAllSlash(LsNow->model.item(i,0)->text());
                if (theirBaseCall_inmsg == s_last_bccall_tolog_excp) f_addtolog = false;
                if (f_addtolog)
                {
                    //s_last_bccall_tolog_excp = theirBaseCall_inmsg;
                    comm = "MASTD QSO";
                    if (s_co_type>1)
                    {
                        //All=2 and up
                        comm = s_cont_name[s_co_id];
                        cont_id = QString("%1").arg(s_co_id);
                        if (s_co_type==3)
                        {
                            QString s = LsNow->model.item(i,10)->text();
                            if (!s.isEmpty())
                            {
                                int sn = s.toInt();
                                rxsn = QString("%1").arg(sn);
                            }
                        }
                        else if (s_co_type==4)
                        {
                            rxex = LsNow->model.item(i,11)->text();
                        }
                        else if (s_co_type==5)
                        {
                            rxex = LsNow->model.item(i,11)->text();
                            QString s = LsNow->model.item(i,10)->text();
                            if (!s.isEmpty())
                            {
                                int sn = s.toInt();
                                rxsn = QString("%1").arg(sn);
                            }
                        }
                    }
                }
            }
            if (f_addtolog)
            {
                QStringList l;
                l<<LsNow->model.item(i,6)->text()<<LsNow->model.item(i,0)->text()
                <<LsNow->model.item(i,4)->text()<<LsNow->model.item(i,1)->text()
                <<LsNow->model.item(i,2)->text()
                <<comm<<rxsn<<rxex<<cont_id; //qDebug()<<"AddtoLog"<<LsNow->model.item(i,0)->text();
                emit AddToLog(l);
            }
            LsNow->RemoveRow(i);
            is_change = true;
        }
        //else if (id_rpt==wait_for && g_tx_t=="1")//exeption
        else if (id_rpt=="3" && g_tx_t=="1")//exeption
        {
            //gen_in_tx_time->find decoded in tx period,and gen in tx period and no emited yet,important for RR73 removing msgs
            LsNow->SetItem(i,9,"0");
        }
    }
    if (is_change) RefreshLists(0);
}
void MultiAnswerModW::RefreshLists(int c_plus)
{
    //qDebug()<<"RefreshLists==="<<c_plus<<LsNow->GetRowCount()<<LsQueue->GetRowCount();
    bool is_need_rfresh_lists = true;
    if (LsNow->GetRowCount() >= SBslots->value() + c_plus || LsQueue->GetRowCount()<=0) is_need_rfresh_lists = false;

    if (is_need_rfresh_lists)
    {
        int remc = 0;
        for (int i = 0; i < LsQueue->GetRowCount(); ++i)
        {
            //"Call"<<"dB"<<"Rx dB"<<"Dist"<<"Grid"<<"Freq"<<"Time"<<"IDrpt"<<"TTry"<<"GinTxT";
            QStringList ls;
            for (int j = 0; j < LsQueue->GetColumnCount(); ++j)
                ls << LsQueue->model.item(i,j)->text();

            QDateTime utc_t = QDateTime::currentDateTimeUtc();
            if (ls.at(6).isEmpty())//no start time
            {
                //QDateTime utc_t = QDateTime::currentDateTimeUtc();
                QString d=utc_t.toString("yyyyMMdd");
                QString t=utc_t.toString("hh:mm");
                ls.replace(6,d+" "+t);
            }
            QString ttry = QString("%1").arg(utc_t.toTime_t());//moze +15s
            ls.replace(8,ttry);  //qDebug()<<"ls.replace(8,ttry);"<<ttry;

            LsNow->InsertItem_hv(ls);
            remc++;
            if (LsNow->GetRowCount() >= SBslots->value())
                break;
        }
        LsQueue->RemoveRows(0,remc);

        QStringList lout;//2.00 for hash
        for (int i = 0; i < LsNow->GetRowCount(); ++i)
            lout<<LsNow->model.item(i,0)->text();
        emit EmitMAMCalls(lout);

    }
    if (c_plus == 0) gen_msg();
}
static QString _s00_;
void MultiAnswerModW::SetTextMark(bool b,bool m)
{
    s_txt_mark_b = b;
    s_txt_mark_m = m;
    _s00_ = tr("Filtered By")+": "+tr("Call");
    if (s_txt_mark_b) _s00_.append(", "+tr("Band"));// band
    if (s_txt_mark_m) _s00_.append(", "+tr("Mode"));// mode
    Cb_dupes->setToolTip(tr("Maximum QSOs per Call")+"\n"+_s00_);
}
void MultiAnswerModW::SetInfoDupeQso(bool f)
{
    info_dupe_qso = f;
}
bool MultiAnswerModW::DialogIsCallDupeInLog(QString theirCall_inmsg)
{
    bool res = false;
    bool is_dupe = false;

    emit IsCallDupeInLog(theirCall_inmsg,1,is_dupe);//2.66 (0 or 1)=1-QSO 2=2-QSO 3=3-QSO

    if (is_dupe)
    {
        emit EmitGBlockListExp(true);//2.06
        setFocus(Qt::MouseFocusReason);//?? <-crash in decodelist.cpp bool MyDelegate::eventFilter
        //b_gen_msg->setFocus();//?? <-crash in decodelist.cpp QWidget* bool MyDelegate::eventFilter
        this->setFocus();

        //QString criter = "  Criteria are: By Call"; //Mode "+ModeStr(s_mode)+", Band "+s_band
        /*QString criter = " "+tr("Filtered By")+": "+tr("Call");
        if (s_txt_mark_b) criter.append(", "+tr("Band"));// band
        if (s_txt_mark_m) criter.append(", "+tr("Mode"));// mode*/

        QString text = "<p align='center'>"+tr("QSO Before")+": "+tr("Call")+" "+theirCall_inmsg//+"<br>"
                       +" "+_s00_+"<br>"+tr("Do You Want To Continue QSO?")+"</p>";//ModeStr(s_mode),s_band

        int ret = QMessageBox::warning(this,"  MSHV Log Warning  ",text,QMessageBox::Ok | QMessageBox::Cancel);

        switch (ret)
        {
        case QMessageBox::Cancel:
            res = true;
            break;
        case QMessageBox::Ok:
            res = false;
            break;
        default:
            res = true;
            break;
        }
        emit EmitGBlockListExp(false);//2.06
    }
    return res;
}
void MultiAnswerModW::SetCntestOnlySdtc(bool f)
{
    f_con_only_sdtc = f; //qDebug()<<"f_cntest_only_sdtc="<<f_cntest_only_sdtc;
}
QString MultiAnswerModW::TryFormatRPTtoRST(QString rpt)//2.59
{
    QString rst = rpt;
    if ((s_mode == 0 || s_mode == 11 || s_mode == 13 || allq65) && (s_co_type==3 || s_co_type==5))//ft4  3=52-59 for Contest v2  5=//529-599
    {
        int n = rst.toInt();
        int nn=(n+36)/6;
        if (nn<2) nn=2;
        if (nn>9) nn=9;
        rst = "5"+QString("%1").arg(nn)+"9";
        if (s_co_type==3) rst = rst.mid(0,2);
    }
    return rst;
}
void MultiAnswerModW::SetCfm73(bool f)
{
    f_cfm73 = f; //qDebug()<<"SetCfm73"<<f;
}
void MultiAnswerModW::SetIsLastTxRptCq(bool f)//2.66
{
	is_LastTxRptCq = f;
	if (!is_LastTxRptCq) s_dist_points = -1;//2.66 reset
}
void MultiAnswerModW::SetUseASeqMaxDist(bool f)//2.66
{
	f_aseqmaxdist = f;
}
void MultiAnswerModW::DecListTextAll(QString tx_rpt,QString str,QString freq,bool f_double_click,
                                     QString &their_call_for_ap,QString &their_loc_for_dist)
{
    //QDateTime utc_t = QDateTime::currentDateTimeUtc();
    //s_log_data_start=utc_t.toString("yyyyMMdd");
    //s_log_time_start=utc_t.toString("hh:mm");
    QString theirCall_inmsg = "";
    QString theirLoc_inmsg  = "";
    QString myCall_inmsg  = "";
    QString rpt_inmsg  = "";
    QString cont_r_inmsg  = ""; //msk144 ft8 contest mode R fictive
    QString rr73_inmsg  = "";   ////1.54=RR73 msk144 ft8 rr73
    int row_queue = -1;// -1=ident find mam   -2=no find mam
    int row_now = -1;  // -1=ident find mam   -2=no find mam
    QString sn_inmsg = "";//v.2.0 fictive
    QString arrl_exch_imsg = "";//v.2.01 fictive

    //QString nowcall = "";//inportent only one slot needed     nowcall,//"" <- corr for eu VHF
    //if (f_multi_answer_mod_std && LsNow->GetRowCount()>0)//no problem bez tova-> && s_id_con==3
    //nowcall = LsNow->model.item(0,0)->text();//call
    //qDebug()<<"nowcall"<<f_multi_answer_mod_std<<s_id_con<<LsNow->GetRowCount()<<nowcall;

    DetectTextInMsg(str, theirCall_inmsg,theirLoc_inmsg,myCall_inmsg,rpt_inmsg,cont_r_inmsg,rr73_inmsg,
                    row_queue,row_now,sn_inmsg,arrl_exch_imsg);
    their_call_for_ap = theirCall_inmsg;
    their_loc_for_dist = theirLoc_inmsg;
    //for now and=&&   or=|| if msg=DE SP9HWY/QRP R-15

    if ((!myCall_inmsg.isEmpty() || f_multi_answer_mod_std) && !theirCall_inmsg.isEmpty())//
    {
        bool fc1,fc2,noQSO;
        isStandardCalls(list_macros.at(0),theirCall_inmsg,fc1,fc2,noQSO);
        if (f_multi_answer_mod_std && f_con_only_sdtc)
        {
            if (!fc1 || !fc2) return;
        }
        if (noQSO) return; //two_no_sdtc

        int id_0qe_1nw_2ne = 2;//0=Queue,1=Now,2=New //2.47 moved here
        if (row_queue>-1) id_0qe_1nw_2ne = 0;
        if (row_now  >-1) id_0qe_1nw_2ne = 1;

        //if (cb_no_dupes->isChecked() && id_0qe_1nw_2ne == 2) //2.47 kp4hf problem
        if (Cb_dupes->currentIndex()>0 && id_0qe_1nw_2ne == 2 && (!f_multi_answer_mod_std || !f_double_click))//2.66=?
        {
            bool is_dupe = false;
            emit IsCallDupeInLog(theirCall_inmsg,Cb_dupes->currentIndex(),is_dupe);
            if (is_dupe) return;
        }
        /*if (f_multi_answer_mod_std && info_dupe_qso && f_double_click)//2.66=stop
        {
            if (DialogIsCallDupeInLog(theirCall_inmsg)) return;
        }*/

        ////////// ORG only for MSK, FT8/4 and not for contests and MA ///////////////////
        /*QStringList lstr = str.split(" "); //for the future restrict QRG as message
        if (lstr.count() > 2) //CQ 236 LZ2HV
        {
            QString s = lstr.at(1);
            if (s.count()<4 && lstr.at(0)=="CQ")// only kHz 236
            {
                bool alldig = true;
                for (int j = 0; j < s.count(); ++j)
                {
                    if (s.at(j).isLetter())
                    {
                        alldig = false;
                        break;
                    }
                }
                if (alldig) return;
            }
        }*/
        ///////////////////////////// END ORG ////////////////////////////////////////////

        //qDebug()<<LsQueue->FindCallRow(theirCall_inmsg)<<LsNow->FindCallRow(theirCall_inmsg);
        QString id_rpt = "0";
        bool block_rpt_all = true;
        if (!myCall_inmsg.isEmpty())//<-- && f_double_click
        {
            if (rpt_inmsg.isEmpty() && theirLoc_inmsg.isEmpty() && cont_r_inmsg.isEmpty() && rr73_inmsg.isEmpty() && arrl_exch_imsg.isEmpty())
            {//msg=0 only calls exeption if have slashs
                id_rpt = "1"; //qDebug()<<"MAM msg=0 only calls===================";
                block_rpt_all = false;
            }
            else if (rpt_inmsg.isEmpty() && (!theirLoc_inmsg.isEmpty() || !arrl_exch_imsg.isEmpty()))//1.84 down my be for later
            {//msg=0 KN23
                if (!cont_r_inmsg.isEmpty())  //msk144 ft8 c mode
                    id_rpt = "3";
                else
                {
                    if (f_multi_answer_mod_std && (s_co_type==2 || s_co_type==4)) // || s_co_type==6 msk144 ft8
                        id_rpt = "2";
                    else
                        id_rpt = "1";
                }
                block_rpt_all = false;
            }
            else if (!rpt_inmsg.isEmpty() && rpt_inmsg.at(0)!='R' && rpt_inmsg.at(rpt_inmsg.count()-1).isDigit() && rpt_inmsg!="73")
            {//msg=1 +00
                if (!cont_r_inmsg.isEmpty())
                    id_rpt = "3";
                else
                    id_rpt = "2";
                rpt_inmsg = format_rpt_ma(rpt_inmsg);
                block_rpt_all = false;
            }
            else if (!rpt_inmsg.isEmpty() && rpt_inmsg.at(0)=='R' && rpt_inmsg.at(rpt_inmsg.count()-1).isDigit())
            {//msg=2 R+00
                id_rpt = "3";
                rpt_inmsg.remove("R");
                rpt_inmsg = format_rpt_ma(rpt_inmsg);

                //if(f_multi_answer_mod_std && s_id_con>0)
                block_rpt_all = false;// i ot tx2=1 i ot tx3=2 se gubi lokatora pri std taka 4e puskaj gi
                //else
                //block_rpt_all = true;
            }
            else if (!rpt_inmsg.isEmpty() && rpt_inmsg.at(0)=='R' && !rpt_inmsg.at(rpt_inmsg.count()-1).isDigit() &&
                     rpt_inmsg.at(rpt_inmsg.count()-1)=='R')
            {//msg=3 RRR
                id_rpt = "3";
                block_rpt_all = true;
            }
            else if ((!rpt_inmsg.isEmpty() && rpt_inmsg=="73") || rr73_inmsg=="RR73")//1.54=RR73
            {//msg=4 73 or RR73
                if (f_multi_answer_mod_std)
                    id_rpt = "4";
                else
                    id_rpt = "3";
                block_rpt_all = true;
            }
        }
        else if (f_multi_answer_mod_std && myCall_inmsg.isEmpty() && f_double_click)//2.23
        {//msg=9 click to someone else
            if (s_start_qso_from_tx2 && s_co_type!=3)//2.31 no in eu vhf
                id_rpt = "1";
            else
                id_rpt = "0";
            block_rpt_all = false;
            if (!rpt_inmsg.isEmpty() && rpt_inmsg.at(0)=='R' && rpt_inmsg.at(rpt_inmsg.count()-1).isDigit())
                rpt_inmsg.remove("R");
        }
        else
            return;

        if (id_0qe_1nw_2ne == 2 && block_rpt_all) return; //MAM no posible newcand with rpt-> RRR RR73 73
        /*QString tr0 = "";
        if (id_0qe_1nw_2ne == 2 && block_rpt_all) 
        {
        	//if (FindCallBackupDB(theirCall_inmsg)==-1) return;
        	if (!f_double_click || !f_multi_answer_mod_std) return;
        	id_rpt = "3";
        	tr0 = gen_in_tx_time;
        	//if (f_tx_rx) tr0 = "1";
        }*/

        bool is_checked = false;//2.66
        int c_que_limit = SBqueueLimit->value(); //2.39 no Queue
        if (c_que_limit == 0)//2.39 no Queue   id_0qe_1nw_2ne -> 0=Queue,1=Now,2=New
        {      	
			bool f_aseqmd = false;
            if (f_aseqmaxdist && LsQueue->GetRowCount()==0 && SBslots->value()==1 && id_0qe_1nw_2ne==2)//2.66  && !TQueuedCall->haveQueuedCall() ???
            {
                if (!myCall_inmsg.isEmpty() && !theirCall_inmsg.isEmpty() && is_LastTxRptCq)//&& !theirLoc_inmsg.isEmpty()
                {
                    //int ds = MultiAnswerMod->CalcDistance(theirLoc_inmsg.mid(0,4),false).toInt();//false=kilometers
                    //int po=ds/500;  //ARRL Inter. Contest rules points, bad for VHF
                    //if (ds>500*po) po++;
                    //po++;
                    int po = -1;
                    if (theirLoc_inmsg.isEmpty()) po = 0; //<mycall> theircall no loc 
            		else po = CalcDistance(theirLoc_inmsg,false).toInt();//good for VHF false=kilometers
            		if (po > s_dist_points)
            		{
            			/*QString s;
            			if (LsNow->GetRowCount()>0) s = LsNow->model.item(0,0)->text();
                		qDebug()<<"Change="<<s<<s_dist_points<<"to"<<theirCall_inmsg<<po;*/
                		s_dist_points = po;
                		if (LsNow->GetRowCount()==1) f_aseqmd = true;
            		}
				}
            }
            if ((f_double_click || f_aseqmd) && id_0qe_1nw_2ne!=1 && id_0qe_1nw_2ne!=0 && LsQueue->GetRowCount()==0
                    && SBslots->value()==1 && LsNow->GetRowCount()==1) //2.59 all on the fly
            {
                if (f_multi_answer_mod_std && info_dupe_qso && f_double_click) //2.66=?
                {
                    is_checked = true;
                    if (DialogIsCallDupeInLog(theirCall_inmsg)) return;
                }
                ClrNowUserDoubleClick();
            }
            if (LsNow->GetRowCount() < SBslots->value()) c_que_limit = 1;
        }
        if (id_0qe_1nw_2ne == 2 && LsQueue->GetRowCount() >= c_que_limit) return; //2.39 no Queue, new and no have place

        if (!is_checked && f_multi_answer_mod_std && info_dupe_qso && f_double_click) //2.66=?
        {
            if (DialogIsCallDupeInLog(theirCall_inmsg)) return;
        }

        QString dist = "?";
        if (!theirLoc_inmsg.isEmpty()) dist = CalcDistance(theirLoc_inmsg,f_km_mi);

        if (rpt_inmsg=="73" || rpt_inmsg=="RRR" || rpt_inmsg=="RR73") rpt_inmsg = "";//no update TheirRxRptForMe

		//if (id_rpt == "9" || id_rpt == "0" || id_rpt == "1")//2.22  1.80 no update MyTxRptForThem
        if (id_rpt == "0" || id_rpt == "1" || id_rpt == "2")//2.22  1.80 no update MyTxRptForThem
        {
            /*if (f_multi_answer_mod_std && (s_co_type==3 || s_co_type==5))
                tx_rpt = FormatRPTtoRST(tx_rpt);*/
            if (f_multi_answer_mod_std) tx_rpt = TryFormatRPTtoRST(tx_rpt); //2.59
            tx_rpt = format_rpt_ma(tx_rpt);
        }
        else
            tx_rpt = "";
		//qDebug()<<"tx_rpt"<<tx_rpt;

		//if (id_0qe_1nw_2ne == 1) tx_rpt = "";//exist no update

        if (id_0qe_1nw_2ne == 1)     //first upd if Now 1=Now
        {
            QString prev_id_rpt = LsNow->model.item(row_now,7)->text();
            //int iprev_id_rpt = prev_id_rpt.toInt();

            if (theirCall_inmsg.contains("/"))//1.73 update if have slash during QSO
                LsNow->SetItem(row_now,0,theirCall_inmsg);

            if (!tx_rpt.isEmpty())//1.80 no update MyTxRptForThem
                LsNow->SetItem(row_now,1,tx_rpt);

            if (!rpt_inmsg.isEmpty())
                LsNow->SetItem(row_now,2,rpt_inmsg);
            if (dist!="?")
                LsNow->SetItem(row_now,3,dist);
            if (!theirLoc_inmsg.isEmpty())
                LsNow->SetItem(row_now,4,theirLoc_inmsg);
            LsNow->SetItem(row_now,5,freq);
            LsNow->SetItem(row_now,7,id_rpt);
            QString ttry = QString("%1").arg(QDateTime::currentDateTimeUtc().toTime_t());
            LsNow->SetItem(row_now,8,ttry);//reset time

            if (!sn_inmsg.isEmpty())
                LsNow->SetItem(row_now,10,sn_inmsg);
            if (!arrl_exch_imsg.isEmpty())
                LsNow->SetItem(row_now,11,arrl_exch_imsg);

            //qDebug()<<"C_msg="<<current_msg<<current_msg.mid(current_msg.count()-4,4);

            if (f_tx_rx && SBslots->value()==1 && (id_rpt == "4" || id_rpt == "3"))//2.66
            {//if (f_tx_rx && (s_mode == 11 || s_mode == 13 || allq65) && SBslots->value()==1 && (id_rpt == "4" || id_rpt == "3"))
                //if (f_tx_rx && f_auto_on && SBslots->value()==1 && s_mode == 11 && (id_rpt == "4" || id_rpt == "3"))
                LsNow->SetItem(row_now,7,"3");
                LsNow->SetItem(row_now,9,"0");//1 tx 0 rx gen_in_tx_time
                if (!f_cfm73 && id_rpt == "4")
                    SetTxMsgEnd();
                else
                    gen_msg();
                //qDebug()<<"000SetTxMsgEnd()"<<gen_in_tx_time<<id_rpt;
            }
            else if (!f_cfm73 && prev_id_rpt == "2" && id_rpt == "4")  //no needed -> f_multi_answer_mod_std &&
            {
                LsNow->SetItem(row_now,7,"3");// out id for SetTxMsgEnd();
                LsNow->SetItem(row_now,9,"0");//1 tx 0 rx
                SetTxMsgEnd();
                //qDebug()<<"111SetTxMsgEnd()"<<gen_in_tx_time;
            }
            //else if (f_cfm73 && prev_id_rpt == "2" && id_rpt == "4")//old 2.47
            else if (f_cfm73 && (prev_id_rpt == "2" || prev_id_rpt == "3") && id_rpt == "4")//2.48 no needed -> f_multi_answer_mod_std &&
            {
                LsNow->SetItem(row_now,7,"3");// out id for SetTxMsgEnd();
                gen_msg();
                //qDebug()<<"222SetTxMsgEnd()"<<gen_in_tx_time;
            }
            else
                gen_msg();
            //qDebug()<<"prev_id_rpt"<<prev_id_rpt<<"id_rpt"<<id_rpt;
        }
        else if (id_0qe_1nw_2ne == 0)//second upd if Queue 0=Queue
        {
            if (theirCall_inmsg.contains("/"))//1.73 update if have slash during QSO
                LsQueue->SetItem(row_queue,0,theirCall_inmsg);

            if (!tx_rpt.isEmpty())//1.80 no update MyTxRptForThem
                LsQueue->SetItem(row_queue,1,tx_rpt);

            if (!rpt_inmsg.isEmpty())
                LsQueue->SetItem(row_queue,2,rpt_inmsg);
            if (dist!="?")
                LsQueue->SetItem(row_queue,3,dist);
            if (!theirLoc_inmsg.isEmpty())
                LsQueue->SetItem(row_queue,4,theirLoc_inmsg);
            LsQueue->SetItem(row_queue,5,freq);
            LsQueue->SetItem(row_queue,7,id_rpt);

            if (!sn_inmsg.isEmpty())
                LsQueue->SetItem(row_now,10,sn_inmsg);
            if (!arrl_exch_imsg.isEmpty())
                LsQueue->SetItem(row_now,11,arrl_exch_imsg);
        }
        else if (id_0qe_1nw_2ne == 2)//thirt upd  2=New
        {
            //"Call"<<"dB"<<"Rx dB"<<"Dist"<<"Grid"<<"Freq"<<"Time"<<"IDrpt"<<"Try"<<"GinTxT"<<s<<e;
            QStringList lss;  //qDebug()<<"mmmmmmm="<<rpt_inmsg;                                        //""<-Time and    TTry need to be empty
            if (!rpt_inmsg.isEmpty()) rpt_inmsg = format_rpt_ma(rpt_inmsg);
            lss<<theirCall_inmsg<<tx_rpt<<rpt_inmsg<<dist<<theirLoc_inmsg<<freq<<""<<id_rpt<<""<<""<<sn_inmsg<<arrl_exch_imsg;
            LsQueue->InsertItem_hv(lss);
            RefreshLists(0);
        }
        if (f_double_click)
        {
            s_last_bccall_tolog_excp = "_NONE_";//reset add to log if I want to make QSO again
            emit EmitDoubleClick();
        }
    }
}
void MultiAnswerModW::SetTextForAutoSeq(QStringList list_in)
{
    //if (!list_in.isEmpty() && (s_mode == 0 || s_mode == 11 || s_mode == 12) && list_in.count()>7 && f_auto_on)//FT8 have column 7 for freq msk144 have column 8 for freq
    if (!list_in.isEmpty() && (s_mode == 11 || s_mode == 13 || allq65) && list_in.count()>7)
    {
        QString text_msg = list_in.at(4); //ft8 only
        QString tx_rpt = list_in.at(1);
        QString freq = list_in.at(7);
        QString hcap;//fictive
        QString hloc;//fictive
        DecListTextAll(tx_rpt,text_msg,freq,false,hcap,hloc);//false f_double_click
    }
}



