changeset 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 453f7da3534e
children 0f36cdf407a6
files layer/NoteLayer.cpp layer/TimeValueLayer.cpp widgets/PropertyBox.cpp widgets/PropertyBox.h
diffstat 4 files changed, 98 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/layer/NoteLayer.cpp	Thu May 11 11:35:46 2006 +0000
+++ b/layer/NoteLayer.cpp	Thu May 11 15:02:14 2006 +0000
@@ -71,6 +71,7 @@
     PropertyList list;
     list.push_back("Colour");
     list.push_back("Vertical Scale");
+    list.push_back("Scale Units");
     return list;
 }
 
@@ -79,12 +80,14 @@
 {
     if (name == "Colour") return tr("Colour");
     if (name == "Vertical Scale") return tr("Vertical Scale");
+    if (name == "Scale Units") return tr("Pitch Units");
     return "";
 }
 
 Layer::PropertyType
-NoteLayer::getPropertyType(const PropertyName &) const
+NoteLayer::getPropertyType(const PropertyName &name) const
 {
+    if (name == "Scale Units") return UnitsProperty;
     return ValueProperty;
 }
 
@@ -115,6 +118,13 @@
 	
 	deft = int(m_verticalScale);
 
+    } else if (name == "Scale Units") {
+
+        if (m_model) {
+            deft = UnitDatabase::getInstance()->getUnitId
+                (m_model->getScaleUnits());
+        }
+
     } else {
 	
 	deft = Layer::getPropertyRangeAndValue(name, min, max);
@@ -163,6 +173,12 @@
 	}
     } else if (name == "Vertical Scale") {
 	setVerticalScale(VerticalScale(value));
+    } else if (name == "Scale Units") {
+        if (m_model) {
+            m_model->setScaleUnits
+                (UnitDatabase::getInstance()->getUnitById(value));
+            emit modelChanged();
+        }
     }
 }
 
@@ -660,7 +676,8 @@
          ItemEditDialog::ShowTime |
          ItemEditDialog::ShowDuration |
          ItemEditDialog::ShowValue |
-         ItemEditDialog::ShowText);
+         ItemEditDialog::ShowText,
+         m_model->getScaleUnits());
 
     dialog->setFrameTime(note.frame);
     dialog->setValue(note.value);
--- a/layer/TimeValueLayer.cpp	Thu May 11 11:35:46 2006 +0000
+++ b/layer/TimeValueLayer.cpp	Thu May 11 15:02:14 2006 +0000
@@ -72,6 +72,7 @@
     list.push_back("Colour");
     list.push_back("Plot Type");
     list.push_back("Vertical Scale");
+    list.push_back("Scale Units");
     return list;
 }
 
@@ -81,13 +82,15 @@
     if (name == "Colour") return tr("Colour");
     if (name == "Plot Type") return tr("Plot Type");
     if (name == "Vertical Scale") return tr("Vertical Scale");
+    if (name == "Scale Units") return tr("Scale Units");
     return "";
 }
 
 Layer::PropertyType
 TimeValueLayer::getPropertyType(const PropertyName &name) const
 {
-    return ValueProperty;
+    if (name == "Scale Units") return UnitsProperty;
+    else return ValueProperty;
 }
 
 int
@@ -124,6 +127,13 @@
 	
 	deft = int(m_verticalScale);
 
+    } else if (name == "Scale Units") {
+
+        if (m_model) {
+            deft = UnitDatabase::getInstance()->getUnitId
+                (m_model->getScaleUnits());
+        }
+
     } else {
 	
 	deft = Layer::getPropertyRangeAndValue(name, min, max);
@@ -185,6 +195,12 @@
 	setPlotStyle(PlotStyle(value));
     } else if (name == "Vertical Scale") {
 	setVerticalScale(VerticalScale(value));
+    } else if (name == "Scale Units") {
+        if (m_model) {
+            m_model->setScaleUnits
+                (UnitDatabase::getInstance()->getUnitById(value));
+            emit modelChanged();
+        }
     }
 }
 
--- a/widgets/PropertyBox.cpp	Thu May 11 11:35:46 2006 +0000
+++ b/widgets/PropertyBox.cpp	Thu May 11 15:02:14 2006 +0000
@@ -19,6 +19,7 @@
 #include "base/PropertyContainer.h"
 #include "base/PlayParameters.h"
 #include "base/Layer.h"
+#include "base/UnitDatabase.h"
 
 #include "plugin/RealTimePluginFactory.h"
 #include "plugin/RealTimePluginInstance.h"
@@ -78,6 +79,9 @@
 
     m_layout->setRowStretch(m_layout->rowCount(), 10);
 
+    connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()),
+            this, SLOT(unitDatabaseChanged()));
+
 #ifdef DEBUG_PROPERTY_BOX
     std::cerr << "PropertyBox[" << this << "]::PropertyBox returning" << std::endl;
 #endif
@@ -341,6 +345,7 @@
     }
 
     case PropertyContainer::ValueProperty:
+    case PropertyContainer::UnitsProperty:
     {
 	QComboBox *cb;
 
@@ -354,11 +359,24 @@
 
 	    cb = new QComboBox();
 	    cb->setObjectName(name);
-	    for (int i = min; i <= max; ++i) {
-		cb->addItem(m_container->getPropertyValueLabel(name, i));
-	    }
+            cb->setDuplicatesEnabled(false);
+
+            if (type == PropertyContainer::ValueProperty) {
+                for (int i = min; i <= max; ++i) {
+                    cb->addItem(m_container->getPropertyValueLabel(name, i));
+                }
+                cb->setEditable(false);
+            } else {
+                QStringList units = UnitDatabase::getInstance()->getKnownUnits();
+                for (int i = 0; i < units.size(); ++i) {
+                    cb->addItem(units[i]);
+                }
+                cb->setEditable(true);
+            }
+
 	    connect(cb, SIGNAL(activated(int)),
 		    this, SLOT(propertyControllerChanged(int)));
+
 	    if (inGroup) {
 		cb->setToolTip(name);
 		m_groupLayouts[groupName]->addWidget(cb);
@@ -368,11 +386,23 @@
 	    m_propertyControllers[name] = cb;
 	}
 
-	if (cb->currentIndex() != value) {
-	    cb->blockSignals(true);
-	    cb->setCurrentIndex(value);
-	    cb->blockSignals(false);
-	}
+        cb->blockSignals(true);
+        if (type == PropertyContainer::ValueProperty) {
+            if (cb->currentIndex() != value) {
+                cb->setCurrentIndex(value);
+            }
+        } else {
+            QString unit = UnitDatabase::getInstance()->getUnitById(value);
+            if (cb->currentText() != unit) {
+                for (int i = 0; i < cb->count(); ++i) {
+                    if (cb->itemText(i) == unit) {
+                        cb->setCurrentIndex(i);
+                        break;
+                    }
+                }
+            }
+        }
+        cb->blockSignals(false);
 
 #ifdef Q_WS_MAC
 	// Crashes on startup without this, for some reason
@@ -409,6 +439,19 @@
 }
 
 void
+PropertyBox::unitDatabaseChanged()
+{
+    blockSignals(true);
+
+    PropertyContainer::PropertyList properties = m_container->getProperties();
+    for (size_t i = 0; i < properties.size(); ++i) {
+	updatePropertyEditor(properties[i]);
+    }
+
+    blockSignals(false);
+}    
+
+void
 PropertyBox::propertyControllerChanged(int value)
 {
     QObject *obj = sender();
@@ -420,8 +463,15 @@
 #endif
     
     PropertyContainer::PropertyType type = m_container->getPropertyType(name);
-    
-    if (type != PropertyContainer::InvalidProperty) {
+
+    if (type == PropertyContainer::UnitsProperty) {
+        QComboBox *cb = dynamic_cast<QComboBox *>(obj);
+        if (cb) {
+            QString unit = cb->currentText();
+            m_container->setPropertyWithCommand
+                (name, UnitDatabase::getInstance()->getUnitId(unit));
+        }
+    } else if (type != PropertyContainer::InvalidProperty) {
 	m_container->setPropertyWithCommand(name, value);
     }
 
--- a/widgets/PropertyBox.h	Thu May 11 11:35:46 2006 +0000
+++ b/widgets/PropertyBox.h	Thu May 11 15:02:14 2006 +0000
@@ -57,6 +57,8 @@
 
     void populateViewPlayFrame();
 
+    void unitDatabaseChanged();
+
     void editPlugin();
 
 protected: