annotate widgets/PluginParameterDialog.cpp @ 1605:ae2d5f8ff005

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