annotate widgets/PluginParameterDialog.cpp @ 454:e2a40fdadd8c

Various fixes: * Fix handling of HTTP redirects (avoiding crashes... I hope) * Fix failure to delete FFT models when a feature extraction model transformer was abandoned (also a cause of crashes in the past) * Fix deadlock when said transform was abandoned before its source model was ready because the session was being cleared (and so the source model would never be ready)
author Chris Cannam
date Fri, 28 Nov 2008 13:36:13 +0000
parents c803eb18ebba
children 035d62c4cddf
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@182 7 This file copyright 2006 Chris Cannam and QMUL.
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@140 19 #include "WindowTypeSelector.h"
Chris@62 20
Chris@376 21 #include "TextAbbrev.h"
Chris@440 22 #include "IconLoader.h"
Chris@294 23
Chris@442 24 #include <vamp-hostsdk/Plugin.h>
Chris@442 25 #include <vamp-hostsdk/PluginHostAdapter.h>
Chris@442 26 #include <vamp-hostsdk/PluginWrapper.h>
Chris@106 27
Chris@62 28 #include <QGridLayout>
Chris@62 29 #include <QLabel>
Chris@62 30 #include <QGroupBox>
Chris@62 31 #include <QHBoxLayout>
Chris@143 32 #include <QVBoxLayout>
Chris@149 33 #include <QScrollArea>
Chris@62 34 #include <QPushButton>
Chris@69 35 #include <QMessageBox>
Chris@69 36 #include <QComboBox>
Chris@302 37 #include <QCheckBox>
Chris@143 38 #include <QSettings>
Chris@282 39 #include <QDialogButtonBox>
Chris@440 40 #include <QDesktopServices>
Chris@440 41 #include <QUrl>
Chris@62 42
Chris@71 43 PluginParameterDialog::PluginParameterDialog(Vamp::PluginBase *plugin,
Chris@62 44 QWidget *parent) :
Chris@62 45 QDialog(parent),
Chris@62 46 m_plugin(plugin),
Chris@163 47 m_channel(-1),
Chris@145 48 m_stepSize(0),
Chris@145 49 m_blockSize(0),
Chris@145 50 m_windowType(HanningWindow),
Chris@302 51 m_parameterBox(0),
Chris@302 52 m_selectionOnly(false)
Chris@62 53 {
Chris@122 54 setWindowTitle(tr("Plugin Parameters"));
Chris@122 55
Chris@62 56 QGridLayout *grid = new QGridLayout;
Chris@62 57 setLayout(grid);
Chris@62 58
Chris@62 59 QGroupBox *pluginBox = new QGroupBox;
Chris@208 60 pluginBox->setTitle(plugin->getType().c_str());
Chris@62 61 grid->addWidget(pluginBox, 0, 0);
Chris@62 62
Chris@62 63 QGridLayout *subgrid = new QGridLayout;
Chris@62 64 pluginBox->setLayout(subgrid);
Chris@62 65
Chris@63 66 subgrid->setSpacing(0);
Chris@63 67 subgrid->setMargin(10);
Chris@63 68
Chris@208 69 QFont boldFont(pluginBox->font());
Chris@208 70 boldFont.setBold(true);
Chris@208 71
Chris@208 72 QFont italicFont(pluginBox->font());
Chris@208 73 italicFont.setItalic(true);
Chris@62 74
Chris@207 75 QLabel *nameLabel = new QLabel(plugin->getName().c_str());
Chris@146 76 nameLabel->setWordWrap(true);
Chris@208 77 nameLabel->setFont(boldFont);
Chris@62 78
Chris@62 79 QLabel *makerLabel = new QLabel(plugin->getMaker().c_str());
Chris@146 80 makerLabel->setWordWrap(true);
Chris@62 81
Chris@441 82 int version = plugin->getPluginVersion();
Chris@441 83 QLabel *versionLabel = new QLabel(QString("%1").arg(version));
Chris@146 84 versionLabel->setWordWrap(true);
Chris@62 85
Chris@62 86 QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str());
Chris@146 87 copyrightLabel->setWordWrap(true);
Chris@62 88
Chris@208 89 // QLabel *typeLabel = new QLabel(plugin->getType().c_str());
Chris@208 90 // typeLabel->setWordWrap(true);
Chris@208 91 // typeLabel->setFont(boldFont);
Chris@208 92
Chris@208 93 QLabel *descriptionLabel = 0;
Chris@208 94 if (plugin->getDescription() != "") {
Chris@208 95 descriptionLabel = new QLabel(plugin->getDescription().c_str());
Chris@208 96 descriptionLabel->setWordWrap(true);
Chris@208 97 descriptionLabel->setFont(italicFont);
Chris@208 98 }
Chris@63 99
Chris@163 100 int row = 0;
Chris@163 101
Chris@147 102 QLabel *label = new QLabel(tr("Name:"));
Chris@147 103 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Chris@163 104 subgrid->addWidget(label, row, 0);
Chris@163 105 subgrid->addWidget(nameLabel, row, 1);
Chris@440 106
Chris@440 107 m_moreInfo = new QPushButton;
Chris@440 108 m_moreInfo->setIcon(IconLoader().load("info"));
Chris@440 109 m_moreInfo->setFixedSize(QSize(16, 16));
Chris@440 110 connect(m_moreInfo, SIGNAL(clicked()), this, SLOT(moreInfo()));
Chris@440 111 subgrid->addWidget(m_moreInfo, row, 2, Qt::AlignTop | Qt::AlignRight);
Chris@440 112 m_moreInfo->hide();
Chris@440 113
Chris@163 114 row++;
Chris@62 115
Chris@208 116 if (descriptionLabel) {
Chris@208 117 // label = new QLabel(tr("Description:"));
Chris@208 118 // label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Chris@208 119 // subgrid->addWidget(label, row, 0);
Chris@440 120 subgrid->addWidget(descriptionLabel, row, 1, 1, 2);
Chris@208 121 row++;
Chris@208 122 }
Chris@208 123
Chris@441 124 if (version >= 0) {
Chris@208 125 label = new QLabel(tr("Version:"));
Chris@208 126 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Chris@208 127 subgrid->addWidget(label, row, 0);
Chris@208 128 subgrid->addWidget(versionLabel, row, 1);
Chris@208 129 row++;
Chris@208 130 }
Chris@208 131
Chris@208 132 // label = new QLabel(tr("Type:"));
Chris@208 133 // label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Chris@208 134 // subgrid->addWidget(label, row, 0);
Chris@208 135 // subgrid->addWidget(typeLabel, row, 1);
Chris@208 136 // row++;
Chris@62 137
Chris@147 138 label = new QLabel(tr("Maker:"));
Chris@147 139 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Chris@163 140 subgrid->addWidget(label, row, 0);
Chris@163 141 subgrid->addWidget(makerLabel, row, 1);
Chris@163 142 row++;
Chris@63 143
Chris@147 144 label = new QLabel(tr("Copyright: "));
Chris@147 145 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Chris@163 146 subgrid->addWidget(label, row, 0);
Chris@163 147 subgrid->addWidget(copyrightLabel, row, 1);
Chris@163 148 row++;
Chris@208 149
Chris@208 150 m_outputSpacer = new QLabel;
Chris@208 151 subgrid->addWidget(m_outputSpacer, row, 0);
Chris@208 152 m_outputSpacer->setFixedHeight(7);
Chris@208 153 m_outputSpacer->hide();
Chris@208 154 row++;
Chris@106 155
Chris@208 156 m_outputLabel = new QLabel(tr("Output:"));
Chris@208 157 m_outputLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Chris@208 158 subgrid->addWidget(m_outputLabel, row, 0);
Chris@208 159 m_outputValue = new QLabel;
Chris@208 160 m_outputValue->setFont(boldFont);
Chris@208 161 subgrid->addWidget(m_outputValue, row, 1);
Chris@208 162 m_outputLabel->hide();
Chris@208 163 m_outputValue->hide();
Chris@208 164 row++;
Chris@208 165
Chris@208 166 m_outputDescription = new QLabel;
Chris@208 167 m_outputDescription->setFont(italicFont);
Chris@208 168 subgrid->addWidget(m_outputDescription, row, 1);
Chris@208 169 m_outputDescription->hide();
Chris@163 170 row++;
Chris@62 171
Chris@62 172 subgrid->setColumnStretch(1, 2);
Chris@62 173
Chris@164 174 m_inputModelBox = new QGroupBox;
Chris@302 175 m_inputModelBox->setTitle(tr("Input Material"));
Chris@164 176 grid->addWidget(m_inputModelBox, 1, 0);
Chris@164 177
Chris@164 178 m_inputModels = new QComboBox;
Chris@302 179 QVBoxLayout *inputLayout = new QVBoxLayout;
Chris@164 180 m_inputModelBox->setLayout(inputLayout);
Chris@164 181 inputLayout->addWidget(m_inputModels);
Chris@302 182 m_inputModels->hide();
Chris@302 183
Chris@302 184 m_selectionOnly = new QCheckBox(tr("Restrict to selection extents"));
Chris@302 185 inputLayout->addWidget(m_selectionOnly);
Chris@302 186 m_selectionOnly->hide();
Chris@302 187
Chris@164 188 m_inputModelBox->hide();
Chris@164 189
Chris@62 190 QGroupBox *paramBox = new QGroupBox;
Chris@62 191 paramBox->setTitle(tr("Plugin Parameters"));
Chris@164 192 grid->addWidget(paramBox, 2, 0);
Chris@164 193 grid->setRowStretch(2, 10);
Chris@62 194
Chris@62 195 QHBoxLayout *paramLayout = new QHBoxLayout;
Chris@63 196 paramLayout->setMargin(0);
Chris@62 197 paramBox->setLayout(paramLayout);
Chris@62 198
Chris@149 199 QScrollArea *scroll = new QScrollArea;
Chris@149 200 scroll->setWidgetResizable(true);
Chris@149 201 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Chris@149 202 scroll->setFrameShape(QFrame::NoFrame);
Chris@149 203 paramLayout->addWidget(scroll);
Chris@149 204
Chris@62 205 m_parameterBox = new PluginParameterBox(m_plugin);
Chris@64 206 connect(m_parameterBox, SIGNAL(pluginConfigurationChanged(QString)),
Chris@64 207 this, SIGNAL(pluginConfigurationChanged(QString)));
Chris@149 208 scroll->setWidget(m_parameterBox);
Chris@62 209
Chris@143 210 m_advanced = new QFrame;
Chris@143 211 QVBoxLayout *advancedLayout = new QVBoxLayout;
Chris@143 212 advancedLayout->setMargin(0);
Chris@143 213 m_advanced->setLayout(advancedLayout);
Chris@164 214 grid->addWidget(m_advanced, 3, 0);
Chris@143 215
Chris@163 216 m_channelBox = new QGroupBox;
Chris@163 217 m_channelBox->setTitle(tr("Channels"));
Chris@163 218 advancedLayout->addWidget(m_channelBox);
Chris@163 219 m_channelBox->setVisible(false);
Chris@163 220 m_haveChannelBoxData = false;
Chris@163 221
Chris@163 222 m_windowBox = new QGroupBox;
Chris@163 223 m_windowBox->setTitle(tr("Processing"));
Chris@163 224 advancedLayout->addWidget(m_windowBox);
Chris@163 225 m_windowBox->setVisible(false);
Chris@163 226 m_haveWindowBoxData = false;
Chris@163 227
Chris@163 228 QHBoxLayout *hbox = new QHBoxLayout;
Chris@163 229 grid->addLayout(hbox, 4, 0);
Chris@163 230
Chris@163 231 m_advancedVisible = false;
Chris@163 232
Chris@163 233 m_advancedButton = new QPushButton(tr("Advanced >>"));
Chris@163 234 m_advancedButton->setCheckable(true);
Chris@163 235 connect(m_advancedButton, SIGNAL(clicked()), this, SLOT(advancedToggled()));
Chris@163 236
Chris@163 237 QSettings settings;
Chris@163 238 settings.beginGroup("PluginParameterDialog");
Chris@163 239 m_advancedVisible = settings.value("advancedvisible", false).toBool();
Chris@163 240 settings.endGroup();
Chris@163 241
Chris@163 242 m_advanced->setVisible(false);
Chris@163 243
Chris@163 244 hbox->addWidget(m_advancedButton);
Chris@163 245 m_advancedButton->hide();
Chris@163 246
Chris@282 247 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@282 248 QDialogButtonBox::Cancel);
Chris@282 249 hbox->addWidget(bb);
Chris@294 250 connect(bb, SIGNAL(accepted()), this, SLOT(dialogAccepted()));
Chris@282 251 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
Chris@163 252
Chris@163 253 setAdvancedVisible(m_advancedVisible);
Chris@163 254 }
Chris@163 255
Chris@163 256 PluginParameterDialog::~PluginParameterDialog()
Chris@163 257 {
Chris@163 258 }
Chris@163 259
Chris@163 260
Chris@163 261 void
Chris@208 262 PluginParameterDialog::setOutputLabel(QString text,
Chris@208 263 QString description)
Chris@163 264 {
Chris@163 265 if (text == "") {
Chris@208 266 m_outputSpacer->hide();
Chris@163 267 m_outputLabel->hide();
Chris@163 268 m_outputValue->hide();
Chris@208 269 m_outputDescription->hide();
Chris@163 270 } else {
Chris@208 271 m_outputSpacer->show();
Chris@163 272 m_outputValue->setText(text);
Chris@163 273 m_outputValue->setWordWrap(true);
Chris@208 274 m_outputDescription->setText(description);
Chris@309 275 m_outputDescription->setWordWrap(true);
Chris@163 276 m_outputLabel->show();
Chris@163 277 m_outputValue->show();
Chris@208 278 if (description != "") {
Chris@208 279 m_outputDescription->show();
Chris@208 280 } else {
Chris@208 281 m_outputDescription->hide();
Chris@208 282 }
Chris@163 283 }
Chris@163 284 }
Chris@163 285
Chris@163 286 void
Chris@440 287 PluginParameterDialog::setMoreInfoUrl(QString moreInfoUrl)
Chris@440 288 {
Chris@440 289 m_moreInfoUrl = moreInfoUrl;
Chris@440 290 if (m_moreInfoUrl != "") {
Chris@440 291 m_moreInfo->show();
Chris@440 292 } else {
Chris@440 293 m_moreInfo->hide();
Chris@440 294 }
Chris@440 295 }
Chris@440 296
Chris@440 297 void
Chris@163 298 PluginParameterDialog::setChannelArrangement(int sourceChannels,
Chris@163 299 int targetChannels,
Chris@163 300 int defaultChannel)
Chris@163 301 {
Chris@163 302 m_channel = defaultChannel;
Chris@163 303
Chris@69 304 if (sourceChannels != targetChannels) {
Chris@69 305
Chris@69 306 // At the moment we can only cope with the case where
Chris@69 307 // sourceChannels > targetChannels and targetChannels == 1
Chris@69 308
Chris@69 309 if (sourceChannels < targetChannels) {
Chris@69 310
Chris@69 311 QMessageBox::warning
Chris@163 312 (parentWidget(),
Chris@69 313 tr("Channel mismatch"),
Chris@69 314 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 315 QMessageBox::Ok,
Chris@69 316 QMessageBox::NoButton);
Chris@69 317
Chris@69 318 } else {
Chris@69 319
Chris@163 320 if (m_haveChannelBoxData) {
Chris@163 321 std::cerr << "WARNING: PluginParameterDialog::setChannelArrangement: Calling more than once on same dialog is not currently implemented" << std::endl;
Chris@163 322 return;
Chris@163 323 }
Chris@69 324
Chris@69 325 QVBoxLayout *channelLayout = new QVBoxLayout;
Chris@163 326 m_channelBox->setLayout(channelLayout);
Chris@69 327
Chris@69 328 if (targetChannels != 1) {
Chris@69 329
Chris@69 330 channelLayout->addWidget
Chris@69 331 (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 332 .arg(targetChannels)
Chris@69 333 .arg(sourceChannels)
Chris@69 334 .arg(targetChannels)));
Chris@69 335
Chris@69 336 } else {
Chris@69 337
Chris@69 338 channelLayout->addWidget(new QLabel(tr("This plugin only has a single channel input,\nbut the source has %1 channels.").arg(sourceChannels)));
Chris@69 339
Chris@69 340 QComboBox *channelCombo = new QComboBox;
Chris@76 341 channelCombo->addItem(tr("Use mean of source channels"));
Chris@69 342 for (int i = 0; i < sourceChannels; ++i) {
Chris@69 343 channelCombo->addItem(tr("Use channel %1 only").arg(i + 1));
Chris@69 344 }
Chris@69 345
Chris@69 346 connect(channelCombo, SIGNAL(activated(int)),
Chris@69 347 this, SLOT(channelComboChanged(int)));
Chris@69 348
Chris@69 349 channelLayout->addWidget(channelCombo);
Chris@69 350 }
Chris@163 351
Chris@163 352 m_channelBox->setVisible(true);
Chris@163 353 m_haveChannelBoxData = true;
Chris@163 354 m_advancedButton->show();
Chris@69 355 }
Chris@69 356 }
Chris@69 357
Chris@163 358 setAdvancedVisible(m_advancedVisible);
Chris@163 359 }
Chris@163 360
Chris@163 361 void
Chris@163 362 PluginParameterDialog::setShowProcessingOptions(bool showWindowSize,
Chris@163 363 bool showFrequencyDomainOptions)
Chris@163 364 {
Chris@163 365 if (m_haveWindowBoxData) {
Chris@163 366 std::cerr << "WARNING: PluginParameterDialog::setShowProcessingOptions: Calling more than once on same dialog is not currently implemented" << std::endl;
Chris@163 367 return;
Chris@163 368 }
Chris@163 369
Chris@140 370 if (showWindowSize) {
Chris@140 371
Chris@309 372 Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(m_plugin);
Chris@309 373 if (!fePlugin) fePlugin = dynamic_cast<Vamp::PluginHostAdapter *>(m_plugin);
Chris@309 374 if (!fePlugin) fePlugin = dynamic_cast<Vamp::HostExt::PluginWrapper *>(m_plugin);
Chris@140 375 int size = 1024;
Chris@140 376 int increment = 1024;
Chris@140 377 if (fePlugin) {
Chris@140 378 size = fePlugin->getPreferredBlockSize();
Chris@207 379 std::cerr << "Feature extraction plugin \"" << fePlugin->getName() << "\" reports preferred block size as " << size << std::endl;
Chris@140 380 if (size == 0) size = 1024;
Chris@140 381 increment = fePlugin->getPreferredStepSize();
Chris@146 382 if (increment == 0) {
Chris@146 383 if (fePlugin->getInputDomain() == Vamp::Plugin::TimeDomain) {
Chris@146 384 increment = size;
Chris@146 385 } else {
Chris@146 386 increment = size/2;
Chris@146 387 }
Chris@146 388 }
Chris@140 389 }
Chris@140 390
Chris@140 391 QGridLayout *windowLayout = new QGridLayout;
Chris@163 392 m_windowBox->setLayout(windowLayout);
Chris@140 393
Chris@140 394 if (showFrequencyDomainOptions) {
Chris@140 395 windowLayout->addWidget(new QLabel(tr("Window size:")), 0, 0);
Chris@140 396 } else {
Chris@140 397 windowLayout->addWidget(new QLabel(tr("Audio frames per block:")), 0, 0);
Chris@140 398 }
Chris@140 399
Chris@143 400 std::cerr << "size: " << size << ", increment: " << increment << std::endl;
Chris@143 401
Chris@140 402 QComboBox *blockSizeCombo = new QComboBox;
Chris@140 403 blockSizeCombo->setEditable(true);
Chris@147 404 bool found = false;
Chris@143 405 for (int i = 0; i < 14; ++i) {
Chris@249 406 int val = 1 << (i + 3);
Chris@140 407 blockSizeCombo->addItem(QString("%1").arg(val));
Chris@147 408 if (val == size) {
Chris@147 409 blockSizeCombo->setCurrentIndex(i);
Chris@147 410 found = true;
Chris@147 411 }
Chris@147 412 }
Chris@147 413 if (!found) {
Chris@147 414 blockSizeCombo->addItem(QString("%1").arg(size));
Chris@147 415 blockSizeCombo->setCurrentIndex(blockSizeCombo->count() - 1);
Chris@140 416 }
Chris@282 417 blockSizeCombo->setValidator(new QIntValidator(1, int(pow(2, 18)), this));
Chris@155 418 connect(blockSizeCombo, SIGNAL(editTextChanged(const QString &)),
Chris@155 419 this, SLOT(blockSizeComboChanged(const QString &)));
Chris@140 420 windowLayout->addWidget(blockSizeCombo, 0, 1);
Chris@140 421
Chris@148 422 windowLayout->addWidget(new QLabel(tr("Window increment:")), 1, 0);
Chris@148 423
Chris@148 424 QComboBox *incrementCombo = new QComboBox;
Chris@148 425 incrementCombo->setEditable(true);
Chris@148 426 found = false;
Chris@148 427 for (int i = 0; i < 14; ++i) {
Chris@249 428 int val = 1 << (i + 3);
Chris@148 429 incrementCombo->addItem(QString("%1").arg(val));
Chris@148 430 if (val == increment) {
Chris@148 431 incrementCombo->setCurrentIndex(i);
Chris@148 432 found = true;
Chris@148 433 }
Chris@148 434 }
Chris@148 435 if (!found) {
Chris@148 436 incrementCombo->addItem(QString("%1").arg(increment));
Chris@148 437 incrementCombo->setCurrentIndex(incrementCombo->count() - 1);
Chris@148 438 }
Chris@282 439 incrementCombo->setValidator(new QIntValidator(1, int(pow(2, 18)), this));
Chris@155 440 connect(incrementCombo, SIGNAL(editTextChanged(const QString &)),
Chris@155 441 this, SLOT(incrementComboChanged(const QString &)));
Chris@148 442 windowLayout->addWidget(incrementCombo, 1, 1);
Chris@148 443
Chris@140 444 if (showFrequencyDomainOptions) {
Chris@140 445
Chris@140 446 windowLayout->addWidget(new QLabel(tr("Window shape:")), 2, 0);
Chris@140 447 WindowTypeSelector *windowTypeSelector = new WindowTypeSelector;
Chris@171 448 connect(windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
Chris@171 449 this, SLOT(windowTypeChanged(WindowType)));
Chris@140 450 windowLayout->addWidget(windowTypeSelector, 2, 1);
Chris@140 451 }
Chris@163 452
Chris@163 453 m_windowBox->setVisible(true);
Chris@163 454 m_haveWindowBoxData = true;
Chris@163 455 m_advancedButton->show();
Chris@140 456 }
Chris@140 457
Chris@163 458 setAdvancedVisible(m_advancedVisible);
Chris@62 459 }
Chris@62 460
Chris@69 461 void
Chris@336 462 PluginParameterDialog::setCandidateInputModels(const QStringList &models,
Chris@336 463 QString defaultModel)
Chris@164 464 {
Chris@164 465 m_inputModels->clear();
Chris@294 466
Chris@294 467 QSettings settings;
Chris@294 468 settings.beginGroup("PluginParameterDialog");
Chris@294 469 QString lastModel = settings.value("lastinputmodel").toString();
Chris@294 470 settings.endGroup();
Chris@294 471
Chris@336 472 if (defaultModel == "") defaultModel = lastModel;
Chris@336 473
Chris@302 474 m_inputModels->show();
Chris@302 475
Chris@294 476 m_inputModelList = models;
Chris@294 477 m_inputModels->addItems(TextAbbrev::abbreviate(models, 80));
Chris@296 478 m_inputModels->setCurrentIndex(0);
Chris@294 479
Chris@336 480 if (defaultModel != "") {
Chris@294 481 for (int i = 0; i < models.size(); ++i) {
Chris@336 482 if (defaultModel == models[i]) {
Chris@294 483 m_inputModels->setCurrentIndex(i);
Chris@296 484 m_currentInputModel = models[i];
Chris@294 485 break;
Chris@294 486 }
Chris@294 487 }
Chris@294 488 }
Chris@294 489
Chris@294 490 connect(m_inputModels, SIGNAL(activated(int)),
Chris@294 491 this, SLOT(inputModelComboChanged(int)));
Chris@164 492 m_inputModelBox->show();
Chris@164 493 }
Chris@164 494
Chris@302 495 void
Chris@302 496 PluginParameterDialog::setShowSelectionOnlyOption(bool show)
Chris@302 497 {
Chris@302 498 if (!show) {
Chris@302 499 m_selectionOnly->hide();
Chris@302 500 if (!m_inputModels->isVisible()) m_inputModelBox->hide();
Chris@302 501 return;
Chris@302 502 }
Chris@302 503
Chris@302 504 QSettings settings;
Chris@302 505 settings.beginGroup("PluginParameterDialog");
Chris@302 506 bool lastSelectionOnly = settings.value("lastselectiononly", false).toBool();
Chris@302 507 settings.endGroup();
Chris@302 508
Chris@302 509 m_selectionOnly->setChecked(lastSelectionOnly);
Chris@309 510 m_currentSelectionOnly = lastSelectionOnly;
Chris@302 511
Chris@302 512 connect(m_selectionOnly, SIGNAL(stateChanged(int)),
Chris@302 513 this, SLOT(selectionOnlyChanged(int)));
Chris@302 514
Chris@302 515 m_selectionOnly->show();
Chris@302 516 m_inputModelBox->show();
Chris@302 517 }
Chris@302 518
Chris@164 519 QString
Chris@164 520 PluginParameterDialog::getInputModel() const
Chris@164 521 {
Chris@296 522 return m_currentInputModel;
Chris@164 523 }
Chris@164 524
Chris@302 525 bool
Chris@302 526 PluginParameterDialog::getSelectionOnly() const
Chris@302 527 {
Chris@309 528 return m_currentSelectionOnly;
Chris@302 529 }
Chris@302 530
Chris@164 531 void
Chris@145 532 PluginParameterDialog::getProcessingParameters(size_t &blockSize) const
Chris@145 533 {
Chris@145 534 blockSize = m_blockSize;
Chris@145 535 return;
Chris@145 536 }
Chris@145 537
Chris@145 538 void
Chris@145 539 PluginParameterDialog::getProcessingParameters(size_t &stepSize,
Chris@145 540 size_t &blockSize,
Chris@145 541 WindowType &windowType) const
Chris@145 542 {
Chris@145 543 stepSize = m_stepSize;
Chris@145 544 blockSize = m_blockSize;
Chris@145 545 windowType = m_windowType;
Chris@146 546 return;
Chris@145 547 }
Chris@145 548
Chris@145 549 void
Chris@155 550 PluginParameterDialog::blockSizeComboChanged(const QString &text)
Chris@145 551 {
Chris@145 552 m_blockSize = text.toInt();
Chris@146 553 std::cerr << "Block size changed to " << m_blockSize << std::endl;
Chris@145 554 }
Chris@145 555
Chris@145 556 void
Chris@155 557 PluginParameterDialog::incrementComboChanged(const QString &text)
Chris@145 558 {
Chris@145 559 m_stepSize = text.toInt();
Chris@146 560 //!!! rename increment to step size throughout
Chris@147 561 std::cerr << "Increment changed to " << m_stepSize << std::endl;
Chris@145 562 }
Chris@145 563
Chris@145 564 void
Chris@145 565 PluginParameterDialog::windowTypeChanged(WindowType type)
Chris@145 566 {
Chris@145 567 m_windowType = type;
Chris@145 568 }
Chris@145 569
Chris@145 570 void
Chris@440 571 PluginParameterDialog::moreInfo()
Chris@440 572 {
Chris@440 573 if (m_moreInfoUrl != "") {
Chris@440 574 QDesktopServices::openUrl(QUrl(m_moreInfoUrl));
Chris@440 575 }
Chris@440 576 }
Chris@440 577
Chris@440 578 void
Chris@143 579 PluginParameterDialog::advancedToggled()
Chris@143 580 {
Chris@163 581 setAdvancedVisible(!m_advancedVisible);
Chris@163 582 }
Chris@143 583
Chris@163 584 void
Chris@163 585 PluginParameterDialog::setAdvancedVisible(bool visible)
Chris@163 586 {
Chris@143 587 m_advanced->setVisible(visible);
Chris@143 588
Chris@163 589 if (visible) {
Chris@163 590 m_advancedButton->setText(tr("Advanced <<"));
Chris@163 591 m_advancedButton->setChecked(true);
Chris@163 592 } else {
Chris@163 593 m_advancedButton->setText(tr("Advanced >>"));
Chris@163 594 m_advancedButton->setChecked(false);
Chris@163 595 }
Chris@143 596
Chris@143 597 QSettings settings;
Chris@143 598 settings.beginGroup("PluginParameterDialog");
Chris@143 599 settings.setValue("advancedvisible", visible);
Chris@143 600 settings.endGroup();
Chris@143 601
Chris@213 602 // std::cerr << "resize to " << sizeHint().width() << " x " << sizeHint().height() << std::endl;
Chris@143 603
Chris@149 604 setMinimumHeight(sizeHint().height());
Chris@163 605 adjustSize();
Chris@163 606
Chris@163 607 m_advancedVisible = visible;
Chris@163 608
Chris@163 609 // if (visible) setMaximumHeight(sizeHint().height());
Chris@163 610 // adjustSize();
Chris@143 611 }
Chris@143 612
Chris@143 613 void
Chris@69 614 PluginParameterDialog::channelComboChanged(int index)
Chris@69 615 {
Chris@69 616 m_channel = index - 1;
Chris@69 617 }
Chris@69 618
Chris@294 619 void
Chris@294 620 PluginParameterDialog::inputModelComboChanged(int index)
Chris@294 621 {
Chris@294 622 if (index >= m_inputModelList.size()) return;
Chris@296 623 m_currentInputModel = m_inputModelList[index];
Chris@296 624 emit inputModelChanged(m_currentInputModel);
Chris@294 625 }
Chris@294 626
Chris@294 627 void
Chris@302 628 PluginParameterDialog::selectionOnlyChanged(int state)
Chris@302 629 {
Chris@302 630 if (state == Qt::Checked) {
Chris@302 631 m_currentSelectionOnly = true;
Chris@302 632 } else {
Chris@302 633 m_currentSelectionOnly = false;
Chris@302 634 }
Chris@302 635 }
Chris@302 636
Chris@302 637 void
Chris@294 638 PluginParameterDialog::dialogAccepted()
Chris@294 639 {
Chris@294 640 QSettings settings;
Chris@294 641 settings.beginGroup("PluginParameterDialog");
Chris@302 642
Chris@302 643 if (m_inputModels->isVisible()) {
Chris@302 644 settings.setValue("lastinputmodel", getInputModel());
Chris@302 645 }
Chris@302 646
Chris@302 647 if (m_selectionOnly->isVisible()) {
Chris@302 648 settings.setValue("lastselectiononly", getSelectionOnly());
Chris@302 649 }
Chris@302 650
Chris@294 651 settings.endGroup();
Chris@294 652
Chris@294 653 accept();
Chris@294 654 }
Chris@294 655