comparison widgets/PluginParameterDialog.cpp @ 163:dd6dd983e8ef

* Tidy up plugin parameter dialog by switching it to a simple constructor with separate methods for passing in the additional options if necessary * Fix sizing problem on advanced pane toggle in plugin parameter dialog * Make a start on passing in list of candidate input models for transform
author Chris Cannam
date Wed, 11 Oct 2006 16:18:51 +0000
parents 8c730f49b9b3
children 11949d0b2739
comparison
equal deleted inserted replaced
162:f32212631b9c 163:dd6dd983e8ef
31 #include <QMessageBox> 31 #include <QMessageBox>
32 #include <QComboBox> 32 #include <QComboBox>
33 #include <QSettings> 33 #include <QSettings>
34 34
35 PluginParameterDialog::PluginParameterDialog(Vamp::PluginBase *plugin, 35 PluginParameterDialog::PluginParameterDialog(Vamp::PluginBase *plugin,
36 int sourceChannels,
37 int targetChannels,
38 int defaultChannel,
39 QString output,
40 bool showWindowSize,
41 bool showFrequencyDomainOptions,
42 QWidget *parent) : 36 QWidget *parent) :
43 QDialog(parent), 37 QDialog(parent),
44 m_plugin(plugin), 38 m_plugin(plugin),
45 m_channel(defaultChannel), 39 m_channel(-1),
46 m_stepSize(0), 40 m_stepSize(0),
47 m_blockSize(0), 41 m_blockSize(0),
48 m_windowType(HanningWindow), 42 m_windowType(HanningWindow),
49 m_parameterBox(0) 43 m_parameterBox(0)
50 { 44 {
71 nameLabel->setFont(font); 65 nameLabel->setFont(font);
72 66
73 QLabel *makerLabel = new QLabel(plugin->getMaker().c_str()); 67 QLabel *makerLabel = new QLabel(plugin->getMaker().c_str());
74 makerLabel->setWordWrap(true); 68 makerLabel->setWordWrap(true);
75 69
70 QLabel *versionLabel = new QLabel(QString("%1")
71 .arg(plugin->getPluginVersion()));
72 versionLabel->setWordWrap(true);
73
74 QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str());
75 copyrightLabel->setWordWrap(true);
76
77 QLabel *typeLabel = new QLabel(plugin->getType().c_str());
78 typeLabel->setWordWrap(true);
79 typeLabel->setFont(font);
80
81 int row = 0;
82
83 QLabel *label = new QLabel(tr("Name:"));
84 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
85 subgrid->addWidget(label, row, 0);
86 subgrid->addWidget(nameLabel, row, 1);
87 row++;
88
89 label = new QLabel(tr("Type:"));
90 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
91 subgrid->addWidget(label, row, 0);
92 subgrid->addWidget(typeLabel, row, 1);
93 row++;
94
95 m_outputLabel = new QLabel(tr("Output:"));
96 m_outputLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
97 subgrid->addWidget(m_outputLabel, row, 0);
98 m_outputValue = new QLabel;
99 subgrid->addWidget(m_outputValue, row, 1);
100 m_outputLabel->hide();
101 m_outputValue->hide();
102 row++;
103
104 label = new QLabel(tr("Maker:"));
105 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
106 subgrid->addWidget(label, row, 0);
107 subgrid->addWidget(makerLabel, row, 1);
108 row++;
109
110 label = new QLabel(tr("Copyright: "));
111 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
112 subgrid->addWidget(label, row, 0);
113 subgrid->addWidget(copyrightLabel, row, 1);
114 row++;
115
116 label = new QLabel(tr("Version:"));
117 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
118 subgrid->addWidget(label, row, 0);
119 subgrid->addWidget(versionLabel, row, 1);
120 row++;
121
122 subgrid->setColumnStretch(1, 2);
123
124 QGroupBox *paramBox = new QGroupBox;
125 paramBox->setTitle(tr("Plugin Parameters"));
126 grid->addWidget(paramBox, 1, 0);
127 grid->setRowStretch(1, 10);
128
129 QHBoxLayout *paramLayout = new QHBoxLayout;
130 paramLayout->setMargin(0);
131 paramBox->setLayout(paramLayout);
132
133 QScrollArea *scroll = new QScrollArea;
134 scroll->setWidgetResizable(true);
135 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
136 scroll->setFrameShape(QFrame::NoFrame);
137 paramLayout->addWidget(scroll);
138
139 m_parameterBox = new PluginParameterBox(m_plugin);
140 connect(m_parameterBox, SIGNAL(pluginConfigurationChanged(QString)),
141 this, SIGNAL(pluginConfigurationChanged(QString)));
142 scroll->setWidget(m_parameterBox);
143
144 m_advanced = new QFrame;
145 QVBoxLayout *advancedLayout = new QVBoxLayout;
146 advancedLayout->setMargin(0);
147 m_advanced->setLayout(advancedLayout);
148 grid->addWidget(m_advanced, 2, 0);
149
150 bool haveAdvanced = false;
151
152 m_channelBox = new QGroupBox;
153 m_channelBox->setTitle(tr("Channels"));
154 advancedLayout->addWidget(m_channelBox);
155 m_channelBox->setVisible(false);
156 m_haveChannelBoxData = false;
157
158 m_windowBox = new QGroupBox;
159 m_windowBox->setTitle(tr("Processing"));
160 advancedLayout->addWidget(m_windowBox);
161 m_windowBox->setVisible(false);
162 m_haveWindowBoxData = false;
163
164 QHBoxLayout *hbox = new QHBoxLayout;
165 grid->addLayout(hbox, 4, 0);
166
167 m_advancedVisible = false;
168
169 m_advancedButton = new QPushButton(tr("Advanced >>"));
170 m_advancedButton->setCheckable(true);
171 connect(m_advancedButton, SIGNAL(clicked()), this, SLOT(advancedToggled()));
172
173 QSettings settings;
174 settings.beginGroup("PluginParameterDialog");
175 m_advancedVisible = settings.value("advancedvisible", false).toBool();
176 settings.endGroup();
177
178 m_advanced->setVisible(false);
179
180 hbox->addWidget(m_advancedButton);
181 m_advancedButton->hide();
182
183 QPushButton *ok = new QPushButton(tr("OK"));
184 QPushButton *cancel = new QPushButton(tr("Cancel"));
185 hbox->addStretch(10);
186 hbox->addWidget(ok);
187 hbox->addWidget(cancel);
188 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
189 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
190
191 setAdvancedVisible(m_advancedVisible);
192 }
193
194 PluginParameterDialog::~PluginParameterDialog()
195 {
196 }
197
198
199 void
200 PluginParameterDialog::setOutputLabel(QString text)
201 {
202 if (text == "") {
203 m_outputLabel->hide();
204 m_outputValue->hide();
205 } else {
206 m_outputValue->setText(text);
207 m_outputValue->setWordWrap(true);
208 m_outputLabel->show();
209 m_outputValue->show();
210 }
211 /*
76 QLabel *outputLabel = 0; 212 QLabel *outputLabel = 0;
77 213
78 if (output != "") { 214 if (output != "") {
79 215
80 Vamp::PluginHostAdapter *fePlugin = dynamic_cast<Vamp::PluginHostAdapter *>(m_plugin); 216 Vamp::PluginHostAdapter *fePlugin = dynamic_cast<Vamp::PluginHostAdapter *>(m_plugin);
94 } 230 }
95 } 231 }
96 } 232 }
97 } 233 }
98 } 234 }
99 235 */
100 QLabel *versionLabel = new QLabel(QString("%1") 236 }
101 .arg(plugin->getPluginVersion())); 237
102 versionLabel->setWordWrap(true); 238 void
103 239 PluginParameterDialog::setChannelArrangement(int sourceChannels,
104 QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str()); 240 int targetChannels,
105 copyrightLabel->setWordWrap(true); 241 int defaultChannel)
106 242 {
107 QLabel *typeLabel = new QLabel(plugin->getType().c_str()); 243 m_channel = defaultChannel;
108 typeLabel->setWordWrap(true);
109 typeLabel->setFont(font);
110
111 QLabel *label = new QLabel(tr("Name:"));
112 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
113 subgrid->addWidget(label, 0, 0);
114 subgrid->addWidget(nameLabel, 0, 1);
115
116 label = new QLabel(tr("Type:"));
117 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
118 subgrid->addWidget(label, 1, 0);
119 subgrid->addWidget(typeLabel, 1, 1);
120
121 int outputOffset = 0;
122 if (outputLabel) {
123 label = new QLabel(tr("Output:"));
124 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
125 subgrid->addWidget(label, 2, 0);
126 subgrid->addWidget(outputLabel, 2, 1);
127 outputOffset = 1;
128 }
129
130 label = new QLabel(tr("Maker:"));
131 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
132 subgrid->addWidget(label, 2 + outputOffset, 0);
133 subgrid->addWidget(makerLabel, 2 + outputOffset, 1);
134
135 label = new QLabel(tr("Copyright: "));
136 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
137 subgrid->addWidget(label, 3 + outputOffset, 0);
138 subgrid->addWidget(copyrightLabel, 3 + outputOffset, 1);
139
140 label = new QLabel(tr("Version:"));
141 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
142 subgrid->addWidget(label, 4 + outputOffset, 0);
143 subgrid->addWidget(versionLabel, 4 + outputOffset, 1);
144
145 subgrid->setColumnStretch(1, 2);
146
147 QGroupBox *paramBox = new QGroupBox;
148 paramBox->setTitle(tr("Plugin Parameters"));
149 grid->addWidget(paramBox, 1, 0);
150 grid->setRowStretch(1, 10);
151
152 QHBoxLayout *paramLayout = new QHBoxLayout;
153 paramLayout->setMargin(0);
154 paramBox->setLayout(paramLayout);
155
156 QScrollArea *scroll = new QScrollArea;
157 scroll->setWidgetResizable(true);
158 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
159 scroll->setFrameShape(QFrame::NoFrame);
160 paramLayout->addWidget(scroll);
161
162 m_parameterBox = new PluginParameterBox(m_plugin);
163 connect(m_parameterBox, SIGNAL(pluginConfigurationChanged(QString)),
164 this, SIGNAL(pluginConfigurationChanged(QString)));
165 scroll->setWidget(m_parameterBox);
166
167 m_advanced = new QFrame;
168 QVBoxLayout *advancedLayout = new QVBoxLayout;
169 advancedLayout->setMargin(0);
170 m_advanced->setLayout(advancedLayout);
171 grid->addWidget(m_advanced, 2, 0);
172
173 bool haveAdvanced = false;
174 244
175 if (sourceChannels != targetChannels) { 245 if (sourceChannels != targetChannels) {
176 246
177 // At the moment we can only cope with the case where 247 // At the moment we can only cope with the case where
178 // sourceChannels > targetChannels and targetChannels == 1 248 // sourceChannels > targetChannels and targetChannels == 1
179 249
180 if (sourceChannels < targetChannels) { 250 if (sourceChannels < targetChannels) {
181 251
182 QMessageBox::warning 252 QMessageBox::warning
183 (parent, 253 (parentWidget(),
184 tr("Channel mismatch"), 254 tr("Channel mismatch"),
185 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")), 255 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")),
186 QMessageBox::Ok, 256 QMessageBox::Ok,
187 QMessageBox::NoButton); 257 QMessageBox::NoButton);
188 258
189 } else { 259 } else {
190 260
191 QGroupBox *channelBox = new QGroupBox; 261 if (m_haveChannelBoxData) {
192 channelBox->setTitle(tr("Channels")); 262 std::cerr << "WARNING: PluginParameterDialog::setChannelArrangement: Calling more than once on same dialog is not currently implemented" << std::endl;
193 advancedLayout->addWidget(channelBox); 263 return;
194 haveAdvanced = true; 264 }
195 265
196 QVBoxLayout *channelLayout = new QVBoxLayout; 266 QVBoxLayout *channelLayout = new QVBoxLayout;
197 channelBox->setLayout(channelLayout); 267 m_channelBox->setLayout(channelLayout);
198 268
199 if (targetChannels != 1) { 269 if (targetChannels != 1) {
200 270
201 channelLayout->addWidget 271 channelLayout->addWidget
202 (new QLabel(tr("This plugin accepts no more than %1 input channels,\nbut %2 are available. Only the first %3 will be used.\n") 272 (new QLabel(tr("This plugin accepts no more than %1 input channels,\nbut %2 are available. Only the first %3 will be used.\n")
217 connect(channelCombo, SIGNAL(activated(int)), 287 connect(channelCombo, SIGNAL(activated(int)),
218 this, SLOT(channelComboChanged(int))); 288 this, SLOT(channelComboChanged(int)));
219 289
220 channelLayout->addWidget(channelCombo); 290 channelLayout->addWidget(channelCombo);
221 } 291 }
222 } 292
293 m_channelBox->setVisible(true);
294 m_haveChannelBoxData = true;
295 m_advancedButton->show();
296 }
297 }
298
299 setAdvancedVisible(m_advancedVisible);
300 }
301
302 void
303 PluginParameterDialog::setShowProcessingOptions(bool showWindowSize,
304 bool showFrequencyDomainOptions)
305 {
306 if (m_haveWindowBoxData) {
307 std::cerr << "WARNING: PluginParameterDialog::setShowProcessingOptions: Calling more than once on same dialog is not currently implemented" << std::endl;
308 return;
223 } 309 }
224 310
225 if (showWindowSize) { 311 if (showWindowSize) {
226 312
227 Vamp::PluginHostAdapter *fePlugin = dynamic_cast<Vamp::PluginHostAdapter *>(m_plugin); 313 Vamp::PluginHostAdapter *fePlugin = dynamic_cast<Vamp::PluginHostAdapter *>(m_plugin);
237 increment = size; 323 increment = size;
238 } else { 324 } else {
239 increment = size/2; 325 increment = size/2;
240 } 326 }
241 } 327 }
242 } else { 328 }
243 std::cerr << "Plugin " << plugin << " is not a feature extraction plugin (it's a " << typeid(*plugin).name() << ")" << std::endl;//!!!
244 }
245
246 QGroupBox *windowBox = new QGroupBox;
247 windowBox->setTitle(tr("Processing"));
248 advancedLayout->addWidget(windowBox);
249 haveAdvanced = true;
250 329
251 QGridLayout *windowLayout = new QGridLayout; 330 QGridLayout *windowLayout = new QGridLayout;
252 windowBox->setLayout(windowLayout); 331 m_windowBox->setLayout(windowLayout);
253 332
254 if (showFrequencyDomainOptions) { 333 if (showFrequencyDomainOptions) {
255 windowLayout->addWidget(new QLabel(tr("Window size:")), 0, 0); 334 windowLayout->addWidget(new QLabel(tr("Window size:")), 0, 0);
256 } else { 335 } else {
257 windowLayout->addWidget(new QLabel(tr("Audio frames per block:")), 0, 0); 336 windowLayout->addWidget(new QLabel(tr("Audio frames per block:")), 0, 0);
258 } 337 }
259 338
260 std::cerr << "size: " << size << ", increment: " << increment << std::endl; 339 std::cerr << "size: " << size << ", increment: " << increment << std::endl;
261
262 //!!! deal with block and step sizes (coming from the plugin's
263 // preferences) that don't fit into the default list
264 340
265 QComboBox *blockSizeCombo = new QComboBox; 341 QComboBox *blockSizeCombo = new QComboBox;
266 blockSizeCombo->setEditable(true); 342 blockSizeCombo->setEditable(true);
267 bool found = false; 343 bool found = false;
268 for (int i = 0; i < 14; ++i) { 344 for (int i = 0; i < 14; ++i) {
310 WindowTypeSelector *windowTypeSelector = new WindowTypeSelector; 386 WindowTypeSelector *windowTypeSelector = new WindowTypeSelector;
311 connect(windowTypeSelector, SIGNAL(windowTypeChanged(WindowType type)), 387 connect(windowTypeSelector, SIGNAL(windowTypeChanged(WindowType type)),
312 this, SLOT(windowTypeChanged(type))); 388 this, SLOT(windowTypeChanged(type)));
313 windowLayout->addWidget(windowTypeSelector, 2, 1); 389 windowLayout->addWidget(windowTypeSelector, 2, 1);
314 } 390 }
315 } 391
316 392 m_windowBox->setVisible(true);
317 QHBoxLayout *hbox = new QHBoxLayout; 393 m_haveWindowBoxData = true;
318 grid->addLayout(hbox, 4, 0); 394 m_advancedButton->show();
319 395 }
320 bool advancedVisible = false; 396
321 397 setAdvancedVisible(m_advancedVisible);
322 if (haveAdvanced) {
323
324 m_advancedButton = new QPushButton(tr("Advanced >>"));
325 m_advancedButton->setCheckable(true);
326 connect(m_advancedButton, SIGNAL(clicked()), this, SLOT(advancedToggled()));
327
328 QSettings settings;
329 settings.beginGroup("PluginParameterDialog");
330 advancedVisible = settings.value("advancedvisible", false).toBool();
331 settings.endGroup();
332
333 m_advanced->setVisible(false);
334
335 hbox->addWidget(m_advancedButton);
336 }
337
338 QPushButton *ok = new QPushButton(tr("OK"));
339 QPushButton *cancel = new QPushButton(tr("Cancel"));
340 hbox->addStretch(10);
341 hbox->addWidget(ok);
342 hbox->addWidget(cancel);
343 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
344 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
345
346 if (advancedVisible) {
347 m_advancedButton->setChecked(true);
348 advancedToggled();
349 }
350 }
351
352 PluginParameterDialog::~PluginParameterDialog()
353 {
354 } 398 }
355 399
356 void 400 void
357 PluginParameterDialog::getProcessingParameters(size_t &blockSize) const 401 PluginParameterDialog::getProcessingParameters(size_t &blockSize) const
358 { 402 {
393 } 437 }
394 438
395 void 439 void
396 PluginParameterDialog::advancedToggled() 440 PluginParameterDialog::advancedToggled()
397 { 441 {
398 bool visible = !m_advanced->isVisible(); 442 setAdvancedVisible(!m_advancedVisible);
399 443 }
444
445 void
446 PluginParameterDialog::setAdvancedVisible(bool visible)
447 {
400 m_advanced->setVisible(visible); 448 m_advanced->setVisible(visible);
401 449
402 if (visible) m_advancedButton->setText(tr("Advanced <<")); 450 if (visible) {
403 else m_advancedButton->setText(tr("Advanced >>")); 451 m_advancedButton->setText(tr("Advanced <<"));
452 m_advancedButton->setChecked(true);
453 } else {
454 m_advancedButton->setText(tr("Advanced >>"));
455 m_advancedButton->setChecked(false);
456 }
404 457
405 QSettings settings; 458 QSettings settings;
406 settings.beginGroup("PluginParameterDialog"); 459 settings.beginGroup("PluginParameterDialog");
407 settings.setValue("advancedvisible", visible); 460 settings.setValue("advancedvisible", visible);
408 settings.endGroup(); 461 settings.endGroup();
409 462
410 std::cerr << "resize to " << sizeHint().width() << " x " << sizeHint().height() << std::endl; 463 std::cerr << "resize to " << sizeHint().width() << " x " << sizeHint().height() << std::endl;
411 464
412 setMinimumHeight(sizeHint().height()); 465 setMinimumHeight(sizeHint().height());
413 if (visible) setMaximumHeight(sizeHint().height()); 466 adjustSize();
467
468 m_advancedVisible = visible;
469
470 // if (visible) setMaximumHeight(sizeHint().height());
471 // adjustSize();
414 } 472 }
415 473
416 void 474 void
417 PluginParameterDialog::channelComboChanged(int index) 475 PluginParameterDialog::channelComboChanged(int index)
418 { 476 {