dlgccconfig.cpp 4.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
#include <QSettings>
#include <QMessageBox>
#include <QTimer>

#include "dlgccconfig.h"
#include "ui_dlgccconfig.h"

dlgccconfig::dlgccconfig(QWidget *parent, int dev, Device *part, tCCConfig *ccconfig, bool *DataChanged) :
    QDialog(parent),
    ui(new Ui::dlgccconfig)
{
    ui->setupUi(this);
    _Partner        = (Device*)part;
    _DeviceNo       = dev;
    _CCConfig       = ccconfig;
    _DataChanged    = DataChanged;

    // CC_MAX_COMMANDS = 6 beachten !!
    FunctionNames.append(CC_FUNCTION_0);
    FunctionNames.append(CC_FUNCTION_1);
    FunctionNames.append(CC_FUNCTION_2);
    FunctionNames.append(CC_FUNCTION_3);
    FunctionNames.append(CC_FUNCTION_4);
    FunctionNames.append(CC_FUNCTION_5);
    // CC_MAX_COMMANDS = 6 beachten !!

    QFrame          *line;
    for (int f=0; f<CC_MAX_COMMANDS; f++) {
        for (int c=0; c<CC_MAX_COLUMNS; c++) {

            QFrame *frame = new QFrame();
            frame->setFrameStyle(QFrame::Sunken | QFrame::Box);
            frame->setLayout(&Layout[c][f]);

            ui->gridLayout->addWidget(frame,f+1,c);

            switch (c) {
                case 0:     _Check[c][f] = new QIdxCheckBox(c,f,FunctionNames[f]);
                            _Check[c][f]->setStyleSheet("QCheckBox { font-weight: bold; } ");
                            _Check[c][f]->setChecked(_CCConfig[f].checked[c]);
                            connect(_Check[c][f],SIGNAL(isClicked(int,int,int)),this,SLOT(CbClicked(int,int,int)));
                            Layout[c][f].insertWidget(c,_Check[c][f]);
                            break;
                case 1:     _Check[c][f] = new QIdxCheckBox(c,f,QString("invert"));
                            _Check[c][f]->setChecked(_CCConfig[f].checked[c]);
                            connect(_Check[c][f],SIGNAL(isClicked(int,int,int)),this,SLOT(CbClicked(int,int,int)));
                            Layout[c][f].insertWidget(c,_Check[c][f]);
                            break;
                case 2:     _Check[c][f] = new QIdxCheckBox(c,f,QString("enable"));
                            _Check[c][f]->setChecked(_CCConfig[f].checked[c]);
                            connect(_Check[c][f],SIGNAL(isClicked(int,int,int)),this,SLOT(CbClicked(int,int,int)));
                            Layout[c][f].insertWidget(c,_Check[c][f]);
                            break;

                case 3:     // Input Selection
                            for (int x=0; x<CC_MAX_INPUTS; x++) {
                                _Input[x][f] = new QIdxRadioButton(x,f,QString("%1").arg(x%5));
                                bool doframe = false;
                                if (((x+1)%5==0)&&(x+1<CC_MAX_INPUTS)) {
                                    line = new QFrame(this);
                                    line->setFrameShape(QFrame::VLine);
                                    line->setFrameShadow(QFrame::Sunken);
                                    doframe = true;
                                }
                                Layout[c][f].insertWidget(0,_Input[x][f]);
                                if (doframe) Layout[c][f].insertWidget(0,line);
                                connect(_Input[x][f],SIGNAL(isClicked(int,int)),this,SLOT(RbClicked(int,int)));
                            }
                            break;

                default:    break;
            }
        }
    }

    QTimer::singleShot(200, this, SLOT(InitDlg()));
}

dlgccconfig::~dlgccconfig()
{
    delete ui;
}


void dlgccconfig::InitDlg()
{
    SetCheckBox();
}

void dlgccconfig::CheckRadio()
{
    for (int f=0; f<CC_MAX_COMMANDS; f++) {
        for (int i=0; i<CC_MAX_INPUTS; i++) {
            _Input[i][f]->setEnabled(_CCConfig[f].checked[CC_USE]);
            if (i==_CCConfig[f].input) _Input[i][f]->setChecked(true); else _Input[i][f]->setChecked(false);
        }
    }
}


void dlgccconfig::SetCheckBox()
{
    for (int f=0; f<CC_MAX_COMMANDS; f++) {
        for (int c=0; c<CC_MAX_COLUMNS-1; c++) {
            _Check[c][f]->setChecked(_CCConfig[f].checked[c]);
            if (c>0) _Check[c][f]->setEnabled(_CCConfig[f].checked[CC_USE]);
        }
    }
    CheckRadio();
}

void dlgccconfig::RbClicked(int x, int y)
{
    *_DataChanged    = true;
    _CCConfig[y].input = x;
//    CalcMaskPattern();
}

void dlgccconfig::CbClicked(int x, int y, int state)
{
    *_DataChanged    = true;
    _CCConfig[y].checked[x]  = state;
//    CalcMaskPattern();
    SetCheckBox();
}



void dlgccconfig::on_dlgccconfig_finished(int result)
{
    Q_UNUSED(result)

//    CalcMaskPattern();
}