comparison widgets/PropertyBox.cpp @ 100:0db5e7492ce8

* Add units repository, and unit property on time-value and note layers.
author Chris Cannam
date Thu, 11 May 2006 15:02:14 +0000
parents 4b98bda7e94d
children bf196d6e8998
comparison
equal deleted inserted replaced
99:453f7da3534e 100:0db5e7492ce8
17 #include "PluginParameterDialog.h" 17 #include "PluginParameterDialog.h"
18 18
19 #include "base/PropertyContainer.h" 19 #include "base/PropertyContainer.h"
20 #include "base/PlayParameters.h" 20 #include "base/PlayParameters.h"
21 #include "base/Layer.h" 21 #include "base/Layer.h"
22 #include "base/UnitDatabase.h"
22 23
23 #include "plugin/RealTimePluginFactory.h" 24 #include "plugin/RealTimePluginFactory.h"
24 #include "plugin/RealTimePluginInstance.h" 25 #include "plugin/RealTimePluginInstance.h"
25 #include "plugin/PluginXml.h" 26 #include "plugin/PluginXml.h"
26 27
75 } 76 }
76 77
77 blockSignals(false); 78 blockSignals(false);
78 79
79 m_layout->setRowStretch(m_layout->rowCount(), 10); 80 m_layout->setRowStretch(m_layout->rowCount(), 10);
81
82 connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()),
83 this, SLOT(unitDatabaseChanged()));
80 84
81 #ifdef DEBUG_PROPERTY_BOX 85 #ifdef DEBUG_PROPERTY_BOX
82 std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl; 86 std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl;
83 #endif 87 #endif
84 } 88 }
339 } 343 }
340 break; 344 break;
341 } 345 }
342 346
343 case PropertyContainer::ValueProperty: 347 case PropertyContainer::ValueProperty:
348 case PropertyContainer::UnitsProperty:
344 { 349 {
345 QComboBox *cb; 350 QComboBox *cb;
346 351
347 if (have) { 352 if (have) {
348 cb = dynamic_cast<QComboBox *>(m_propertyControllers[name]); 353 cb = dynamic_cast<QComboBox *>(m_propertyControllers[name]);
352 std::cerr << "PropertyBox: creating new combobox" << std::endl; 357 std::cerr << "PropertyBox: creating new combobox" << std::endl;
353 #endif 358 #endif
354 359
355 cb = new QComboBox(); 360 cb = new QComboBox();
356 cb->setObjectName(name); 361 cb->setObjectName(name);
357 for (int i = min; i <= max; ++i) { 362 cb->setDuplicatesEnabled(false);
358 cb->addItem(m_container->getPropertyValueLabel(name, i)); 363
359 } 364 if (type == PropertyContainer::ValueProperty) {
365 for (int i = min; i <= max; ++i) {
366 cb->addItem(m_container->getPropertyValueLabel(name, i));
367 }
368 cb->setEditable(false);
369 } else {
370 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
371 for (int i = 0; i < units.size(); ++i) {
372 cb->addItem(units[i]);
373 }
374 cb->setEditable(true);
375 }
376
360 connect(cb, SIGNAL(activated(int)), 377 connect(cb, SIGNAL(activated(int)),
361 this, SLOT(propertyControllerChanged(int))); 378 this, SLOT(propertyControllerChanged(int)));
379
362 if (inGroup) { 380 if (inGroup) {
363 cb->setToolTip(name); 381 cb->setToolTip(name);
364 m_groupLayouts[groupName]->addWidget(cb); 382 m_groupLayouts[groupName]->addWidget(cb);
365 } else { 383 } else {
366 m_layout->addWidget(cb, row, 1, 1, 2); 384 m_layout->addWidget(cb, row, 1, 1, 2);
367 } 385 }
368 m_propertyControllers[name] = cb; 386 m_propertyControllers[name] = cb;
369 } 387 }
370 388
371 if (cb->currentIndex() != value) { 389 cb->blockSignals(true);
372 cb->blockSignals(true); 390 if (type == PropertyContainer::ValueProperty) {
373 cb->setCurrentIndex(value); 391 if (cb->currentIndex() != value) {
374 cb->blockSignals(false); 392 cb->setCurrentIndex(value);
375 } 393 }
394 } else {
395 QString unit = UnitDatabase::getInstance()->getUnitById(value);
396 if (cb->currentText() != unit) {
397 for (int i = 0; i < cb->count(); ++i) {
398 if (cb->itemText(i) == unit) {
399 cb->setCurrentIndex(i);
400 break;
401 }
402 }
403 }
404 }
405 cb->blockSignals(false);
376 406
377 #ifdef Q_WS_MAC 407 #ifdef Q_WS_MAC
378 // Crashes on startup without this, for some reason 408 // Crashes on startup without this, for some reason
379 cb->setMinimumSize(QSize(10, 10)); 409 cb->setMinimumSize(QSize(10, 10));
380 #endif 410 #endif
407 437
408 blockSignals(false); 438 blockSignals(false);
409 } 439 }
410 440
411 void 441 void
442 PropertyBox::unitDatabaseChanged()
443 {
444 blockSignals(true);
445
446 PropertyContainer::PropertyList properties = m_container->getProperties();
447 for (size_t i = 0; i < properties.size(); ++i) {
448 updatePropertyEditor(properties[i]);
449 }
450
451 blockSignals(false);
452 }
453
454 void
412 PropertyBox::propertyControllerChanged(int value) 455 PropertyBox::propertyControllerChanged(int value)
413 { 456 {
414 QObject *obj = sender(); 457 QObject *obj = sender();
415 QString name = obj->objectName(); 458 QString name = obj->objectName();
416 459
418 std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString() 461 std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString()
419 << ", " << value << ")" << std::endl; 462 << ", " << value << ")" << std::endl;
420 #endif 463 #endif
421 464
422 PropertyContainer::PropertyType type = m_container->getPropertyType(name); 465 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
423 466
424 if (type != PropertyContainer::InvalidProperty) { 467 if (type == PropertyContainer::UnitsProperty) {
468 QComboBox *cb = dynamic_cast<QComboBox *>(obj);
469 if (cb) {
470 QString unit = cb->currentText();
471 m_container->setPropertyWithCommand
472 (name, UnitDatabase::getInstance()->getUnitId(unit));
473 }
474 } else if (type != PropertyContainer::InvalidProperty) {
425 m_container->setPropertyWithCommand(name, value); 475 m_container->setPropertyWithCommand(name, value);
426 } 476 }
427 477
428 if (type == PropertyContainer::RangeProperty) { 478 if (type == PropertyContainer::RangeProperty) {
429 AudioDial *dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]); 479 AudioDial *dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);