annotate widgets/PluginParameterDialog.cpp @ 96:095916d7ed4d

* tuning tweaks
author Chris Cannam
date Tue, 09 May 2006 20:39:23 +0000
parents 45ba0b381c5d
children 551d7ae05526
rev   line source
Chris@62 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@62 2
Chris@62 3 /*
Chris@62 4 Sonic Visualiser
Chris@62 5 An audio file viewer and annotation editor.
Chris@62 6 Centre for Digital Music, Queen Mary, University of London.
Chris@62 7 This file copyright 2006 Chris Cannam.
Chris@62 8
Chris@62 9 This program is free software; you can redistribute it and/or
Chris@62 10 modify it under the terms of the GNU General Public License as
Chris@62 11 published by the Free Software Foundation; either version 2 of the
Chris@62 12 License, or (at your option) any later version. See the file
Chris@62 13 COPYING included with this distribution for more information.
Chris@62 14 */
Chris@62 15
Chris@62 16 #include "PluginParameterDialog.h"
Chris@62 17
Chris@62 18 #include "PluginParameterBox.h"
Chris@62 19
Chris@62 20 #include <QGridLayout>
Chris@62 21 #include <QLabel>
Chris@62 22 #include <QGroupBox>
Chris@62 23 #include <QHBoxLayout>
Chris@62 24 #include <QPushButton>
Chris@69 25 #include <QMessageBox>
Chris@69 26 #include <QComboBox>
Chris@62 27
Chris@71 28 PluginParameterDialog::PluginParameterDialog(Vamp::PluginBase *plugin,
Chris@69 29 int sourceChannels,
Chris@69 30 int targetChannels,
Chris@69 31 int defaultChannel,
Chris@62 32 QWidget *parent) :
Chris@62 33 QDialog(parent),
Chris@62 34 m_plugin(plugin),
Chris@69 35 m_channel(defaultChannel),
Chris@62 36 m_parameterBox(0)
Chris@62 37 {
Chris@62 38 QGridLayout *grid = new QGridLayout;
Chris@62 39 setLayout(grid);
Chris@62 40
Chris@62 41 QGroupBox *pluginBox = new QGroupBox;
Chris@62 42 pluginBox->setTitle(tr("Plugin"));
Chris@62 43 grid->addWidget(pluginBox, 0, 0);
Chris@62 44
Chris@62 45 QGridLayout *subgrid = new QGridLayout;
Chris@62 46 pluginBox->setLayout(subgrid);
Chris@62 47
Chris@63 48 subgrid->setSpacing(0);
Chris@63 49 subgrid->setMargin(10);
Chris@63 50
Chris@62 51 QFont font(pluginBox->font());
Chris@62 52 font.setBold(true);
Chris@62 53
Chris@62 54 QLabel *nameLabel = new QLabel(plugin->getDescription().c_str());
Chris@62 55 nameLabel->setFont(font);
Chris@62 56
Chris@62 57 QLabel *makerLabel = new QLabel(plugin->getMaker().c_str());
Chris@62 58
Chris@62 59 QLabel *versionLabel = new QLabel(QString("%1")
Chris@62 60 .arg(plugin->getPluginVersion()));
Chris@62 61
Chris@62 62 QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str());
Chris@62 63
Chris@63 64 QLabel *typeLabel = new QLabel(plugin->getType().c_str());
Chris@63 65 typeLabel->setFont(font);
Chris@63 66
Chris@62 67 subgrid->addWidget(new QLabel(tr("Name:")), 0, 0);
Chris@62 68 subgrid->addWidget(nameLabel, 0, 1);
Chris@62 69
Chris@63 70 subgrid->addWidget(new QLabel(tr("Type:")), 1, 0);
Chris@63 71 subgrid->addWidget(typeLabel, 1, 1);
Chris@62 72
Chris@63 73 subgrid->addWidget(new QLabel(tr("Maker:")), 2, 0);
Chris@63 74 subgrid->addWidget(makerLabel, 2, 1);
Chris@62 75
Chris@63 76 subgrid->addWidget(new QLabel(tr("Copyright: ")), 3, 0);
Chris@63 77 subgrid->addWidget(copyrightLabel, 3, 1);
Chris@63 78
Chris@63 79 subgrid->addWidget(new QLabel(tr("Version:")), 4, 0);
Chris@63 80 subgrid->addWidget(versionLabel, 4, 1);
Chris@62 81
Chris@62 82 subgrid->setColumnStretch(1, 2);
Chris@62 83
Chris@62 84 QGroupBox *paramBox = new QGroupBox;
Chris@62 85 paramBox->setTitle(tr("Plugin Parameters"));
Chris@62 86 grid->addWidget(paramBox, 1, 0);
Chris@62 87 grid->setRowStretch(1, 10);
Chris@62 88
Chris@62 89 QHBoxLayout *paramLayout = new QHBoxLayout;
Chris@63 90 paramLayout->setMargin(0);
Chris@62 91 paramBox->setLayout(paramLayout);
Chris@62 92
Chris@62 93 m_parameterBox = new PluginParameterBox(m_plugin);
Chris@64 94 connect(m_parameterBox, SIGNAL(pluginConfigurationChanged(QString)),
Chris@64 95 this, SIGNAL(pluginConfigurationChanged(QString)));
Chris@62 96 paramLayout->addWidget(m_parameterBox);
Chris@62 97
Chris@69 98 if (sourceChannels != targetChannels) {
Chris@69 99
Chris@69 100 // At the moment we can only cope with the case where
Chris@69 101 // sourceChannels > targetChannels and targetChannels == 1
Chris@69 102
Chris@69 103 if (sourceChannels < targetChannels) {
Chris@69 104
Chris@69 105 QMessageBox::warning
Chris@69 106 (parent,
Chris@69 107 tr("Channel mismatch"),
Chris@69 108 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 109 QMessageBox::Ok,
Chris@69 110 QMessageBox::NoButton);
Chris@69 111
Chris@69 112 } else {
Chris@69 113
Chris@69 114 QGroupBox *channelBox = new QGroupBox;
Chris@69 115 channelBox->setTitle(tr("Channels"));
Chris@69 116 grid->addWidget(channelBox, 2, 0);
Chris@69 117
Chris@69 118 QVBoxLayout *channelLayout = new QVBoxLayout;
Chris@69 119 channelBox->setLayout(channelLayout);
Chris@69 120
Chris@69 121 if (targetChannels != 1) {
Chris@69 122
Chris@69 123 channelLayout->addWidget
Chris@69 124 (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 125 .arg(targetChannels)
Chris@69 126 .arg(sourceChannels)
Chris@69 127 .arg(targetChannels)));
Chris@69 128
Chris@69 129 } else {
Chris@69 130
Chris@69 131 channelLayout->addWidget(new QLabel(tr("This plugin only has a single channel input,\nbut the source has %1 channels.").arg(sourceChannels)));
Chris@69 132
Chris@69 133 QComboBox *channelCombo = new QComboBox;
Chris@76 134 channelCombo->addItem(tr("Use mean of source channels"));
Chris@69 135 for (int i = 0; i < sourceChannels; ++i) {
Chris@69 136 channelCombo->addItem(tr("Use channel %1 only").arg(i + 1));
Chris@69 137 }
Chris@69 138
Chris@69 139 connect(channelCombo, SIGNAL(activated(int)),
Chris@69 140 this, SLOT(channelComboChanged(int)));
Chris@69 141
Chris@69 142 channelLayout->addWidget(channelCombo);
Chris@69 143 }
Chris@69 144 }
Chris@69 145 }
Chris@69 146
Chris@62 147 QHBoxLayout *hbox = new QHBoxLayout;
Chris@69 148 grid->addLayout(hbox, 3, 0);
Chris@62 149
Chris@62 150 QPushButton *ok = new QPushButton(tr("OK"));
Chris@62 151 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@62 152 hbox->addStretch(10);
Chris@62 153 hbox->addWidget(ok);
Chris@62 154 hbox->addWidget(cancel);
Chris@62 155 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@62 156 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@62 157 }
Chris@62 158
Chris@62 159 PluginParameterDialog::~PluginParameterDialog()
Chris@62 160 {
Chris@62 161 }
Chris@62 162
Chris@69 163 void
Chris@69 164 PluginParameterDialog::channelComboChanged(int index)
Chris@69 165 {
Chris@69 166 m_channel = index - 1;
Chris@69 167 }
Chris@69 168