Exemplo n.º 1
0
CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, FirmwareInterface * firmware):
  ModelPanel(parent, model, generalSettings, firmware),
  initialized(false)
#if defined(PHONON)
  ,
  phononCurrent(-1),
  clickObject(NULL),
  clickOutput(NULL)
#endif
{
  QGridLayout * gridLayout = new QGridLayout(this);

  addLabel(gridLayout, tr("Switch"), 1);
  addLabel(gridLayout, tr("Action"), 2);
  addLabel(gridLayout, tr("Parameters"), 3);
  addLabel(gridLayout, tr("Enable"), 4, true );
  addEmptyLabel(gridLayout, 5 );

  lock = true;
  int num_fsw = firmware->getCapability(CustomFunctions);

  if (!firmware->getCapability(VoicesAsNumbers)) {
    tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength));
    for (int i=0; i<num_fsw; i++) {
      if (model.funcSw[i].func==FuncPlayPrompt || model.funcSw[i].func==FuncBackgroundMusic) {
        QString temp = model.funcSw[i].paramarm;
        if (!temp.isEmpty()) {
          tracksSet.insert(temp);
        }
      }
    }
    qDebug() << tracksSet;
  }

  if (IS_TARANIS(firmware->getBoard())) {
    scriptsSet = getFilesSet(g.profile[g.id()].sdPath() + "/SCRIPTS", QStringList() << "*.lua", firmware->getCapability(VoicesMaxLength));
    for (int i=0; i<num_fsw; i++) {
      if (model.funcSw[i].func==FuncPlayScript) {
        QString temp = model.funcSw[i].paramarm;
        if (!temp.isEmpty()) {
          scriptsSet.insert(temp);
        }
      }
    }
    qDebug() << scriptsSet;
  }

  CompanionIcon playIcon("play.png");

  for (int i=0; i<num_fsw; i++) {
    // The label
    QLabel * label = new QLabel(this);
    label->setContextMenuPolicy(Qt::CustomContextMenu);
    label->setMouseTracking(true);
    label->setProperty("index", i);
    label->setText(tr("SF%1").arg(i+1));
    label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
    connect(label, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(fsw_customContextMenuRequested(QPoint)));
    gridLayout->addWidget(label, i+1, 0);

    // The switch
    fswtchSwtch[i] = new QComboBox(this);
    fswtchSwtch[i]->setProperty("index", i);
    fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
    connect(fswtchSwtch[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
    gridLayout->addWidget(fswtchSwtch[i], i+1, 1);

    // The function
    fswtchFunc[i] = new QComboBox(this);
    fswtchFunc[i]->setProperty("index", i);
    connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited()));
    gridLayout->addWidget(fswtchFunc[i], i+1, 2);

    QHBoxLayout *paramLayout = new QHBoxLayout();
    gridLayout->addLayout(paramLayout, i+1, 3);

    fswtchGVmode[i] = new QComboBox(this);
    fswtchGVmode[i]->setProperty("index", i);
    connect(fswtchGVmode[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
    paramLayout->addWidget(fswtchGVmode[i]);

    fswtchParamGV[i] = new QCheckBox(this);
    fswtchParamGV[i]->setProperty("index", i);
    fswtchParamGV[i]->setText("GV");
    fswtchParamGV[i]->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
    connect(fswtchParamGV[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited()));
    paramLayout->addWidget(fswtchParamGV[i]);

    fswtchParam[i] = new QDoubleSpinBox(this);
    fswtchParam[i]->setProperty("index", i);
    fswtchParam[i]->setAccelerated(true);
    fswtchParam[i]->setDecimals(0);
    connect(fswtchParam[i], SIGNAL(editingFinished()), this, SLOT(customFunctionEdited()));
    paramLayout->addWidget(fswtchParam[i]);

    fswtchParamTime[i] = new QTimeEdit(this);
    fswtchParamTime[i]->setProperty("index", i);
    fswtchParamTime[i]->setAccelerated(true);
    fswtchParamTime[i]->setDisplayFormat("hh:mm:ss");
    connect(fswtchParamTime[i], SIGNAL(editingFinished()), this, SLOT(customFunctionEdited()));
    paramLayout->addWidget(fswtchParamTime[i]);

    fswtchParamT[i] = new QComboBox(this);
    fswtchParamT[i]->setProperty("index", i);
    paramLayout->addWidget(fswtchParamT[i]);
    connect(fswtchParamT[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));

    fswtchParamArmT[i] = new QComboBox(this);
    fswtchParamArmT[i]->setProperty("index", i);
    fswtchParamArmT[i]->setEditable(true);
    paramLayout->addWidget(fswtchParamArmT[i]);

    connect(fswtchParamArmT[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
    connect(fswtchParamArmT[i], SIGNAL(editTextChanged ( const QString)), this, SLOT(customFunctionEdited()));

    fswtchBLcolor[i] = new QSlider(this);
    fswtchBLcolor[i]->setProperty("index", i);
    fswtchBLcolor[i]->setMinimum(0);
    fswtchBLcolor[i]->setMaximum(100);
    fswtchBLcolor[i]->setSingleStep(1);
    fswtchBLcolor[i]->setOrientation(Qt::Horizontal);
    paramLayout->addWidget(fswtchBLcolor[i]);
    connect(fswtchBLcolor[i], SIGNAL(sliderReleased()), this, SLOT(customFunctionEdited()));

#ifdef PHONON
    playBT[i] = new QPushButton(this);
    playBT[i]->setProperty("index", i);
    playBT[i]->setIcon(playIcon);
    paramLayout->addWidget(playBT[i]);
    connect(playBT[i], SIGNAL(pressed()), this, SLOT(playMusic()));
#endif

    QHBoxLayout *repeatLayout = new QHBoxLayout();
    gridLayout->addLayout(repeatLayout, i+1, 4);
    fswtchRepeat[i] = new RepeatComboBox(this, model.funcSw[i].repeatParam);
    repeatLayout->addWidget(fswtchRepeat[i], i+1);
    connect(fswtchRepeat[i], SIGNAL(modified()), this, SLOT(onChildModified()));

    fswtchEnable[i] = new QCheckBox(this);
    fswtchEnable[i]->setProperty("index", i);
    fswtchEnable[i]->setText(tr("ON"));
    fswtchEnable[i]->setFixedWidth( 80 );
    repeatLayout->addWidget(fswtchEnable[i], i+1);
    connect(fswtchEnable[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited()));
  }

  // Push rows upward
  addDoubleSpring(gridLayout, 5, num_fsw+1);

  disableMouseScrolling();

  lock = false;
}
Exemplo n.º 2
0
CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware):
  GenericPanel(parent, model, generalSettings, firmware),
  functions(model ? model->customFn : generalSettings.customFn)
#if defined(PHONON)
  ,
  phononCurrent(-1),
  clickObject(NULL),
  clickOutput(NULL)
#endif
{
  Stopwatch s1("CustomFunctionsPanel - populate"); 
  lock = true;
  int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);

  if (!firmware->getCapability(VoicesAsNumbers)) {
    tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength));
    for (int i=0; i<num_fsw; i++) {
      if (functions[i].func==FuncPlayPrompt || functions[i].func==FuncBackgroundMusic) {
        QString temp = functions[i].paramarm;
        if (!temp.isEmpty()) {
          tracksSet.insert(temp);
        }
      }
    }
  }

  s1.report("get tracks");

  if (IS_TARANIS(firmware->getBoard())) {
    scriptsSet = getFilesSet(g.profile[g.id()].sdPath() + "/SCRIPTS/FUNCTIONS", QStringList() << "*.lua", firmware->getCapability(VoicesMaxLength));
    for (int i=0; i<num_fsw; i++) {
      if (functions[i].func==FuncPlayScript) {
        QString temp = functions[i].paramarm;
        if (!temp.isEmpty()) {
          scriptsSet.insert(temp);
        }
      }
    }
  }
  s1.report("get scripts");

  CompanionIcon playIcon("play.png");

  QStringList headerLabels;
  headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << tr("Enable");
  TableLayout * tableLayout = new TableLayout(this, num_fsw, headerLabels);

  for (int i=0; i<num_fsw; i++) {
    // The label
    QLabel * label = new QLabel(this);
    label->setContextMenuPolicy(Qt::CustomContextMenu);
    label->setMouseTracking(true);
    label->setProperty("index", i);
    if (model)
      label->setText(tr("SF%1").arg(i+1));
    else
      label->setText(tr("GF%1").arg(i+1));
    label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
    connect(label, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(fsw_customContextMenuRequested(QPoint)));
    tableLayout->addWidget(i, 0, label);
    // s1.report("label");

    // The switch
    fswtchSwtch[i] = new QComboBox(this);
    fswtchSwtch[i]->setProperty("index", i);
    populateSwitchCB(fswtchSwtch[i], functions[i].swtch, generalSettings, model ? SpecialFunctionsContext : GlobalFunctionsContext);
    fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
    fswtchSwtch[i]->setMaxVisibleItems(10);
    connect(fswtchSwtch[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
    tableLayout->addWidget(i, 1, fswtchSwtch[i]);
    // s1.report("switch");

    // The function
    fswtchFunc[i] = new QComboBox(this);
    fswtchFunc[i]->setProperty("index", i);
    populateFuncCB(fswtchFunc[i], functions[i].func);
    connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited()));
    tableLayout->addWidget(i, 2, fswtchFunc[i]);
    // s1.report("func");

    // The parameters
    QHBoxLayout * paramLayout = new QHBoxLayout();
    tableLayout->addLayout(i, 3, paramLayout);

    fswtchGVmode[i] = new QComboBox(this);
    fswtchGVmode[i]->setProperty("index", i);
    populateGVmodeCB(fswtchGVmode[i], functions[i].adjustMode);
    fswtchGVmode[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    connect(fswtchGVmode[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
    paramLayout->addWidget(fswtchGVmode[i]);

    fswtchParamGV[i] = new QCheckBox(this);
    fswtchParamGV[i]->setProperty("index", i);
    fswtchParamGV[i]->setText("GV");
    fswtchParamGV[i]->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
    connect(fswtchParamGV[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited()));
    paramLayout->addWidget(fswtchParamGV[i]);

    fswtchParam[i] = new QDoubleSpinBox(this);
    fswtchParam[i]->setProperty("index", i);
    fswtchParam[i]->setAccelerated(true);
    fswtchParam[i]->setDecimals(0);
    connect(fswtchParam[i], SIGNAL(editingFinished()), this, SLOT(customFunctionEdited()));
    paramLayout->addWidget(fswtchParam[i]);

    fswtchParamTime[i] = new QTimeEdit(this);
    fswtchParamTime[i]->setProperty("index", i);
    fswtchParamTime[i]->setAccelerated(true);
    fswtchParamTime[i]->setDisplayFormat("hh:mm:ss");
    connect(fswtchParamTime[i], SIGNAL(editingFinished()), this, SLOT(customFunctionEdited()));
    paramLayout->addWidget(fswtchParamTime[i]);

    fswtchParamT[i] = new QComboBox(this);
    fswtchParamT[i]->setProperty("index", i);
    populateFuncParamCB(fswtchParamT[i], functions[i].func, functions[i].param, functions[i].adjustMode);
    paramLayout->addWidget(fswtchParamT[i]);
    fswtchParamT[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    connect(fswtchParamT[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));

    fswtchParamArmT[i] = new QComboBox(this);
    fswtchParamArmT[i]->setProperty("index", i);
    fswtchParamArmT[i]->setEditable(true);
    fswtchParamArmT[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    paramLayout->addWidget(fswtchParamArmT[i]);

    connect(fswtchParamArmT[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
    connect(fswtchParamArmT[i], SIGNAL(editTextChanged ( const QString)), this, SLOT(customFunctionEdited()));

    fswtchBLcolor[i] = new QSlider(this);
    fswtchBLcolor[i]->setProperty("index", i);
    fswtchBLcolor[i]->setMinimum(0);
    fswtchBLcolor[i]->setMaximum(100);
    fswtchBLcolor[i]->setSingleStep(1);
    fswtchBLcolor[i]->setOrientation(Qt::Horizontal);
    paramLayout->addWidget(fswtchBLcolor[i]);
    connect(fswtchBLcolor[i], SIGNAL(sliderReleased()), this, SLOT(customFunctionEdited()));

#ifdef PHONON
    playBT[i] = new QPushButton(this);
    playBT[i]->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    playBT[i]->setProperty("index", i);
    playBT[i]->setIcon(playIcon);
    paramLayout->addWidget(playBT[i]);
    connect(playBT[i], SIGNAL(pressed()), this, SLOT(playMusic()));
#endif

    QHBoxLayout * repeatLayout = new QHBoxLayout();
    tableLayout->addLayout(i, 4, repeatLayout);
    fswtchRepeat[i] = new RepeatComboBox(this, functions[i].repeatParam);
    repeatLayout->addWidget(fswtchRepeat[i], i+1);
    connect(fswtchRepeat[i], SIGNAL(modified()), this, SLOT(onChildModified()));

    fswtchEnable[i] = new QCheckBox(this);
    fswtchEnable[i]->setProperty("index", i);
    fswtchEnable[i]->setText(tr("ON"));
    fswtchEnable[i]->setFixedWidth(200);
    repeatLayout->addWidget(fswtchEnable[i], i+1);
    connect(fswtchEnable[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited()));
  }
  s1.report("add items");

  disableMouseScrolling();
  s1.report("disableMouseScrolling");

  lock = false;

  update();
  s1.report("update");
  tableLayout->resizeColumnsToContents();
  s1.report("resizeColumnsToContents");
  tableLayout->setColumnWidth(3, 300);
  tableLayout->pushRowsUp(num_fsw+1);
  s1.report("end");
}