Mercurial > hg > svgui
diff 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 |
line wrap: on
line diff
--- a/widgets/PropertyBox.cpp Fri Jul 06 15:17:35 2007 +0000 +++ b/widgets/PropertyBox.cpp Wed Jul 11 17:21:37 2007 +0000 @@ -20,6 +20,7 @@ #include "base/PlayParameters.h" #include "layer/Layer.h" #include "base/UnitDatabase.h" +#include "base/ColourDatabase.h" #include "base/RangeMapper.h" #include "plugin/RealTimePluginFactory.h" @@ -31,6 +32,7 @@ #include "NotifyingCheckBox.h" #include "NotifyingComboBox.h" +#include "ColourNameDialog.h" #include <QGridLayout> #include <QHBoxLayout> @@ -39,12 +41,14 @@ #include <QLabel> #include <QFrame> #include <QApplication> +#include <QColorDialog> +#include <QInputDialog> #include <cassert> #include <iostream> #include <cmath> -//#define DEBUG_PROPERTY_BOX 1 +#define DEBUG_PROPERTY_BOX 1 PropertyBox::PropertyBox(PropertyContainer *container) : m_container(container), @@ -91,6 +95,9 @@ connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()), this, SLOT(unitDatabaseChanged())); + connect(ColourDatabase::getInstance(), SIGNAL(colourDatabaseChanged()), + this, SLOT(colourDatabaseChanged())); + #ifdef DEBUG_PROPERTY_BOX std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl; #endif @@ -397,6 +404,7 @@ case PropertyContainer::ValueProperty: case PropertyContainer::UnitsProperty: + case PropertyContainer::ColourProperty: { NotifyingComboBox *cb; @@ -414,20 +422,39 @@ } if (!have || rangeChanged) { + cb->blockSignals(true); cb->clear(); + cb->setEditable(false); + if (type == PropertyContainer::ValueProperty) { + for (int i = min; i <= max; ++i) { cb->addItem(m_container->getPropertyValueLabel(name, i)); } - cb->setEditable(false); - } else { + + } else if (type == PropertyContainer::UnitsProperty) { + QStringList units = UnitDatabase::getInstance()->getKnownUnits(); for (int i = 0; i < units.size(); ++i) { cb->addItem(units[i]); } + cb->setEditable(true); - } + + } else { // ColourProperty + + ColourDatabase *db = ColourDatabase::getInstance(); + for (size_t i = 0; i < db->getColourCount(); ++i) { + QString name = db->getColourName(i); + QColor colour = db->getColour(i); + QPixmap pmap(12, 12); + pmap.fill(colour); + cb->addItem(pmap, name); + } + cb->addItem(tr("Add New Colour...")); + } + cb->blockSignals(false); if (cb->count() < 20 && cb->count() > cb->maxVisibleItems()) { cb->setMaxVisibleItems(cb->count()); @@ -452,7 +479,8 @@ } cb->blockSignals(true); - if (type == PropertyContainer::ValueProperty) { + if (type == PropertyContainer::ValueProperty || + type == PropertyContainer::ColourProperty) { if (cb->currentIndex() != value) { cb->setCurrentIndex(value); } @@ -523,7 +551,26 @@ PropertyContainer::PropertyList properties = m_container->getProperties(); for (size_t i = 0; i < properties.size(); ++i) { - updatePropertyEditor(properties[i]); + if (m_container->getPropertyType(properties[i]) == + PropertyContainer::UnitsProperty) { + updatePropertyEditor(properties[i]); + } + } + + blockSignals(false); +} + +void +PropertyBox::colourDatabaseChanged() +{ + blockSignals(true); + + PropertyContainer::PropertyList properties = m_container->getProperties(); + for (size_t i = 0; i < properties.size(); ++i) { + if (m_container->getPropertyType(properties[i]) == + PropertyContainer::ColourProperty) { + updatePropertyEditor(properties[i], true); + } } blockSignals(false); @@ -543,18 +590,50 @@ PropertyContainer::PropertyType type = m_container->getPropertyType(name); if (type == PropertyContainer::UnitsProperty) { + NotifyingComboBox *cb = dynamic_cast<NotifyingComboBox *>(obj); if (cb) { QString unit = cb->currentText(); m_container->setPropertyWithCommand (name, UnitDatabase::getInstance()->getUnitId(unit)); } + + } else if (type == PropertyContainer::ColourProperty) { + + if (value == int(ColourDatabase::getInstance()->getColourCount())) { + addNewColour(); + if (value == int(ColourDatabase::getInstance()->getColourCount())) { + propertyContainerPropertyChanged(m_container); + return; + } + } + m_container->setPropertyWithCommand(name, value); + } else if (type != PropertyContainer::InvalidProperty) { + m_container->setPropertyWithCommand(name, value); } updateContextHelp(obj); } + +void +PropertyBox::addNewColour() +{ + QColor newColour = QColorDialog::getColor(); + if (!newColour.isValid()) return; + + ColourNameDialog dialog(tr("Name New Colour"), + tr("Enter name for the new colour:"), + newColour, "", this); + dialog.showDarkBackgroundCheckbox(tr("Prefer black background for this colour")); + if (dialog.exec() == QDialog::Accepted) { + //!!! command + ColourDatabase *db = ColourDatabase::getInstance(); + int index = db->addColour(newColour, dialog.getColourName()); + db->setUseDarkBackground(index, dialog.isDarkBackgroundChecked()); + } +} void PropertyBox::playGainChanged(float gain)