Mercurial > hg > svgui
comparison widgets/PropertyBox.cpp @ 285:9dd432665059
* Add a colour database, and Add New Colour function to the colour combo
in property box. The colour property is only correctly handled in the
waveform layer so far.
* Add en_GB translation, to translate those annoying Color texts in the
Qt colour picker dialog.
author | Chris Cannam |
---|---|
date | Wed, 11 Jul 2007 17:21:37 +0000 |
parents | 3c402c6052f6 |
children | cd2492c5fe45 |
comparison
equal
deleted
inserted
replaced
284:1284955856ab | 285:9dd432665059 |
---|---|
18 | 18 |
19 #include "base/PropertyContainer.h" | 19 #include "base/PropertyContainer.h" |
20 #include "base/PlayParameters.h" | 20 #include "base/PlayParameters.h" |
21 #include "layer/Layer.h" | 21 #include "layer/Layer.h" |
22 #include "base/UnitDatabase.h" | 22 #include "base/UnitDatabase.h" |
23 #include "base/ColourDatabase.h" | |
23 #include "base/RangeMapper.h" | 24 #include "base/RangeMapper.h" |
24 | 25 |
25 #include "plugin/RealTimePluginFactory.h" | 26 #include "plugin/RealTimePluginFactory.h" |
26 #include "plugin/RealTimePluginInstance.h" | 27 #include "plugin/RealTimePluginInstance.h" |
27 #include "plugin/PluginXml.h" | 28 #include "plugin/PluginXml.h" |
29 #include "AudioDial.h" | 30 #include "AudioDial.h" |
30 #include "LEDButton.h" | 31 #include "LEDButton.h" |
31 | 32 |
32 #include "NotifyingCheckBox.h" | 33 #include "NotifyingCheckBox.h" |
33 #include "NotifyingComboBox.h" | 34 #include "NotifyingComboBox.h" |
35 #include "ColourNameDialog.h" | |
34 | 36 |
35 #include <QGridLayout> | 37 #include <QGridLayout> |
36 #include <QHBoxLayout> | 38 #include <QHBoxLayout> |
37 #include <QVBoxLayout> | 39 #include <QVBoxLayout> |
38 #include <QPushButton> | 40 #include <QPushButton> |
39 #include <QLabel> | 41 #include <QLabel> |
40 #include <QFrame> | 42 #include <QFrame> |
41 #include <QApplication> | 43 #include <QApplication> |
44 #include <QColorDialog> | |
45 #include <QInputDialog> | |
42 | 46 |
43 #include <cassert> | 47 #include <cassert> |
44 #include <iostream> | 48 #include <iostream> |
45 #include <cmath> | 49 #include <cmath> |
46 | 50 |
47 //#define DEBUG_PROPERTY_BOX 1 | 51 #define DEBUG_PROPERTY_BOX 1 |
48 | 52 |
49 PropertyBox::PropertyBox(PropertyContainer *container) : | 53 PropertyBox::PropertyBox(PropertyContainer *container) : |
50 m_container(container), | 54 m_container(container), |
51 m_showButton(0), | 55 m_showButton(0), |
52 m_playButton(0) | 56 m_playButton(0) |
88 | 92 |
89 m_layout->setRowStretch(m_layout->rowCount(), 10); | 93 m_layout->setRowStretch(m_layout->rowCount(), 10); |
90 | 94 |
91 connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()), | 95 connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()), |
92 this, SLOT(unitDatabaseChanged())); | 96 this, SLOT(unitDatabaseChanged())); |
97 | |
98 connect(ColourDatabase::getInstance(), SIGNAL(colourDatabaseChanged()), | |
99 this, SLOT(colourDatabaseChanged())); | |
93 | 100 |
94 #ifdef DEBUG_PROPERTY_BOX | 101 #ifdef DEBUG_PROPERTY_BOX |
95 std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl; | 102 std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl; |
96 #endif | 103 #endif |
97 } | 104 } |
395 break; | 402 break; |
396 } | 403 } |
397 | 404 |
398 case PropertyContainer::ValueProperty: | 405 case PropertyContainer::ValueProperty: |
399 case PropertyContainer::UnitsProperty: | 406 case PropertyContainer::UnitsProperty: |
407 case PropertyContainer::ColourProperty: | |
400 { | 408 { |
401 NotifyingComboBox *cb; | 409 NotifyingComboBox *cb; |
402 | 410 |
403 if (have) { | 411 if (have) { |
404 cb = dynamic_cast<NotifyingComboBox *>(m_propertyControllers[name]); | 412 cb = dynamic_cast<NotifyingComboBox *>(m_propertyControllers[name]); |
412 cb->setObjectName(name); | 420 cb->setObjectName(name); |
413 cb->setDuplicatesEnabled(false); | 421 cb->setDuplicatesEnabled(false); |
414 } | 422 } |
415 | 423 |
416 if (!have || rangeChanged) { | 424 if (!have || rangeChanged) { |
425 | |
417 cb->blockSignals(true); | 426 cb->blockSignals(true); |
418 cb->clear(); | 427 cb->clear(); |
428 cb->setEditable(false); | |
429 | |
419 if (type == PropertyContainer::ValueProperty) { | 430 if (type == PropertyContainer::ValueProperty) { |
431 | |
420 for (int i = min; i <= max; ++i) { | 432 for (int i = min; i <= max; ++i) { |
421 cb->addItem(m_container->getPropertyValueLabel(name, i)); | 433 cb->addItem(m_container->getPropertyValueLabel(name, i)); |
422 } | 434 } |
423 cb->setEditable(false); | 435 |
424 } else { | 436 } else if (type == PropertyContainer::UnitsProperty) { |
437 | |
425 QStringList units = UnitDatabase::getInstance()->getKnownUnits(); | 438 QStringList units = UnitDatabase::getInstance()->getKnownUnits(); |
426 for (int i = 0; i < units.size(); ++i) { | 439 for (int i = 0; i < units.size(); ++i) { |
427 cb->addItem(units[i]); | 440 cb->addItem(units[i]); |
428 } | 441 } |
442 | |
429 cb->setEditable(true); | 443 cb->setEditable(true); |
430 } | 444 |
445 } else { // ColourProperty | |
446 | |
447 ColourDatabase *db = ColourDatabase::getInstance(); | |
448 for (size_t i = 0; i < db->getColourCount(); ++i) { | |
449 QString name = db->getColourName(i); | |
450 QColor colour = db->getColour(i); | |
451 QPixmap pmap(12, 12); | |
452 pmap.fill(colour); | |
453 cb->addItem(pmap, name); | |
454 } | |
455 cb->addItem(tr("Add New Colour...")); | |
456 } | |
457 | |
431 cb->blockSignals(false); | 458 cb->blockSignals(false); |
432 if (cb->count() < 20 && cb->count() > cb->maxVisibleItems()) { | 459 if (cb->count() < 20 && cb->count() > cb->maxVisibleItems()) { |
433 cb->setMaxVisibleItems(cb->count()); | 460 cb->setMaxVisibleItems(cb->count()); |
434 } | 461 } |
435 } | 462 } |
450 } | 477 } |
451 m_propertyControllers[name] = cb; | 478 m_propertyControllers[name] = cb; |
452 } | 479 } |
453 | 480 |
454 cb->blockSignals(true); | 481 cb->blockSignals(true); |
455 if (type == PropertyContainer::ValueProperty) { | 482 if (type == PropertyContainer::ValueProperty || |
483 type == PropertyContainer::ColourProperty) { | |
456 if (cb->currentIndex() != value) { | 484 if (cb->currentIndex() != value) { |
457 cb->setCurrentIndex(value); | 485 cb->setCurrentIndex(value); |
458 } | 486 } |
459 } else { | 487 } else { |
460 QString unit = UnitDatabase::getInstance()->getUnitById(value); | 488 QString unit = UnitDatabase::getInstance()->getUnitById(value); |
521 { | 549 { |
522 blockSignals(true); | 550 blockSignals(true); |
523 | 551 |
524 PropertyContainer::PropertyList properties = m_container->getProperties(); | 552 PropertyContainer::PropertyList properties = m_container->getProperties(); |
525 for (size_t i = 0; i < properties.size(); ++i) { | 553 for (size_t i = 0; i < properties.size(); ++i) { |
526 updatePropertyEditor(properties[i]); | 554 if (m_container->getPropertyType(properties[i]) == |
555 PropertyContainer::UnitsProperty) { | |
556 updatePropertyEditor(properties[i]); | |
557 } | |
527 } | 558 } |
528 | 559 |
529 blockSignals(false); | 560 blockSignals(false); |
530 } | 561 } |
531 | 562 |
532 void | 563 void |
564 PropertyBox::colourDatabaseChanged() | |
565 { | |
566 blockSignals(true); | |
567 | |
568 PropertyContainer::PropertyList properties = m_container->getProperties(); | |
569 for (size_t i = 0; i < properties.size(); ++i) { | |
570 if (m_container->getPropertyType(properties[i]) == | |
571 PropertyContainer::ColourProperty) { | |
572 updatePropertyEditor(properties[i], true); | |
573 } | |
574 } | |
575 | |
576 blockSignals(false); | |
577 } | |
578 | |
579 void | |
533 PropertyBox::propertyControllerChanged(int value) | 580 PropertyBox::propertyControllerChanged(int value) |
534 { | 581 { |
535 QObject *obj = sender(); | 582 QObject *obj = sender(); |
536 QString name = obj->objectName(); | 583 QString name = obj->objectName(); |
537 | 584 |
541 #endif | 588 #endif |
542 | 589 |
543 PropertyContainer::PropertyType type = m_container->getPropertyType(name); | 590 PropertyContainer::PropertyType type = m_container->getPropertyType(name); |
544 | 591 |
545 if (type == PropertyContainer::UnitsProperty) { | 592 if (type == PropertyContainer::UnitsProperty) { |
593 | |
546 NotifyingComboBox *cb = dynamic_cast<NotifyingComboBox *>(obj); | 594 NotifyingComboBox *cb = dynamic_cast<NotifyingComboBox *>(obj); |
547 if (cb) { | 595 if (cb) { |
548 QString unit = cb->currentText(); | 596 QString unit = cb->currentText(); |
549 m_container->setPropertyWithCommand | 597 m_container->setPropertyWithCommand |
550 (name, UnitDatabase::getInstance()->getUnitId(unit)); | 598 (name, UnitDatabase::getInstance()->getUnitId(unit)); |
551 } | 599 } |
600 | |
601 } else if (type == PropertyContainer::ColourProperty) { | |
602 | |
603 if (value == int(ColourDatabase::getInstance()->getColourCount())) { | |
604 addNewColour(); | |
605 if (value == int(ColourDatabase::getInstance()->getColourCount())) { | |
606 propertyContainerPropertyChanged(m_container); | |
607 return; | |
608 } | |
609 } | |
610 m_container->setPropertyWithCommand(name, value); | |
611 | |
552 } else if (type != PropertyContainer::InvalidProperty) { | 612 } else if (type != PropertyContainer::InvalidProperty) { |
613 | |
553 m_container->setPropertyWithCommand(name, value); | 614 m_container->setPropertyWithCommand(name, value); |
554 } | 615 } |
555 | 616 |
556 updateContextHelp(obj); | 617 updateContextHelp(obj); |
618 } | |
619 | |
620 void | |
621 PropertyBox::addNewColour() | |
622 { | |
623 QColor newColour = QColorDialog::getColor(); | |
624 if (!newColour.isValid()) return; | |
625 | |
626 ColourNameDialog dialog(tr("Name New Colour"), | |
627 tr("Enter name for the new colour:"), | |
628 newColour, "", this); | |
629 dialog.showDarkBackgroundCheckbox(tr("Prefer black background for this colour")); | |
630 if (dialog.exec() == QDialog::Accepted) { | |
631 //!!! command | |
632 ColourDatabase *db = ColourDatabase::getInstance(); | |
633 int index = db->addColour(newColour, dialog.getColourName()); | |
634 db->setUseDarkBackground(index, dialog.isDarkBackgroundChecked()); | |
635 } | |
557 } | 636 } |
558 | 637 |
559 void | 638 void |
560 PropertyBox::playGainChanged(float gain) | 639 PropertyBox::playGainChanged(float gain) |
561 { | 640 { |