From f3b9135a09becce7d32440a9ae7351cfcbdfc876 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 22 Feb 2014 12:32:28 +0100 Subject: [PATCH] Core in Custom Functions Panel --- companion/src/modeledit/customfunctions.cpp | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index c9ba53ba5..b1805df46 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -162,7 +162,8 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData & model, #ifdef PHONON playBT[i] = new QPushButton(this); - playBT[i]->setObjectName(QString("play_%1").arg(i)); + playBT[i]->setProperty("index", i); + playBT[i]->setProperty("state", "play"); playBT[i]->setIcon(CompanionIcon("play.png")); paramLayout->addWidget(playBT[i]); connect(playBT[i], SIGNAL(pressed()), this, SLOT(playMusic())); @@ -222,42 +223,43 @@ void CustomFunctionsPanel::mediaPlayer_state(Phonon::State newState, Phonon::Sta void CustomFunctionsPanel::playMusic() { - QPushButton *playButton = qobject_cast(sender()); - int index=playButton->objectName().mid(5,2).toInt(); - QString function=playButton->objectName().left(4); - QString path = g.profile[g.id()].sdPath(); + QPushButton * button = qobject_cast(sender()); + int index = button->property("index").toInt(); + QString function = button->property("state").toString(); + QString path = g.profile[g.id()].sdPath(); QDir qd(path); QString track; if (qd.exists()) { if (GetEepromInterface()->getCapability(VoicesAsNumbers)) { - track=path+QString("/%1.wav").arg(int(fswtchParam[index]->value()),4,10,(const QChar)'0'); + track = path + QString("/%1.wav").arg(int(fswtchParam[index]->value()), 4, 10, (const QChar)'0'); } else { path.append("/SOUNDS/"); QString lang = generalSettings.ttsLanguage; if (lang.isEmpty()) - lang="en"; + lang = "en"; path.append(lang); - if (fswtchParamArmT[index]->currentText()!="----") { - track=path+"/"+fswtchParamArmT[index]->currentText()+".wav"; + if (fswtchParamArmT[index]->currentText() != "----") { + track = path + "/" + fswtchParamArmT[index]->currentText() + ".wav"; } } QFile file(track); if (!file.exists()) { QMessageBox::critical(this, tr("Error"), tr("Unable to find sound file %1!").arg(track)); - track.clear(); + return; } #ifdef PHONON - if (function=="play" && !track.isEmpty()) { + if (function=="play") { clickObject->clear(); clickObject->setCurrentSource(Phonon::MediaSource(track)); clickObject->play(); - playBT[index]->setObjectName(QString("stop_%1").arg(index)); + playBT[index]->setProperty("state", "stop"); playBT[index]->setIcon(CompanionIcon("stop.png")); - } else { + } + else { clickObject->stop(); clickObject->clear(); - playBT[index]->setObjectName(QString("play_%1").arg(index)); + playBT[index]->setProperty("state", "play"); playBT[index]->setIcon(CompanionIcon("play.png")); } #endif