Chris@62: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@62: Chris@62: /* Chris@62: Sonic Visualiser Chris@62: An audio file viewer and annotation editor. Chris@62: Centre for Digital Music, Queen Mary, University of London. Chris@62: This file copyright 2006 Chris Cannam. Chris@62: Chris@62: This program is free software; you can redistribute it and/or Chris@62: modify it under the terms of the GNU General Public License as Chris@62: published by the Free Software Foundation; either version 2 of the Chris@62: License, or (at your option) any later version. See the file Chris@62: COPYING included with this distribution for more information. Chris@62: */ Chris@62: Chris@62: #include "PluginParameterDialog.h" Chris@62: Chris@62: #include "PluginParameterBox.h" Chris@62: Chris@62: #include Chris@62: #include Chris@62: #include Chris@62: #include Chris@62: #include Chris@69: #include Chris@69: #include Chris@62: Chris@62: PluginParameterDialog::PluginParameterDialog(PluginInstance *plugin, Chris@69: int sourceChannels, Chris@69: int targetChannels, Chris@69: int defaultChannel, Chris@62: QWidget *parent) : Chris@62: QDialog(parent), Chris@62: m_plugin(plugin), Chris@69: m_channel(defaultChannel), Chris@62: m_parameterBox(0) Chris@62: { Chris@62: QGridLayout *grid = new QGridLayout; Chris@62: setLayout(grid); Chris@62: Chris@62: QGroupBox *pluginBox = new QGroupBox; Chris@62: pluginBox->setTitle(tr("Plugin")); Chris@62: grid->addWidget(pluginBox, 0, 0); Chris@62: Chris@62: QGridLayout *subgrid = new QGridLayout; Chris@62: pluginBox->setLayout(subgrid); Chris@62: Chris@63: subgrid->setSpacing(0); Chris@63: subgrid->setMargin(10); Chris@63: Chris@62: QFont font(pluginBox->font()); Chris@62: font.setBold(true); Chris@62: Chris@62: QLabel *nameLabel = new QLabel(plugin->getDescription().c_str()); Chris@62: nameLabel->setFont(font); Chris@62: Chris@62: QLabel *makerLabel = new QLabel(plugin->getMaker().c_str()); Chris@62: Chris@62: QLabel *versionLabel = new QLabel(QString("%1") Chris@62: .arg(plugin->getPluginVersion())); Chris@62: Chris@62: QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str()); Chris@62: Chris@63: QLabel *typeLabel = new QLabel(plugin->getType().c_str()); Chris@63: typeLabel->setFont(font); Chris@63: Chris@62: subgrid->addWidget(new QLabel(tr("Name:")), 0, 0); Chris@62: subgrid->addWidget(nameLabel, 0, 1); Chris@62: Chris@63: subgrid->addWidget(new QLabel(tr("Type:")), 1, 0); Chris@63: subgrid->addWidget(typeLabel, 1, 1); Chris@62: Chris@63: subgrid->addWidget(new QLabel(tr("Maker:")), 2, 0); Chris@63: subgrid->addWidget(makerLabel, 2, 1); Chris@62: Chris@63: subgrid->addWidget(new QLabel(tr("Copyright: ")), 3, 0); Chris@63: subgrid->addWidget(copyrightLabel, 3, 1); Chris@63: Chris@63: subgrid->addWidget(new QLabel(tr("Version:")), 4, 0); Chris@63: subgrid->addWidget(versionLabel, 4, 1); Chris@62: Chris@62: subgrid->setColumnStretch(1, 2); Chris@62: Chris@62: QGroupBox *paramBox = new QGroupBox; Chris@62: paramBox->setTitle(tr("Plugin Parameters")); Chris@62: grid->addWidget(paramBox, 1, 0); Chris@62: grid->setRowStretch(1, 10); Chris@62: Chris@62: QHBoxLayout *paramLayout = new QHBoxLayout; Chris@63: paramLayout->setMargin(0); Chris@62: paramBox->setLayout(paramLayout); Chris@62: Chris@62: m_parameterBox = new PluginParameterBox(m_plugin); Chris@64: connect(m_parameterBox, SIGNAL(pluginConfigurationChanged(QString)), Chris@64: this, SIGNAL(pluginConfigurationChanged(QString))); Chris@62: paramLayout->addWidget(m_parameterBox); Chris@62: Chris@69: if (sourceChannels != targetChannels) { Chris@69: Chris@69: // At the moment we can only cope with the case where Chris@69: // sourceChannels > targetChannels and targetChannels == 1 Chris@69: Chris@69: if (sourceChannels < targetChannels) { Chris@69: Chris@69: QMessageBox::warning Chris@69: (parent, Chris@69: tr("Channel mismatch"), Chris@69: tr("This plugin requires at least %1 input channels, but only %2 %3 available. The plugin probably will not work correctly.").arg(targetChannels).arg(sourceChannels).arg(sourceChannels != 1 ? tr("are") : tr("is")), Chris@69: QMessageBox::Ok, Chris@69: QMessageBox::NoButton); Chris@69: Chris@69: } else { Chris@69: Chris@69: QGroupBox *channelBox = new QGroupBox; Chris@69: channelBox->setTitle(tr("Channels")); Chris@69: grid->addWidget(channelBox, 2, 0); Chris@69: Chris@69: QVBoxLayout *channelLayout = new QVBoxLayout; Chris@69: channelBox->setLayout(channelLayout); Chris@69: Chris@69: if (targetChannels != 1) { Chris@69: Chris@69: channelLayout->addWidget Chris@69: (new QLabel(tr("This plugin accepts no more than %1 input channels,\nbut %2 are available. Only the first %3 will be used.\n") Chris@69: .arg(targetChannels) Chris@69: .arg(sourceChannels) Chris@69: .arg(targetChannels))); Chris@69: Chris@69: } else { Chris@69: Chris@69: channelLayout->addWidget(new QLabel(tr("This plugin only has a single channel input,\nbut the source has %1 channels.").arg(sourceChannels))); Chris@69: Chris@69: QComboBox *channelCombo = new QComboBox; Chris@69: channelCombo->addItem(tr("Use sum of source channels").arg(sourceChannels)); Chris@69: for (int i = 0; i < sourceChannels; ++i) { Chris@69: channelCombo->addItem(tr("Use channel %1 only").arg(i + 1)); Chris@69: } Chris@69: Chris@69: connect(channelCombo, SIGNAL(activated(int)), Chris@69: this, SLOT(channelComboChanged(int))); Chris@69: Chris@69: channelLayout->addWidget(channelCombo); Chris@69: } Chris@69: } Chris@69: } Chris@69: Chris@62: QHBoxLayout *hbox = new QHBoxLayout; Chris@69: grid->addLayout(hbox, 3, 0); Chris@62: Chris@62: QPushButton *ok = new QPushButton(tr("OK")); Chris@62: QPushButton *cancel = new QPushButton(tr("Cancel")); Chris@62: hbox->addStretch(10); Chris@62: hbox->addWidget(ok); Chris@62: hbox->addWidget(cancel); Chris@62: connect(ok, SIGNAL(clicked()), this, SLOT(accept())); Chris@62: connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); Chris@62: } Chris@62: Chris@62: PluginParameterDialog::~PluginParameterDialog() Chris@62: { Chris@62: } Chris@62: Chris@69: void Chris@69: PluginParameterDialog::channelComboChanged(int index) Chris@69: { Chris@69: m_channel = index - 1; Chris@69: } Chris@69: