109 lines
3.6 KiB
C++
109 lines
3.6 KiB
C++
#include "settingsdialog.h"
|
|
#include "ui_settingsdialog.h"
|
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent) :
|
|
QDialog(parent)
|
|
, ui(new Ui::SettingsDialog)
|
|
, m_deviceDialog(NULL)
|
|
{
|
|
ui->setupUi(this);
|
|
this->setWindowTitle("Settings");
|
|
ui->layersNumber->setValue(Settings::getInstance()->getLayersNumber());
|
|
//QString path("Path to root folder of the media tree: /n");
|
|
//path.append(Settings::getInstance()->getPathMedia());
|
|
//ui->mediaPath->setText(path);
|
|
connect(ui->mediaPathButton, SIGNAL(clicked()),
|
|
this, SLOT(changeMediaPath()));
|
|
connect(ui->audioDeviceButton , SIGNAL(clicked()),
|
|
this, SLOT(changeAudioDevice()));
|
|
connect(ui->layersNumber, SIGNAL(valueChanged(int)),
|
|
this, SLOT(layersChanged(int)));
|
|
int layer = 0;
|
|
foreach (const dmxSetting &it, Settings::getInstance()->getDmxSettings()) {
|
|
LayerSettingsWidget *temp = new LayerSettingsWidget(this, layer);
|
|
temp->setUniverse(it.universe);
|
|
temp->setAddress(it.address);
|
|
ui->layersLayout->insertWidget(layer, temp);
|
|
layer++;
|
|
}
|
|
}
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void SettingsDialog::changeMediaPath()
|
|
{
|
|
QFileDialog dialog(this);
|
|
dialog.setFileMode(QFileDialog::Directory);
|
|
QStringList fileNames;
|
|
if (!dialog.exec())
|
|
return;
|
|
fileNames = dialog.selectedFiles();
|
|
QString file = fileNames.at(0);
|
|
Settings::getInstance()->setPathMedia(file);
|
|
QString desc = tr("Media Path Changed to: %1").arg(file);
|
|
qInfo("%s", desc.toLatin1().constData());
|
|
}
|
|
|
|
void SettingsDialog::changeAudioDevice()
|
|
{
|
|
if (!m_deviceDialog)
|
|
{
|
|
m_deviceDialog = new QDialog( this );
|
|
}
|
|
QLabel *msgLabel = new QLabel;
|
|
AudioWidget *aw = AudioWidget::getInstance();
|
|
QString *msg = new QString;
|
|
for (uint iAvailableDevice = 0; iAvailableDevice < aw->playbackDeviceCount; iAvailableDevice += 1) {
|
|
msg->append(tr("%1 : %2\n").arg(iAvailableDevice).arg(aw->pPlaybackDeviceInfos[iAvailableDevice].name));
|
|
}
|
|
msgLabel->setText(msg->toLatin1());
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
layout->addWidget(msgLabel);
|
|
QSpinBox *res = new QSpinBox;
|
|
res->setRange(0, aw->playbackDeviceCount);
|
|
res->setValue(AudioWidget::getInstance()->iChosenDevice);
|
|
layout->addWidget(res);
|
|
QPushButton *closeButton = new QPushButton(tr("Close"));
|
|
connect(closeButton, SIGNAL(clicked()), this, SLOT(closeAudioDeviceDialog()));
|
|
closeButton->setDefault(true);
|
|
layout->addWidget(closeButton);
|
|
m_deviceDialog->setLayout(layout);
|
|
m_deviceDialog->setModal(true);
|
|
m_deviceDialog->show();
|
|
}
|
|
|
|
void SettingsDialog::closeAudioDeviceDialog()
|
|
{
|
|
QLayoutItem * const item = m_deviceDialog->layout()->itemAt(1);
|
|
int value = dynamic_cast<QSpinBox *>(item->widget())->value();
|
|
Settings::getInstance()->setAudioDeviceId(value);
|
|
qInfo("device selected: %i", value);
|
|
m_deviceDialog->close();
|
|
emit Settings::getInstance()->audioDeviceChanged(value);
|
|
}
|
|
|
|
void SettingsDialog::layersChanged(int val)
|
|
{
|
|
int layers = Settings::getInstance()->getLayersNumber();
|
|
if (val > layers)
|
|
{
|
|
while (val != layers)
|
|
{
|
|
ui->layersLayout->addWidget(new LayerSettingsWidget(this, val));
|
|
layers++;
|
|
}
|
|
} else if (val < layers)
|
|
{
|
|
while (val != layers)
|
|
{
|
|
Settings::getInstance()->removeLayer(val);
|
|
QLayoutItem * const item = ui->layersLayout->itemAt(layers);
|
|
ui->layersLayout->removeItem(item);
|
|
layers--;
|
|
}
|
|
}
|
|
Settings::getInstance()->setLayersNumber(layers);
|
|
}
|