#include <QComboBox>
using namespace std;
+using namespace std::placeholders;
InputMappingDialog::InputMappingDialog()
- : ui(new Ui::InputMappingDialog)
+ : ui(new Ui::InputMappingDialog),
+ mapping(global_mixer->get_audio_mixer()->get_input_mapping()),
+ old_mapping(mapping),
+ card_names(global_mixer->get_audio_mixer()->get_names())
{
ui->setupUi(this);
- //connect(ui->button_box, &QDialogButtonBox::accepted, [this]{ this->close(); });
- vector<string> card_names = global_mixer->get_audio_mixer()->get_names();
- fill_ui_from_mapping(global_mixer->get_audio_mixer()->get_input_mapping(), card_names);
+ fill_ui_from_mapping(mapping);
+ connect(ui->table, &QTableWidget::cellChanged, this, &InputMappingDialog::cell_changed);
+ connect(ui->ok_cancel_buttons, &QDialogButtonBox::accepted, this, &InputMappingDialog::ok_clicked);
+ connect(ui->ok_cancel_buttons, &QDialogButtonBox::rejected, this, &InputMappingDialog::cancel_clicked);
+ connect(ui->add_button, &QPushButton::clicked, this, &InputMappingDialog::add_clicked);
+ //connect(ui->add_button, &QPushButton::clicked, this, &InputMappingDialog::add_clicked);
}
-void InputMappingDialog::fill_ui_from_mapping(const InputMapping &mapping, const vector<string> &card_names)
+void InputMappingDialog::fill_ui_from_mapping(const InputMapping &mapping)
{
ui->table->verticalHeader()->hide();
ui->table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
ui->table->setRowCount(mapping.inputs.size());
for (unsigned row = 0; row < mapping.inputs.size(); ++row) {
- // TODO: Mark as some sort of header (by means of background color, probably).
- QString name(QString::fromStdString(mapping.inputs[row].name));
- ui->table->setItem(row, 0, new QTableWidgetItem(name));
-
- // Card choices.
- QComboBox *card_combo = new QComboBox;
- card_combo->addItem(QString("(none) "));
- for (const string &name : card_names) {
- card_combo->addItem(QString::fromStdString(name + " "));
- }
- switch (mapping.inputs[row].input_source_type) {
- case InputSourceType::SILENCE:
- card_combo->setCurrentIndex(0);
- break;
- case InputSourceType::CAPTURE_CARD:
- card_combo->setCurrentIndex(mapping.inputs[row].input_source_index + 1);
- break;
- default:
- assert(false);
- }
- ui->table->setCellWidget(row, 1, card_combo);
+ fill_row_from_input(row, mapping.inputs[row]);
+ }
+}
- // Left and right channel.
- fill_channel_ui_from_mapping(row, mapping.inputs[row]);
+void InputMappingDialog::fill_row_from_input(unsigned row, const InputMapping::Input &input)
+{
+ QString name(QString::fromStdString(input.name));
+ ui->table->setItem(row, 0, new QTableWidgetItem(name));
+
+ // Card choices.
+ QComboBox *card_combo = new QComboBox;
+ card_combo->addItem(QString("(none) "));
+ for (const string &name : card_names) {
+ card_combo->addItem(QString::fromStdString(name + " "));
}
+ switch (input.input_source_type) {
+ case InputSourceType::SILENCE:
+ card_combo->setCurrentIndex(0);
+ break;
+ case InputSourceType::CAPTURE_CARD:
+ card_combo->setCurrentIndex(mapping.inputs[row].input_source_index + 1);
+ break;
+ default:
+ assert(false);
+ }
+ connect(card_combo, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
+ bind(&InputMappingDialog::card_selected, this, row, _1));
+ ui->table->setCellWidget(row, 1, card_combo);
+
+ setup_channel_choices_from_input(row, input);
}
-void InputMappingDialog::fill_channel_ui_from_mapping(unsigned row, const InputMapping::Input &input)
+void InputMappingDialog::setup_channel_choices_from_input(unsigned row, const InputMapping::Input &input)
{
+ // Left and right channel.
for (unsigned channel = 0; channel < 2; ++channel) {
QComboBox *channel_combo = new QComboBox;
channel_combo->addItem(QString("(none)"));
snprintf(buf, sizeof(buf), "Channel %u ", source + 1);
channel_combo->addItem(QString(buf));
}
+ channel_combo->setCurrentIndex(input.source_channel[channel] + 1);
+ } else {
+ channel_combo->setCurrentIndex(0);
}
- channel_combo->setCurrentIndex(input.source_channel[channel] + 1);
+ connect(channel_combo, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
+ bind(&InputMappingDialog::channel_selected, this, row, channel, _1));
ui->table->setCellWidget(row, 2 + channel, channel_combo);
}
}
+
+void InputMappingDialog::ok_clicked()
+{
+ global_mixer->get_audio_mixer()->set_input_mapping(mapping);
+ accept();
+}
+
+void InputMappingDialog::cancel_clicked()
+{
+ global_mixer->get_audio_mixer()->set_input_mapping(old_mapping);
+ reject();
+}
+
+void InputMappingDialog::cell_changed(int row, int column)
+{
+ if (column != 0) {
+ // Spurious; only really the name column should fire these.
+ return;
+ }
+ mapping.inputs[row].name = ui->table->item(row, column)->text().toStdString();
+}
+
+void InputMappingDialog::card_selected(unsigned row, int index)
+{
+ if (index == 0) {
+ mapping.inputs[row].input_source_type = InputSourceType::SILENCE;
+ } else {
+ mapping.inputs[row].input_source_type = InputSourceType::CAPTURE_CARD;
+ mapping.inputs[row].input_source_index = index - 1;
+ }
+ setup_channel_choices_from_input(row, mapping.inputs[row]);
+}
+
+void InputMappingDialog::channel_selected(unsigned row, unsigned channel, int index)
+{
+ mapping.inputs[row].source_channel[channel] = index - 1;
+}
+
+void InputMappingDialog::add_clicked()
+{
+ InputMapping::Input new_input;
+ new_input.name = "New input";
+ new_input.input_source_type = InputSourceType::SILENCE;
+ mapping.inputs.push_back(new_input);
+ ui->table->setRowCount(mapping.inputs.size());
+
+ unsigned row = mapping.inputs.size() - 1;
+ fill_row_from_input(row, new_input);
+ ui->table->editItem(ui->table->item(row, 0)); // Start editing the name.
+}
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,1,0,0,1,0">
<item>
- <widget class="QPushButton" name="pushButton">
+ <widget class="QPushButton" name="add_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
</widget>
</item>
<item>
- <widget class="QPushButton" name="pushButton_2">
+ <widget class="QPushButton" name="remove_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
</spacer>
</item>
<item>
- <widget class="QPushButton" name="pushButton_3">
+ <widget class="QPushButton" name="up_button">
<property name="maximumSize">
<size>
<width>30</width>
</widget>
</item>
<item>
- <widget class="QPushButton" name="pushButton_4">
+ <widget class="QPushButton" name="down_button">
<property name="maximumSize">
<size>
<width>30</width>
</spacer>
</item>
<item>
- <widget class="QDialogButtonBox" name="buttonBox">
+ <widget class="QDialogButtonBox" name="ok_cancel_buttons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</layout>
</widget>
<resources/>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>Dialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>248</x>
- <y>254</y>
- </hint>
- <hint type="destinationlabel">
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
- <signal>rejected()</signal>
- <receiver>Dialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>316</x>
- <y>260</y>
- </hint>
- <hint type="destinationlabel">
- <x>286</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- </connections>
+ <connections/>
</ui>