19 #include "base/PropertyContainer.h" 20 #include "base/PlayParameters.h" 21 #include "base/PlayParameterRepository.h" 24 #include "base/UnitDatabase.h" 25 #include "base/RangeMapper.h" 36 #include <QGridLayout> 37 #include <QHBoxLayout> 38 #include <QVBoxLayout> 39 #include <QPushButton> 42 #include <QApplication> 43 #include <QColorDialog> 44 #include <QInputDialog> 54 m_container(container),
58 #ifdef DEBUG_PROPERTY_BOX 59 cerr <<
"PropertyBox[" <<
this <<
"(\"" <<
60 container->getPropertyContainerName() <<
"\" at " << container <<
")]::PropertyBox" << endl;
83 PropertyContainer::PropertyList properties =
m_container->getProperties();
89 for (i = 0; i < properties.size(); ++i) {
103 #ifdef DEBUG_PROPERTY_BOX 104 cerr <<
"PropertyBox[" <<
this <<
"]::PropertyBox returning" << endl;
110 #ifdef DEBUG_PROPERTY_BOX 111 cerr <<
"PropertyBox[" <<
this <<
"]::~PropertyBox" << endl;
118 #ifdef DEBUG_PROPERTY_BOX 119 cerr <<
"PropertyBox[" <<
this <<
":" <<
m_container <<
"]::populateViewPlayFrame" << endl;
131 disconnect(layer, SIGNAL(modelReplaced()),
133 connect(layer, SIGNAL(modelReplaced()),
137 PlayParameters *params =
m_container->getPlayParameters();
138 if (!params && !layer)
return;
144 QHBoxLayout *layout =
new QHBoxLayout;
147 layout->setMargin(layout->margin() / 2);
149 #ifdef DEBUG_PROPERTY_BOX 150 SVDEBUG <<
"PropertyBox::populateViewPlayFrame: container " <<
m_container <<
" (name " <<
m_container->getPropertyContainerName() <<
") params " << params << endl;
154 QLabel *showLabel =
new QLabel(tr(
"Show"));
155 layout->addWidget(showLabel);
156 layout->setAlignment(showLabel, Qt::AlignVCenter);
171 QLabel *playLabel =
new QLabel(tr(
"Play"));
172 layout->addWidget(playLabel);
173 layout->setAlignment(playLabel, Qt::AlignVCenter);
188 layout->insertStretch(-1, 10);
190 if (params->getPlayClipId() !=
"") {
191 QPushButton *playParamButton =
192 new QPushButton(QIcon(
":icons/faders.png"),
"");
193 playParamButton->setFixedWidth(24);
194 playParamButton->setFixedHeight(24);
195 layout->addWidget(playParamButton);
196 connect(playParamButton, SIGNAL(clicked()),
201 layout->addWidget(gainDial);
203 gainDial->setMinimum(-50);
204 gainDial->setMaximum(50);
205 gainDial->setPageStep(1);
206 gainDial->setFixedWidth(24);
207 gainDial->setFixedHeight(24);
208 gainDial->setNotchesVisible(
false);
210 gainDial->setObjectName(tr(
"Playback Gain"));
212 (-50, 50, -25, 25, tr(
"dB")));
214 connect(gainDial, SIGNAL(valueChanged(
int)),
219 gainDial, SLOT(setValue(
int)));
220 connect(gainDial, SIGNAL(mouseEntered()),
222 connect(gainDial, SIGNAL(mouseLeft()),
225 layout->setAlignment(gainDial, Qt::AlignVCenter);
228 layout->addWidget(panDial);
230 panDial->setMinimum(-50);
231 panDial->setMaximum(50);
232 panDial->setPageStep(1);
233 panDial->setFixedWidth(24);
234 panDial->setFixedHeight(24);
235 panDial->setNotchesVisible(
false);
236 panDial->setToolTip(tr(
"Playback Pan / Balance"));
238 panDial->setObjectName(tr(
"Playback Pan / Balance"));
240 connect(panDial, SIGNAL(valueChanged(
int)),
245 panDial, SLOT(setValue(
int)));
246 connect(panDial, SIGNAL(mouseEntered()),
248 connect(panDial, SIGNAL(mouseLeft()),
251 layout->setAlignment(panDial, Qt::AlignVCenter);
255 layout->insertStretch(-1, 10);
263 PropertyContainer::PropertyType type =
m_container->getPropertyType(name);
266 int min = 0, max = 0, value = 0, deflt = 0;
267 value =
m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
272 QString groupName =
m_container->getPropertyGroupName(name);
273 QString propertyLabel =
m_container->getPropertyLabel(name);
274 QString iconName =
m_container->getPropertyIconName(name);
276 #ifdef DEBUG_PROPERTY_BOX 277 cerr <<
"PropertyBox[" <<
this 278 <<
"(\"" <<
m_container->getPropertyContainerName()
280 cerr <<
"::updatePropertyEditor(\"" << name <<
"\"):";
281 cerr <<
" value " << value <<
", have " << have <<
", group \"" 282 << groupName <<
"\"" << endl;
285 bool inGroup = (groupName != QString());
290 #ifdef DEBUG_PROPERTY_BOX 291 cerr <<
"PropertyBox: adding label \"" << groupName <<
"\" and frame for group for \"" << name <<
"\"" << endl;
295 m_layout->addWidget(frame, row, 1, 1, 2);
301 #ifdef DEBUG_PROPERTY_BOX 302 cerr <<
"PropertyBox: adding label \"" << propertyLabel <<
"\"" << endl;
310 case PropertyContainer::ToggleProperty:
312 QAbstractButton *button = 0;
318 #ifdef DEBUG_PROPERTY_BOX 319 cerr <<
"PropertyBox: creating new checkbox" << endl;
321 if (iconName !=
"") {
323 button->setCheckable(
true);
325 button->setIcon(icon);
326 button->setObjectName(name);
327 button->setFixedSize(QSize(18, 18));
330 button->setObjectName(name);
332 connect(button, SIGNAL(toggled(
bool)),
334 connect(button, SIGNAL(mouseEntered()),
336 connect(button, SIGNAL(mouseLeft()),
339 button->setToolTip(propertyLabel);
343 m_layout->addWidget(button, row, 1, 1, 2);
348 if (button->isChecked() != (value > 0)) {
349 button->blockSignals(
true);
350 button->setChecked(value > 0);
351 button->blockSignals(
false);
356 case PropertyContainer::RangeProperty:
364 dial->blockSignals(
true);
365 dial->setMinimum(min);
366 dial->setMaximum(max);
368 dial->blockSignals(
false);
372 #ifdef DEBUG_PROPERTY_BOX 373 cerr <<
"PropertyBox: creating new dial" << endl;
376 dial->setObjectName(name);
377 dial->setMinimum(min);
378 dial->setMaximum(max);
379 dial->setPageStep(1);
380 dial->setNotchesVisible((max - min) <= 12);
384 connect(dial, SIGNAL(valueChanged(
int)),
386 connect(dial, SIGNAL(mouseEntered()),
388 connect(dial, SIGNAL(mouseLeft()),
392 dial->setFixedWidth(24);
393 dial->setFixedHeight(24);
397 dial->setFixedWidth(32);
398 dial->setFixedHeight(32);
401 connect(dial, SIGNAL(valueChanged(
int)),
402 label, SLOT(setNum(
int)));
403 label->setNum(value);
410 if (dial->value() != value) {
411 dial->blockSignals(
true);
413 dial->blockSignals(
false);
418 case PropertyContainer::ValueProperty:
419 case PropertyContainer::UnitsProperty:
420 case PropertyContainer::ColourProperty:
428 #ifdef DEBUG_PROPERTY_BOX 429 cerr <<
"PropertyBox: creating new combobox" << endl;
433 cb->setObjectName(name);
434 cb->setDuplicatesEnabled(
false);
437 if (!have || rangeChanged) {
439 cb->blockSignals(
true);
441 cb->setEditable(
false);
443 if (type == PropertyContainer::ValueProperty) {
445 for (
int i = min; i <= max; ++i) {
446 cb->addItem(
m_container->getPropertyValueLabel(name, i));
449 }
else if (type == PropertyContainer::UnitsProperty) {
451 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
452 for (
int i = 0; i < units.size(); ++i) {
453 cb->addItem(units[i]);
456 cb->setEditable(
true);
468 cb->addItem(tr(
"Add New Colour..."));
471 cb->blockSignals(
false);
472 if (cb->count() < 20 && cb->count() > cb->maxVisibleItems()) {
473 cb->setMaxVisibleItems(cb->count());
478 connect(cb, SIGNAL(activated(
int)),
480 connect(cb, SIGNAL(mouseEntered()),
482 connect(cb, SIGNAL(mouseLeft()),
486 cb->setToolTip(propertyLabel);
490 m_layout->addWidget(cb, row, 1, 1, 2);
495 cb->blockSignals(
true);
496 if (type == PropertyContainer::ValueProperty ||
497 type == PropertyContainer::ColourProperty) {
498 if (cb->currentIndex() != value) {
499 cb->setCurrentIndex(value);
502 QString unit = UnitDatabase::getInstance()->getUnitById(value);
503 if (cb->currentText() != unit) {
504 for (
int i = 0; i < cb->count(); ++i) {
505 if (cb->itemText(i) == unit) {
506 cb->setCurrentIndex(i);
512 cb->blockSignals(
false);
516 cb->setMinimumSize(QSize(10, 10));
522 case PropertyContainer::InvalidProperty:
533 #ifdef DEBUG_PROPERTY_BOX 534 SVDEBUG <<
"PropertyBox::propertyContainerPropertyChanged" << endl;
537 PropertyContainer::PropertyList properties =
m_container->getProperties();
542 for (i = 0; i < properties.size(); ++i) {
554 PropertyContainer::PropertyList properties =
m_container->getProperties();
555 for (
size_t i = 0; i < properties.size(); ++i) {
565 #ifdef DEBUG_PROPERTY_BOX 566 cerr <<
"PropertyBox[" <<
this <<
"]: unitDatabaseChanged" << endl;
574 PropertyContainer::PropertyList properties =
m_container->getProperties();
575 for (
size_t i = 0; i < properties.size(); ++i) {
577 PropertyContainer::UnitsProperty) {
590 PropertyContainer::PropertyList properties =
m_container->getProperties();
591 for (
size_t i = 0; i < properties.size(); ++i) {
593 PropertyContainer::ColourProperty) {
610 QObject *obj = sender();
611 QString name = obj->objectName();
613 #ifdef DEBUG_PROPERTY_BOX 614 SVDEBUG <<
"PropertyBox::propertyControllerChanged(" << name <<
", " << value <<
")" << endl;
617 PropertyContainer::PropertyType type =
m_container->getPropertyType(name);
621 if (type == PropertyContainer::UnitsProperty) {
625 QString unit = cb->currentText();
627 (name, UnitDatabase::getInstance()->getUnitId(unit));
630 }
else if (type == PropertyContainer::ColourProperty) {
639 c =
m_container->getSetPropertyCommand(name, value);
641 }
else if (type != PropertyContainer::InvalidProperty) {
643 c =
m_container->getSetPropertyCommand(name, value);
654 QColor newColour = QColorDialog::getColor();
655 if (!newColour.isValid())
return;
658 tr(
"Enter a name for the new colour:"),
659 newColour, newColour.name(),
this);
661 if (dialog.exec() == QDialog::Accepted) {
664 int index = db->
addColour(newColour, dialog.getColourName());
678 PlayParameters *params =
m_container->getPlayParameters();
681 if (params->isPlayAudible() != audible) {
682 PlayParameterRepository::EditCommand *command =
683 new PlayParameterRepository::EditCommand(params);
684 command->setPlayAudible(audible);
692 int dialValue = lrint(log10(gain) * 20.0);
693 if (dialValue < -50) dialValue = -50;
694 if (dialValue > 50) dialValue = 50;
701 QObject *obj = sender();
703 PlayParameters *params =
m_container->getPlayParameters();
706 float gain = pow(10,
float(dialValue) / 20.0);
708 if (params->getPlayGain() != gain) {
709 PlayParameterRepository::EditCommand *command =
710 new PlayParameterRepository::EditCommand(params);
711 command->setPlayGain(gain);
721 int dialValue = lrint(pan * 50.0);
722 if (dialValue < -50) dialValue = -50;
723 if (dialValue > 50) dialValue = 50;
730 QObject *obj = sender();
732 PlayParameters *params =
m_container->getPlayParameters();
735 float pan = float(dialValue) / 50.0;
736 if (pan < -1.0) pan = -1.0;
737 if (pan > 1.0) pan = 1.0;
739 if (params->getPlayPan() != pan) {
740 PlayParameterRepository::EditCommand *command =
741 new PlayParameterRepository::EditCommand(params);
742 command->setPlayPan(pan);
752 PlayParameters *params =
m_container->getPlayParameters();
755 QString clip = params->getPlayClipId();
757 PlayParameterRepository::EditCommand *command =
758 new PlayParameterRepository::EditCommand(params);
760 QInputDialog *dialog =
new QInputDialog(
this);
762 QDir dir(
":/samples");
763 QStringList clipFiles = dir.entryList(QStringList() <<
"*.wav", QDir::Files);
766 foreach (QString str, clipFiles) {
767 clips.push_back(str.replace(
".wav",
""));
769 dialog->setComboBoxItems(clips);
771 dialog->setLabelText(tr(
"Set playback clip:"));
773 QComboBox *cb = dialog->findChild<QComboBox *>();
775 for (
int i = 0; i < cb->count(); ++i) {
776 if (cb->itemText(i) == clip) {
777 cb->setCurrentIndex(i);
782 connect(dialog, SIGNAL(textValueChanged(QString)),
785 if (dialog->exec() == QDialog::Accepted) {
786 QString newClip = dialog->textValue();
787 command->setPlayClipId(newClip);
793 params->setPlayClipId(clip);
802 PlayParameters *params =
m_container->getPlayParameters();
805 params->setPlayClipId(
id);
823 QWidget *w = dynamic_cast<QWidget *>(o);
827 QString cname =
m_container->getPropertyContainerName();
828 if (cname ==
"")
return;
830 QString wname = w->objectName();
833 AudioDial *dial = dynamic_cast<AudioDial *>(w);
839 extraText = tr(
" (current value: %1%2)").arg(mv).arg(unit);
841 extraText = tr(
" (current value: %1)").arg(mv);
849 }
else if (wname ==
"") {
851 }
else if (dynamic_cast<QAbstractButton *>(w)) {
853 .arg(wname).arg(cname));
856 .arg(wname).arg(cname).arg(extraText));
863 if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
Very trivial enhancement to QComboBox to make it emit signals when the mouse enters and leaves (for c...
QString getColourName(int c) const
void propertyContainerPropertyChanged(PropertyContainer *)
The base class for visual representations of the data found in a Model.
void playGainDialChanged(int)
Very trivial enhancement to QCheckBox to make it emit signals when the mouse enters and leaves (for c...
void setDefaultValue(int defaultValue)
void mouseEnteredWidget()
void playPanDialChanged(int)
std::map< QString, QWidget * > m_propertyControllers
void updateContextHelp(QObject *o)
void colourDatabaseChanged()
void setMeterColor(const QColor &color)
Set the colour of the meter (the highlighted area around the knob that shows the current value).
float mappedValue() const
void propertyControllerChanged(int)
QPixmap getExamplePixmap(int index, QSize size) const
void addCommand(Command *command)
Add a command to the command history.
int addColour(QColor, QString)
void updatePropertyEditor(PropertyContainer::PropertyName, bool rangeChanged=false)
void contextHelpChanged(const QString &)
void setUseDarkBackground(int c, bool dark)
void playAudibleChanged(bool)
AudioDial is a nicer-looking QDial that by default reacts to mouse movement on horizontal and vertica...
void layerVisibilityChanged(bool)
void playPanChanged(float)
void propertyContainerPropertyRangeChanged(PropertyContainer *)
void changePlayPanDial(int)
std::map< QString, QGridLayout * > m_groupLayouts
PropertyContainer * m_container
int getColourCount() const
void editPlayParameters()
static CommandHistory * getInstance()
void playGainChanged(float)
PropertyBox(PropertyContainer *)
void setRangeMapper(RangeMapper *mapper)
void populateViewPlayFrame()
void playAudibleButtonChanged(bool)
void playClipChanged(QString)
void changePlayGainDial(int)
void unitDatabaseChanged()
static ColourDatabase * getInstance()
const RangeMapper * rangeMapper() const
void setShowToolTip(bool show)