annotate widgets/PropertyBox.cpp @ 776:fe59d97750ba

Fix crash on checking progress of slice layer
author Chris Cannam
date Thu, 22 May 2014 15:23:24 +0100
parents 336ccf8fc3f8
children 037a7c22bec8
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@0 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "PropertyBox.h"
Chris@63 17 #include "PluginParameterDialog.h"
Chris@0 18
Chris@0 19 #include "base/PropertyContainer.h"
Chris@33 20 #include "base/PlayParameters.h"
Chris@377 21 #include "base/PlayParameterRepository.h"
Chris@128 22 #include "layer/Layer.h"
Chris@376 23 #include "layer/ColourDatabase.h"
Chris@100 24 #include "base/UnitDatabase.h"
Chris@167 25 #include "base/RangeMapper.h"
Chris@0 26
Chris@0 27 #include "AudioDial.h"
Chris@33 28 #include "LEDButton.h"
Chris@335 29 #include "IconLoader.h"
Chris@0 30
Chris@189 31 #include "NotifyingCheckBox.h"
Chris@189 32 #include "NotifyingComboBox.h"
Chris@335 33 #include "NotifyingPushButton.h"
Chris@285 34 #include "ColourNameDialog.h"
Chris@189 35
Chris@0 36 #include <QGridLayout>
Chris@0 37 #include <QHBoxLayout>
Chris@33 38 #include <QVBoxLayout>
Chris@63 39 #include <QPushButton>
Chris@0 40 #include <QLabel>
Chris@33 41 #include <QFrame>
Chris@218 42 #include <QApplication>
Chris@285 43 #include <QColorDialog>
Chris@285 44 #include <QInputDialog>
Chris@769 45 #include <QDir>
Chris@0 46
Chris@0 47 #include <cassert>
Chris@0 48 #include <iostream>
Martin@46 49 #include <cmath>
Chris@0 50
Chris@456 51 //#define DEBUG_PROPERTY_BOX 1
Chris@0 52
Chris@0 53 PropertyBox::PropertyBox(PropertyContainer *container) :
Chris@185 54 m_container(container),
Chris@189 55 m_showButton(0),
Chris@189 56 m_playButton(0)
Chris@0 57 {
Chris@0 58 #ifdef DEBUG_PROPERTY_BOX
Chris@682 59 cerr << "PropertyBox[" << this << "(\"" <<
Chris@682 60 container->getPropertyContainerName() << "\" at " << container << ")]::PropertyBox" << endl;
Chris@0 61 #endif
Chris@0 62
Chris@34 63 m_mainBox = new QVBoxLayout;
Chris@34 64 setLayout(m_mainBox);
Chris@33 65
Chris@107 66 // m_nameWidget = new QLabel;
Chris@107 67 // m_mainBox->addWidget(m_nameWidget);
Chris@107 68 // m_nameWidget->setText(container->objectName());
Chris@107 69
Chris@34 70 m_mainWidget = new QWidget;
Chris@34 71 m_mainBox->addWidget(m_mainWidget);
Chris@107 72 m_mainBox->insertStretch(2, 10);
Chris@33 73
Chris@34 74 m_viewPlayFrame = 0;
Chris@34 75 populateViewPlayFrame();
Chris@33 76
Chris@0 77 m_layout = new QGridLayout;
Chris@34 78 m_layout->setMargin(0);
Chris@33 79 m_mainWidget->setLayout(m_layout);
Chris@0 80
Chris@34 81 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 82
Chris@0 83 blockSignals(true);
Chris@0 84
Chris@0 85 size_t i;
Chris@0 86
Chris@0 87 for (i = 0; i < properties.size(); ++i) {
Chris@0 88 updatePropertyEditor(properties[i]);
Chris@0 89 }
Chris@0 90
Chris@0 91 blockSignals(false);
Chris@0 92
Chris@0 93 m_layout->setRowStretch(m_layout->rowCount(), 10);
Chris@0 94
Chris@100 95 connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()),
Chris@100 96 this, SLOT(unitDatabaseChanged()));
Chris@100 97
Chris@285 98 connect(ColourDatabase::getInstance(), SIGNAL(colourDatabaseChanged()),
Chris@285 99 this, SLOT(colourDatabaseChanged()));
Chris@285 100
Chris@0 101 #ifdef DEBUG_PROPERTY_BOX
Chris@682 102 cerr << "PropertyBox[" << this << "]::PropertyBox returning" << endl;
Chris@0 103 #endif
Chris@0 104 }
Chris@0 105
Chris@0 106 PropertyBox::~PropertyBox()
Chris@0 107 {
Chris@0 108 #ifdef DEBUG_PROPERTY_BOX
Chris@682 109 cerr << "PropertyBox[" << this << "]::~PropertyBox" << endl;
Chris@0 110 #endif
Chris@0 111 }
Chris@0 112
Chris@0 113 void
Chris@34 114 PropertyBox::populateViewPlayFrame()
Chris@33 115 {
Chris@36 116 #ifdef DEBUG_PROPERTY_BOX
Chris@729 117 cerr << "PropertyBox[" << this << ":" << m_container << "]::populateViewPlayFrame" << endl;
Chris@36 118 #endif
Chris@34 119
Chris@34 120 if (m_viewPlayFrame) {
Chris@34 121 delete m_viewPlayFrame;
Chris@34 122 m_viewPlayFrame = 0;
Chris@34 123 }
Chris@34 124
Chris@34 125 if (!m_container) return;
Chris@34 126
Chris@34 127 Layer *layer = dynamic_cast<Layer *>(m_container);
Chris@34 128 if (layer) {
Chris@193 129 disconnect(layer, SIGNAL(modelReplaced()),
Chris@193 130 this, SLOT(populateViewPlayFrame()));
Chris@34 131 connect(layer, SIGNAL(modelReplaced()),
Chris@34 132 this, SLOT(populateViewPlayFrame()));
Chris@34 133 }
Chris@34 134
Chris@34 135 PlayParameters *params = m_container->getPlayParameters();
Chris@33 136 if (!params && !layer) return;
Chris@33 137
Chris@34 138 m_viewPlayFrame = new QFrame;
Chris@34 139 m_viewPlayFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@34 140 m_mainBox->addWidget(m_viewPlayFrame);
Chris@34 141
Chris@34 142 QHBoxLayout *layout = new QHBoxLayout;
Chris@34 143 m_viewPlayFrame->setLayout(layout);
Chris@34 144
Chris@34 145 layout->setMargin(layout->margin() / 2);
Chris@34 146
Chris@36 147 #ifdef DEBUG_PROPERTY_BOX
Chris@587 148 SVDEBUG << "PropertyBox::populateViewPlayFrame: container " << m_container << " (name " << m_container->getPropertyContainerName() << ") params " << params << endl;
Chris@36 149 #endif
Chris@36 150
Chris@33 151 if (layer) {
Chris@34 152 QLabel *showLabel = new QLabel(tr("Show"));
Chris@34 153 layout->addWidget(showLabel);
Chris@34 154 layout->setAlignment(showLabel, Qt::AlignVCenter);
Chris@34 155
Chris@185 156 m_showButton = new LEDButton(Qt::blue);
Chris@185 157 layout->addWidget(m_showButton);
Chris@185 158 connect(m_showButton, SIGNAL(stateChanged(bool)),
Chris@47 159 this, SIGNAL(showLayer(bool)));
Chris@189 160 connect(m_showButton, SIGNAL(mouseEntered()),
Chris@189 161 this, SLOT(mouseEnteredWidget()));
Chris@189 162 connect(m_showButton, SIGNAL(mouseLeft()),
Chris@189 163 this, SLOT(mouseLeftWidget()));
Chris@185 164 layout->setAlignment(m_showButton, Qt::AlignVCenter);
Chris@33 165 }
Chris@33 166
Chris@33 167 if (params) {
Chris@34 168
Chris@34 169 QLabel *playLabel = new QLabel(tr("Play"));
Chris@34 170 layout->addWidget(playLabel);
Chris@34 171 layout->setAlignment(playLabel, Qt::AlignVCenter);
Chris@34 172
Chris@189 173 m_playButton = new LEDButton(Qt::darkGreen);
Chris@189 174 m_playButton->setState(!params->isPlayMuted());
Chris@189 175 layout->addWidget(m_playButton);
Chris@189 176 connect(m_playButton, SIGNAL(stateChanged(bool)),
Chris@377 177 this, SLOT(playAudibleButtonChanged(bool)));
Chris@189 178 connect(m_playButton, SIGNAL(mouseEntered()),
Chris@189 179 this, SLOT(mouseEnteredWidget()));
Chris@189 180 connect(m_playButton, SIGNAL(mouseLeft()),
Chris@189 181 this, SLOT(mouseLeftWidget()));
Chris@34 182 connect(params, SIGNAL(playAudibleChanged(bool)),
Chris@377 183 this, SLOT(playAudibleChanged(bool)));
Chris@189 184 layout->setAlignment(m_playButton, Qt::AlignVCenter);
Chris@34 185
Chris@34 186 layout->insertStretch(-1, 10);
Chris@34 187
Chris@769 188 if (params->getPlayClipId() != "") {
Chris@769 189 QPushButton *playParamButton =
Chris@769 190 new QPushButton(QIcon(":icons/faders.png"), "");
Chris@769 191 playParamButton->setFixedWidth(24);
Chris@769 192 playParamButton->setFixedHeight(24);
Chris@769 193 layout->addWidget(playParamButton);
Chris@769 194 connect(playParamButton, SIGNAL(clicked()),
Chris@769 195 this, SLOT(editPlayParameters()));
Chris@63 196 }
Chris@63 197
Chris@34 198 AudioDial *gainDial = new AudioDial;
Chris@34 199 layout->addWidget(gainDial);
Chris@34 200 gainDial->setMeterColor(Qt::darkRed);
Chris@34 201 gainDial->setMinimum(-50);
Chris@34 202 gainDial->setMaximum(50);
Chris@34 203 gainDial->setPageStep(1);
Chris@34 204 gainDial->setFixedWidth(24);
Chris@34 205 gainDial->setFixedHeight(24);
Chris@34 206 gainDial->setNotchesVisible(false);
Chris@34 207 gainDial->setDefaultValue(0);
Chris@168 208 gainDial->setObjectName(tr("Playback Gain"));
Chris@167 209 gainDial->setRangeMapper(new LinearRangeMapper
Chris@167 210 (-50, 50, -25, 25, tr("dB")));
Chris@168 211 gainDial->setShowToolTip(true);
Chris@34 212 connect(gainDial, SIGNAL(valueChanged(int)),
Chris@34 213 this, SLOT(playGainDialChanged(int)));
Chris@34 214 connect(params, SIGNAL(playGainChanged(float)),
Chris@34 215 this, SLOT(playGainChanged(float)));
Chris@34 216 connect(this, SIGNAL(changePlayGainDial(int)),
Chris@34 217 gainDial, SLOT(setValue(int)));
Chris@189 218 connect(gainDial, SIGNAL(mouseEntered()),
Chris@189 219 this, SLOT(mouseEnteredWidget()));
Chris@189 220 connect(gainDial, SIGNAL(mouseLeft()),
Chris@189 221 this, SLOT(mouseLeftWidget()));
Chris@377 222 playGainChanged(params->getPlayGain());
Chris@34 223 layout->setAlignment(gainDial, Qt::AlignVCenter);
Chris@34 224
Chris@34 225 AudioDial *panDial = new AudioDial;
Chris@34 226 layout->addWidget(panDial);
Chris@34 227 panDial->setMeterColor(Qt::darkGreen);
Chris@34 228 panDial->setMinimum(-50);
Chris@34 229 panDial->setMaximum(50);
Chris@34 230 panDial->setPageStep(1);
Chris@34 231 panDial->setFixedWidth(24);
Chris@34 232 panDial->setFixedHeight(24);
Chris@34 233 panDial->setNotchesVisible(false);
Chris@57 234 panDial->setToolTip(tr("Playback Pan / Balance"));
Chris@34 235 panDial->setDefaultValue(0);
Chris@168 236 panDial->setObjectName(tr("Playback Pan / Balance"));
Chris@168 237 panDial->setShowToolTip(true);
Chris@34 238 connect(panDial, SIGNAL(valueChanged(int)),
Chris@34 239 this, SLOT(playPanDialChanged(int)));
Chris@34 240 connect(params, SIGNAL(playPanChanged(float)),
Chris@34 241 this, SLOT(playPanChanged(float)));
Chris@34 242 connect(this, SIGNAL(changePlayPanDial(int)),
Chris@34 243 panDial, SLOT(setValue(int)));
Chris@189 244 connect(panDial, SIGNAL(mouseEntered()),
Chris@189 245 this, SLOT(mouseEnteredWidget()));
Chris@189 246 connect(panDial, SIGNAL(mouseLeft()),
Chris@189 247 this, SLOT(mouseLeftWidget()));
Chris@377 248 playPanChanged(params->getPlayPan());
Chris@34 249 layout->setAlignment(panDial, Qt::AlignVCenter);
Chris@34 250
Chris@34 251 } else {
Chris@34 252
Chris@34 253 layout->insertStretch(-1, 10);
Chris@33 254 }
Chris@33 255 }
Chris@33 256
Chris@33 257 void
Chris@197 258 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name,
Chris@197 259 bool rangeChanged)
Chris@0 260 {
Chris@0 261 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 262 int row = m_layout->rowCount();
Chris@0 263
Chris@216 264 int min = 0, max = 0, value = 0, deflt = 0;
Chris@216 265 value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
Chris@0 266
Chris@0 267 bool have = (m_propertyControllers.find(name) !=
Chris@0 268 m_propertyControllers.end());
Chris@0 269
Chris@0 270 QString groupName = m_container->getPropertyGroupName(name);
Chris@87 271 QString propertyLabel = m_container->getPropertyLabel(name);
Chris@335 272 QString iconName = m_container->getPropertyIconName(name);
Chris@0 273
Chris@0 274 #ifdef DEBUG_PROPERTY_BOX
Chris@682 275 cerr << "PropertyBox[" << this
Chris@683 276 << "(\"" << m_container->getPropertyContainerName()
Chris@0 277 << "\")]";
Chris@682 278 cerr << "::updatePropertyEditor(\"" << name << "\"):";
Chris@682 279 cerr << " value " << value << ", have " << have << ", group \""
Chris@682 280 << groupName << "\"" << endl;
Chris@0 281 #endif
Chris@0 282
Chris@0 283 bool inGroup = (groupName != QString());
Chris@0 284
Chris@0 285 if (!have) {
Chris@0 286 if (inGroup) {
Chris@0 287 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@0 288 #ifdef DEBUG_PROPERTY_BOX
Chris@682 289 cerr << "PropertyBox: adding label \"" << groupName << "\" and frame for group for \"" << name << "\"" << endl;
Chris@0 290 #endif
Chris@33 291 m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
Chris@33 292 QFrame *frame = new QFrame(m_mainWidget);
Chris@0 293 m_layout->addWidget(frame, row, 1, 1, 2);
Chris@493 294 m_groupLayouts[groupName] = new QGridLayout;
Chris@0 295 m_groupLayouts[groupName]->setMargin(0);
Chris@0 296 frame->setLayout(m_groupLayouts[groupName]);
Chris@0 297 }
Chris@0 298 } else {
Chris@0 299 #ifdef DEBUG_PROPERTY_BOX
Chris@682 300 cerr << "PropertyBox: adding label \"" << propertyLabel << "\"" << endl;
Chris@0 301 #endif
Chris@87 302 m_layout->addWidget(new QLabel(propertyLabel, m_mainWidget), row, 0);
Chris@0 303 }
Chris@0 304 }
Chris@0 305
Chris@0 306 switch (type) {
Chris@0 307
Chris@0 308 case PropertyContainer::ToggleProperty:
Chris@0 309 {
Chris@335 310 QAbstractButton *button = 0;
Chris@0 311
Chris@0 312 if (have) {
Chris@335 313 button = dynamic_cast<QAbstractButton *>(m_propertyControllers[name]);
Chris@335 314 assert(button);
Chris@0 315 } else {
Chris@0 316 #ifdef DEBUG_PROPERTY_BOX
Chris@682 317 cerr << "PropertyBox: creating new checkbox" << endl;
Chris@0 318 #endif
Chris@335 319 if (iconName != "") {
Chris@335 320 button = new NotifyingPushButton();
Chris@335 321 button->setCheckable(true);
Chris@335 322 QIcon icon(IconLoader().load(iconName));
Chris@335 323 button->setIcon(icon);
Chris@335 324 button->setObjectName(name);
Chris@335 325 button->setFixedSize(QSize(18, 18));
Chris@335 326 } else {
Chris@335 327 button = new NotifyingCheckBox();
Chris@335 328 button->setObjectName(name);
Chris@335 329 }
Chris@335 330 connect(button, SIGNAL(toggled(bool)),
Chris@335 331 this, SLOT(propertyControllerChanged(bool)));
Chris@335 332 connect(button, SIGNAL(mouseEntered()),
Chris@189 333 this, SLOT(mouseEnteredWidget()));
Chris@335 334 connect(button, SIGNAL(mouseLeft()),
Chris@189 335 this, SLOT(mouseLeftWidget()));
Chris@0 336 if (inGroup) {
Chris@335 337 button->setToolTip(propertyLabel);
Chris@493 338 m_groupLayouts[groupName]->addWidget
Chris@493 339 (button, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 340 } else {
Chris@335 341 m_layout->addWidget(button, row, 1, 1, 2);
Chris@0 342 }
Chris@335 343 m_propertyControllers[name] = button;
Chris@0 344 }
Chris@0 345
Chris@335 346 if (button->isChecked() != (value > 0)) {
Chris@335 347 button->blockSignals(true);
Chris@335 348 button->setChecked(value > 0);
Chris@335 349 button->blockSignals(false);
Chris@55 350 }
Chris@0 351 break;
Chris@0 352 }
Chris@0 353
Chris@0 354 case PropertyContainer::RangeProperty:
Chris@0 355 {
Chris@0 356 AudioDial *dial;
Chris@0 357
Chris@0 358 if (have) {
Chris@0 359 dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 360 assert(dial);
Chris@197 361 if (rangeChanged) {
Chris@197 362 dial->blockSignals(true);
Chris@197 363 dial->setMinimum(min);
Chris@197 364 dial->setMaximum(max);
Chris@197 365 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@197 366 dial->blockSignals(false);
Chris@197 367 }
Chris@197 368
Chris@0 369 } else {
Chris@0 370 #ifdef DEBUG_PROPERTY_BOX
Chris@682 371 cerr << "PropertyBox: creating new dial" << endl;
Chris@0 372 #endif
Chris@0 373 dial = new AudioDial();
Chris@0 374 dial->setObjectName(name);
Chris@0 375 dial->setMinimum(min);
Chris@0 376 dial->setMaximum(max);
Chris@0 377 dial->setPageStep(1);
Chris@34 378 dial->setNotchesVisible((max - min) <= 12);
Chris@216 379 dial->setDefaultValue(deflt);
Chris@167 380 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@168 381 dial->setShowToolTip(true);
Chris@0 382 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 383 this, SLOT(propertyControllerChanged(int)));
Chris@189 384 connect(dial, SIGNAL(mouseEntered()),
Chris@189 385 this, SLOT(mouseEnteredWidget()));
Chris@189 386 connect(dial, SIGNAL(mouseLeft()),
Chris@189 387 this, SLOT(mouseLeftWidget()));
Chris@0 388
Chris@0 389 if (inGroup) {
Chris@0 390 dial->setFixedWidth(24);
Chris@0 391 dial->setFixedHeight(24);
Chris@493 392 m_groupLayouts[groupName]->addWidget
Chris@493 393 (dial, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 394 } else {
Chris@0 395 dial->setFixedWidth(32);
Chris@0 396 dial->setFixedHeight(32);
Chris@0 397 m_layout->addWidget(dial, row, 1);
Chris@33 398 QLabel *label = new QLabel(m_mainWidget);
Chris@0 399 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 400 label, SLOT(setNum(int)));
Chris@0 401 label->setNum(value);
Chris@0 402 m_layout->addWidget(label, row, 2);
Chris@0 403 }
Chris@0 404
Chris@0 405 m_propertyControllers[name] = dial;
Chris@0 406 }
Chris@0 407
Chris@55 408 if (dial->value() != value) {
Chris@55 409 dial->blockSignals(true);
Chris@55 410 dial->setValue(value);
Chris@55 411 dial->blockSignals(false);
Chris@55 412 }
Chris@0 413 break;
Chris@0 414 }
Chris@0 415
Chris@0 416 case PropertyContainer::ValueProperty:
Chris@100 417 case PropertyContainer::UnitsProperty:
Chris@285 418 case PropertyContainer::ColourProperty:
Chris@0 419 {
Chris@189 420 NotifyingComboBox *cb;
Chris@0 421
Chris@0 422 if (have) {
Chris@189 423 cb = dynamic_cast<NotifyingComboBox *>(m_propertyControllers[name]);
Chris@0 424 assert(cb);
Chris@0 425 } else {
Chris@0 426 #ifdef DEBUG_PROPERTY_BOX
Chris@682 427 cerr << "PropertyBox: creating new combobox" << endl;
Chris@0 428 #endif
Chris@0 429
Chris@189 430 cb = new NotifyingComboBox();
Chris@0 431 cb->setObjectName(name);
Chris@100 432 cb->setDuplicatesEnabled(false);
Chris@197 433 }
Chris@100 434
Chris@197 435 if (!have || rangeChanged) {
Chris@285 436
Chris@197 437 cb->blockSignals(true);
Chris@197 438 cb->clear();
Chris@285 439 cb->setEditable(false);
Chris@285 440
Chris@100 441 if (type == PropertyContainer::ValueProperty) {
Chris@285 442
Chris@100 443 for (int i = min; i <= max; ++i) {
Chris@100 444 cb->addItem(m_container->getPropertyValueLabel(name, i));
Chris@100 445 }
Chris@285 446
Chris@285 447 } else if (type == PropertyContainer::UnitsProperty) {
Chris@285 448
Chris@100 449 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
Chris@100 450 for (int i = 0; i < units.size(); ++i) {
Chris@100 451 cb->addItem(units[i]);
Chris@100 452 }
Chris@285 453
Chris@100 454 cb->setEditable(true);
Chris@285 455
Chris@285 456 } else { // ColourProperty
Chris@290 457
Chris@290 458 //!!! should be a proper colour combobox class that
Chris@290 459 // manages its own Add New Colour entry...
Chris@285 460
Chris@285 461 ColourDatabase *db = ColourDatabase::getInstance();
Chris@769 462 for (int i = 0; i < db->getColourCount(); ++i) {
Chris@285 463 QString name = db->getColourName(i);
Chris@287 464 cb->addItem(db->getExamplePixmap(i, QSize(12, 12)), name);
Chris@285 465 }
Chris@285 466 cb->addItem(tr("Add New Colour..."));
Chris@285 467 }
Chris@285 468
Chris@197 469 cb->blockSignals(false);
Chris@280 470 if (cb->count() < 20 && cb->count() > cb->maxVisibleItems()) {
Chris@280 471 cb->setMaxVisibleItems(cb->count());
Chris@280 472 }
Chris@197 473 }
Chris@100 474
Chris@197 475 if (!have) {
Chris@0 476 connect(cb, SIGNAL(activated(int)),
Chris@0 477 this, SLOT(propertyControllerChanged(int)));
Chris@189 478 connect(cb, SIGNAL(mouseEntered()),
Chris@189 479 this, SLOT(mouseEnteredWidget()));
Chris@189 480 connect(cb, SIGNAL(mouseLeft()),
Chris@189 481 this, SLOT(mouseLeftWidget()));
Chris@100 482
Chris@0 483 if (inGroup) {
Chris@108 484 cb->setToolTip(propertyLabel);
Chris@493 485 m_groupLayouts[groupName]->addWidget
Chris@493 486 (cb, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 487 } else {
Chris@0 488 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 489 }
Chris@0 490 m_propertyControllers[name] = cb;
Chris@0 491 }
Chris@0 492
Chris@100 493 cb->blockSignals(true);
Chris@285 494 if (type == PropertyContainer::ValueProperty ||
Chris@285 495 type == PropertyContainer::ColourProperty) {
Chris@100 496 if (cb->currentIndex() != value) {
Chris@100 497 cb->setCurrentIndex(value);
Chris@100 498 }
Chris@100 499 } else {
Chris@100 500 QString unit = UnitDatabase::getInstance()->getUnitById(value);
Chris@100 501 if (cb->currentText() != unit) {
Chris@100 502 for (int i = 0; i < cb->count(); ++i) {
Chris@100 503 if (cb->itemText(i) == unit) {
Chris@100 504 cb->setCurrentIndex(i);
Chris@100 505 break;
Chris@100 506 }
Chris@100 507 }
Chris@100 508 }
Chris@100 509 }
Chris@100 510 cb->blockSignals(false);
Chris@0 511
Chris@681 512 #ifdef Q_OS_MAC
Chris@0 513 // Crashes on startup without this, for some reason
Chris@0 514 cb->setMinimumSize(QSize(10, 10));
Chris@0 515 #endif
Chris@0 516
Chris@0 517 break;
Chris@0 518 }
Chris@0 519
Chris@0 520 default:
Chris@0 521 break;
Chris@0 522 }
Chris@0 523 }
Chris@0 524
Chris@0 525 void
Chris@0 526 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 527 {
Chris@0 528 if (pc != m_container) return;
Chris@0 529
Chris@55 530 #ifdef DEBUG_PROPERTY_BOX
Chris@587 531 SVDEBUG << "PropertyBox::propertyContainerPropertyChanged" << endl;
Chris@55 532 #endif
Chris@55 533
Chris@0 534 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 535 size_t i;
Chris@0 536
Chris@0 537 blockSignals(true);
Chris@0 538
Chris@0 539 for (i = 0; i < properties.size(); ++i) {
Chris@0 540 updatePropertyEditor(properties[i]);
Chris@0 541 }
Chris@0 542
Chris@0 543 blockSignals(false);
Chris@0 544 }
Chris@0 545
Chris@0 546 void
Chris@249 547 PropertyBox::propertyContainerPropertyRangeChanged(PropertyContainer *)
Chris@197 548 {
Chris@197 549 blockSignals(true);
Chris@197 550
Chris@197 551 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@197 552 for (size_t i = 0; i < properties.size(); ++i) {
Chris@197 553 updatePropertyEditor(properties[i], true);
Chris@197 554 }
Chris@197 555
Chris@197 556 blockSignals(false);
Chris@197 557 }
Chris@197 558
Chris@197 559 void
Chris@100 560 PropertyBox::unitDatabaseChanged()
Chris@100 561 {
Chris@729 562 #ifdef DEBUG_PROPERTY_BOX
Chris@682 563 cerr << "PropertyBox[" << this << "]: unitDatabaseChanged" << endl;
Chris@729 564 #endif
Chris@100 565 blockSignals(true);
Chris@100 566
Chris@682 567 // cerr << "my container is " << m_container << endl;
Chris@682 568 // cerr << "my container's name is... " << endl;
Chris@682 569 // cerr << m_container->objectName() << endl;
Chris@456 570
Chris@100 571 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@100 572 for (size_t i = 0; i < properties.size(); ++i) {
Chris@285 573 if (m_container->getPropertyType(properties[i]) ==
Chris@285 574 PropertyContainer::UnitsProperty) {
Chris@285 575 updatePropertyEditor(properties[i]);
Chris@285 576 }
Chris@285 577 }
Chris@285 578
Chris@285 579 blockSignals(false);
Chris@285 580 }
Chris@285 581
Chris@285 582 void
Chris@285 583 PropertyBox::colourDatabaseChanged()
Chris@285 584 {
Chris@285 585 blockSignals(true);
Chris@285 586
Chris@285 587 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@285 588 for (size_t i = 0; i < properties.size(); ++i) {
Chris@285 589 if (m_container->getPropertyType(properties[i]) ==
Chris@285 590 PropertyContainer::ColourProperty) {
Chris@285 591 updatePropertyEditor(properties[i], true);
Chris@285 592 }
Chris@100 593 }
Chris@100 594
Chris@100 595 blockSignals(false);
Chris@100 596 }
Chris@100 597
Chris@100 598 void
Chris@335 599 PropertyBox::propertyControllerChanged(bool on)
Chris@335 600 {
Chris@335 601 propertyControllerChanged(on ? 1 : 0);
Chris@335 602 }
Chris@335 603
Chris@335 604 void
Chris@0 605 PropertyBox::propertyControllerChanged(int value)
Chris@0 606 {
Chris@0 607 QObject *obj = sender();
Chris@0 608 QString name = obj->objectName();
Chris@0 609
Chris@34 610 #ifdef DEBUG_PROPERTY_BOX
Chris@587 611 SVDEBUG << "PropertyBox::propertyControllerChanged(" << name << ", " << value << ")" << endl;
Chris@34 612 #endif
Chris@0 613
Chris@0 614 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@100 615
Chris@376 616 Command *c = 0;
Chris@376 617
Chris@100 618 if (type == PropertyContainer::UnitsProperty) {
Chris@285 619
Chris@189 620 NotifyingComboBox *cb = dynamic_cast<NotifyingComboBox *>(obj);
Chris@100 621 if (cb) {
Chris@100 622 QString unit = cb->currentText();
Chris@376 623 c = m_container->getSetPropertyCommand
Chris@100 624 (name, UnitDatabase::getInstance()->getUnitId(unit));
Chris@100 625 }
Chris@285 626
Chris@285 627 } else if (type == PropertyContainer::ColourProperty) {
Chris@285 628
Chris@285 629 if (value == int(ColourDatabase::getInstance()->getColourCount())) {
Chris@285 630 addNewColour();
Chris@285 631 if (value == int(ColourDatabase::getInstance()->getColourCount())) {
Chris@285 632 propertyContainerPropertyChanged(m_container);
Chris@285 633 return;
Chris@285 634 }
Chris@285 635 }
Chris@376 636 c = m_container->getSetPropertyCommand(name, value);
Chris@285 637
Chris@100 638 } else if (type != PropertyContainer::InvalidProperty) {
Chris@285 639
Chris@376 640 c = m_container->getSetPropertyCommand(name, value);
Chris@0 641 }
Chris@376 642
Chris@376 643 if (c) CommandHistory::getInstance()->addCommand(c, true, true);
Chris@218 644
Chris@218 645 updateContextHelp(obj);
Chris@0 646 }
Chris@285 647
Chris@285 648 void
Chris@285 649 PropertyBox::addNewColour()
Chris@285 650 {
Chris@285 651 QColor newColour = QColorDialog::getColor();
Chris@285 652 if (!newColour.isValid()) return;
Chris@285 653
Chris@285 654 ColourNameDialog dialog(tr("Name New Colour"),
Chris@361 655 tr("Enter a name for the new colour:"),
Chris@361 656 newColour, newColour.name(), this);
Chris@285 657 dialog.showDarkBackgroundCheckbox(tr("Prefer black background for this colour"));
Chris@285 658 if (dialog.exec() == QDialog::Accepted) {
Chris@285 659 //!!! command
Chris@285 660 ColourDatabase *db = ColourDatabase::getInstance();
Chris@285 661 int index = db->addColour(newColour, dialog.getColourName());
Chris@285 662 db->setUseDarkBackground(index, dialog.isDarkBackgroundChecked());
Chris@285 663 }
Chris@285 664 }
Chris@377 665
Chris@377 666 void
Chris@377 667 PropertyBox::playAudibleChanged(bool audible)
Chris@377 668 {
Chris@377 669 m_playButton->setState(audible);
Chris@377 670 }
Chris@377 671
Chris@377 672 void
Chris@377 673 PropertyBox::playAudibleButtonChanged(bool audible)
Chris@377 674 {
Chris@377 675 PlayParameters *params = m_container->getPlayParameters();
Chris@377 676 if (!params) return;
Chris@377 677
Chris@377 678 if (params->isPlayAudible() != audible) {
Chris@377 679 PlayParameterRepository::EditCommand *command =
Chris@377 680 new PlayParameterRepository::EditCommand(params);
Chris@377 681 command->setPlayAudible(audible);
Chris@377 682 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 683 }
Chris@377 684 }
Chris@0 685
Chris@34 686 void
Chris@34 687 PropertyBox::playGainChanged(float gain)
Chris@34 688 {
Chris@34 689 int dialValue = lrint(log10(gain) * 20.0);
Chris@34 690 if (dialValue < -50) dialValue = -50;
Chris@34 691 if (dialValue > 50) dialValue = 50;
Chris@34 692 emit changePlayGainDial(dialValue);
Chris@34 693 }
Chris@34 694
Chris@34 695 void
Chris@34 696 PropertyBox::playGainDialChanged(int dialValue)
Chris@34 697 {
Chris@218 698 QObject *obj = sender();
Chris@377 699
Chris@377 700 PlayParameters *params = m_container->getPlayParameters();
Chris@377 701 if (!params) return;
Chris@377 702
Chris@34 703 float gain = pow(10, float(dialValue) / 20.0);
Chris@377 704
Chris@377 705 if (params->getPlayGain() != gain) {
Chris@377 706 PlayParameterRepository::EditCommand *command =
Chris@377 707 new PlayParameterRepository::EditCommand(params);
Chris@377 708 command->setPlayGain(gain);
Chris@377 709 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 710 }
Chris@377 711
Chris@218 712 updateContextHelp(obj);
Chris@34 713 }
Chris@34 714
Chris@34 715 void
Chris@34 716 PropertyBox::playPanChanged(float pan)
Chris@34 717 {
Chris@34 718 int dialValue = lrint(pan * 50.0);
Chris@34 719 if (dialValue < -50) dialValue = -50;
Chris@34 720 if (dialValue > 50) dialValue = 50;
Chris@34 721 emit changePlayPanDial(dialValue);
Chris@34 722 }
Chris@34 723
Chris@34 724 void
Chris@34 725 PropertyBox::playPanDialChanged(int dialValue)
Chris@34 726 {
Chris@218 727 QObject *obj = sender();
Chris@377 728
Chris@377 729 PlayParameters *params = m_container->getPlayParameters();
Chris@377 730 if (!params) return;
Chris@377 731
Chris@34 732 float pan = float(dialValue) / 50.0;
Chris@34 733 if (pan < -1.0) pan = -1.0;
Chris@34 734 if (pan > 1.0) pan = 1.0;
Chris@377 735
Chris@377 736 if (params->getPlayPan() != pan) {
Chris@377 737 PlayParameterRepository::EditCommand *command =
Chris@377 738 new PlayParameterRepository::EditCommand(params);
Chris@377 739 command->setPlayPan(pan);
Chris@377 740 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 741 }
Chris@377 742
Chris@218 743 updateContextHelp(obj);
Chris@34 744 }
Chris@769 745
Chris@63 746 void
Chris@769 747 PropertyBox::editPlayParameters()
Chris@63 748 {
Chris@63 749 PlayParameters *params = m_container->getPlayParameters();
Chris@63 750 if (!params) return;
Chris@63 751
Chris@769 752 QString clip = params->getPlayClipId();
Chris@377 753
Chris@377 754 PlayParameterRepository::EditCommand *command =
Chris@377 755 new PlayParameterRepository::EditCommand(params);
Chris@63 756
Chris@769 757 QInputDialog *dialog = new QInputDialog(this);
Chris@63 758
Chris@769 759 QDir dir(":/samples");
Chris@769 760 QStringList clipFiles = dir.entryList(QStringList() << "*.wav", QDir::Files);
Chris@63 761
Chris@769 762 QStringList clips;
Chris@769 763 foreach (QString str, clipFiles) {
Chris@769 764 clips.push_back(str.replace(".wav", ""));
Chris@769 765 }
Chris@769 766 dialog->setComboBoxItems(clips);
Chris@63 767
Chris@769 768 dialog->setLabelText(tr("Set playback clip:"));
Chris@769 769
Chris@769 770 QComboBox *cb = dialog->findChild<QComboBox *>();
Chris@769 771 if (cb) cb->setCurrentText(clip);
Chris@769 772
Chris@769 773 connect(dialog, SIGNAL(textValueChanged(QString)),
Chris@769 774 this, SLOT(playClipChanged(QString)));
Chris@64 775
Chris@63 776 if (dialog->exec() == QDialog::Accepted) {
Chris@769 777 QString newClip = dialog->textValue();
Chris@769 778 command->setPlayClipId(newClip);
Chris@377 779 CommandHistory::getInstance()->addCommand(command, true);
Chris@64 780 } else {
Chris@377 781 delete command;
Chris@64 782 // restore in case we mucked about with the configuration
Chris@64 783 // as a consequence of signals from the dialog
Chris@769 784 params->setPlayClipId(clip);
Chris@63 785 }
Chris@63 786
Chris@63 787 delete dialog;
Chris@63 788 }
Chris@63 789
Chris@64 790 void
Chris@769 791 PropertyBox::playClipChanged(QString id)
Chris@64 792 {
Chris@64 793 PlayParameters *params = m_container->getPlayParameters();
Chris@64 794 if (!params) return;
Chris@64 795
Chris@769 796 params->setPlayClipId(id);
Chris@64 797 }
Chris@769 798
Chris@185 799 void
Chris@185 800 PropertyBox::layerVisibilityChanged(bool visible)
Chris@185 801 {
Chris@185 802 if (m_showButton) m_showButton->setState(visible);
Chris@185 803 }
Chris@189 804
Chris@189 805 void
Chris@189 806 PropertyBox::mouseEnteredWidget()
Chris@189 807 {
Chris@218 808 updateContextHelp(sender());
Chris@218 809 }
Chris@218 810
Chris@218 811 void
Chris@218 812 PropertyBox::updateContextHelp(QObject *o)
Chris@218 813 {
Chris@218 814 QWidget *w = dynamic_cast<QWidget *>(o);
Chris@189 815 if (!w) return;
Chris@218 816
Chris@189 817 if (!m_container) return;
Chris@190 818 QString cname = m_container->getPropertyContainerName();
Chris@189 819 if (cname == "") return;
Chris@189 820
Chris@189 821 QString wname = w->objectName();
Chris@189 822
Chris@218 823 QString extraText;
Chris@218 824 AudioDial *dial = dynamic_cast<AudioDial *>(w);
Chris@218 825 if (dial) {
Chris@218 826 float mv = dial->mappedValue();
Chris@218 827 QString unit = "";
Chris@218 828 if (dial->rangeMapper()) unit = dial->rangeMapper()->getUnit();
Chris@218 829 if (unit != "") {
Chris@218 830 extraText = tr(" (current value: %1%2)").arg(mv).arg(unit);
Chris@218 831 } else {
Chris@218 832 extraText = tr(" (current value: %1)").arg(mv);
Chris@218 833 }
Chris@218 834 }
Chris@218 835
Chris@189 836 if (w == m_showButton) {
Chris@190 837 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
Chris@189 838 } else if (w == m_playButton) {
Chris@190 839 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
Chris@189 840 } else if (wname == "") {
Chris@189 841 return;
Chris@335 842 } else if (dynamic_cast<QAbstractButton *>(w)) {
Chris@190 843 emit contextHelpChanged(tr("Toggle %1 property of %2")
Chris@189 844 .arg(wname).arg(cname));
Chris@189 845 } else {
Chris@218 846 emit contextHelpChanged(tr("Adjust %1 property of %2%3")
Chris@218 847 .arg(wname).arg(cname).arg(extraText));
Chris@189 848 }
Chris@189 849 }
Chris@189 850
Chris@189 851 void
Chris@189 852 PropertyBox::mouseLeftWidget()
Chris@189 853 {
Chris@218 854 if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
Chris@218 855 emit contextHelpChanged("");
Chris@218 856 }
Chris@189 857 }
Chris@189 858
Chris@64 859