svgui  1.9
PropertyBox.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #include "PropertyBox.h"
17 #include "PluginParameterDialog.h"
18 
19 #include "base/PropertyContainer.h"
20 #include "base/PlayParameters.h"
21 #include "base/PlayParameterRepository.h"
22 #include "layer/Layer.h"
23 #include "layer/ColourDatabase.h"
24 #include "base/UnitDatabase.h"
25 #include "base/RangeMapper.h"
26 
27 #include "AudioDial.h"
28 #include "LEDButton.h"
29 #include "IconLoader.h"
30 
31 #include "NotifyingCheckBox.h"
32 #include "NotifyingComboBox.h"
33 #include "NotifyingPushButton.h"
34 #include "ColourNameDialog.h"
35 
36 #include <QGridLayout>
37 #include <QHBoxLayout>
38 #include <QVBoxLayout>
39 #include <QPushButton>
40 #include <QLabel>
41 #include <QFrame>
42 #include <QApplication>
43 #include <QColorDialog>
44 #include <QInputDialog>
45 #include <QDir>
46 
47 #include <cassert>
48 #include <iostream>
49 #include <cmath>
50 
51 //#define DEBUG_PROPERTY_BOX 1
52 
53 PropertyBox::PropertyBox(PropertyContainer *container) :
54  m_container(container),
55  m_showButton(0),
56  m_playButton(0)
57 {
58 #ifdef DEBUG_PROPERTY_BOX
59  cerr << "PropertyBox[" << this << "(\"" <<
60  container->getPropertyContainerName() << "\" at " << container << ")]::PropertyBox" << endl;
61 #endif
62 
63  m_mainBox = new QVBoxLayout;
64  setLayout(m_mainBox);
65 
66 // m_nameWidget = new QLabel;
67 // m_mainBox->addWidget(m_nameWidget);
68 // m_nameWidget->setText(container->objectName());
69 
70  m_mainWidget = new QWidget;
71  m_mainBox->addWidget(m_mainWidget);
72  m_mainBox->insertStretch(2, 10);
73 
74  m_viewPlayFrame = 0;
76 
77  m_layout = new QGridLayout;
78  m_layout->setMargin(0);
79  m_layout->setHorizontalSpacing(2);
80  m_layout->setVerticalSpacing(1);
81  m_mainWidget->setLayout(m_layout);
82 
83  PropertyContainer::PropertyList properties = m_container->getProperties();
84 
85  blockSignals(true);
86 
87  size_t i;
88 
89  for (i = 0; i < properties.size(); ++i) {
90  updatePropertyEditor(properties[i]);
91  }
92 
93  blockSignals(false);
94 
95  m_layout->setRowStretch(m_layout->rowCount(), 10);
96 
97  connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()),
98  this, SLOT(unitDatabaseChanged()));
99 
101  this, SLOT(colourDatabaseChanged()));
102 
103 #ifdef DEBUG_PROPERTY_BOX
104  cerr << "PropertyBox[" << this << "]::PropertyBox returning" << endl;
105 #endif
106 }
107 
109 {
110 #ifdef DEBUG_PROPERTY_BOX
111  cerr << "PropertyBox[" << this << "]::~PropertyBox" << endl;
112 #endif
113 }
114 
115 void
117 {
118 #ifdef DEBUG_PROPERTY_BOX
119  cerr << "PropertyBox[" << this << ":" << m_container << "]::populateViewPlayFrame" << endl;
120 #endif
121 
122  if (m_viewPlayFrame) {
123  delete m_viewPlayFrame;
124  m_viewPlayFrame = 0;
125  }
126 
127  if (!m_container) return;
128 
129  Layer *layer = dynamic_cast<Layer *>(m_container);
130  if (layer) {
131  disconnect(layer, SIGNAL(modelReplaced()),
132  this, SLOT(populateViewPlayFrame()));
133  connect(layer, SIGNAL(modelReplaced()),
134  this, SLOT(populateViewPlayFrame()));
135  }
136 
137  PlayParameters *params = m_container->getPlayParameters();
138  if (!params && !layer) return;
139 
140  m_viewPlayFrame = new QFrame;
141  m_viewPlayFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
142  m_mainBox->addWidget(m_viewPlayFrame);
143 
144  QHBoxLayout *layout = new QHBoxLayout;
145  m_viewPlayFrame->setLayout(layout);
146 
147  layout->setMargin(layout->margin() / 2);
148 
149 #ifdef DEBUG_PROPERTY_BOX
150  SVDEBUG << "PropertyBox::populateViewPlayFrame: container " << m_container << " (name " << m_container->getPropertyContainerName() << ") params " << params << endl;
151 #endif
152 
153  if (layer) {
154  QLabel *showLabel = new QLabel(tr("Show"));
155  layout->addWidget(showLabel);
156  layout->setAlignment(showLabel, Qt::AlignVCenter);
157 
158  m_showButton = new LEDButton(Qt::blue);
159  layout->addWidget(m_showButton);
160  connect(m_showButton, SIGNAL(stateChanged(bool)),
161  this, SIGNAL(showLayer(bool)));
162  connect(m_showButton, SIGNAL(mouseEntered()),
163  this, SLOT(mouseEnteredWidget()));
164  connect(m_showButton, SIGNAL(mouseLeft()),
165  this, SLOT(mouseLeftWidget()));
166  layout->setAlignment(m_showButton, Qt::AlignVCenter);
167  }
168 
169  if (params) {
170 
171  QLabel *playLabel = new QLabel(tr("Play"));
172  layout->addWidget(playLabel);
173  layout->setAlignment(playLabel, Qt::AlignVCenter);
174 
175  m_playButton = new LEDButton(Qt::darkGreen);
176  m_playButton->setState(!params->isPlayMuted());
177  layout->addWidget(m_playButton);
178  connect(m_playButton, SIGNAL(stateChanged(bool)),
179  this, SLOT(playAudibleButtonChanged(bool)));
180  connect(m_playButton, SIGNAL(mouseEntered()),
181  this, SLOT(mouseEnteredWidget()));
182  connect(m_playButton, SIGNAL(mouseLeft()),
183  this, SLOT(mouseLeftWidget()));
184  connect(params, SIGNAL(playAudibleChanged(bool)),
185  this, SLOT(playAudibleChanged(bool)));
186  layout->setAlignment(m_playButton, Qt::AlignVCenter);
187 
188  layout->insertStretch(-1, 10);
189 
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()),
197  this, SLOT(editPlayParameters()));
198  }
199 
200  AudioDial *gainDial = new AudioDial;
201  layout->addWidget(gainDial);
202  gainDial->setMeterColor(Qt::darkRed);
203  gainDial->setMinimum(-50);
204  gainDial->setMaximum(50);
205  gainDial->setPageStep(1);
206  gainDial->setFixedWidth(24);
207  gainDial->setFixedHeight(24);
208  gainDial->setNotchesVisible(false);
209  gainDial->setDefaultValue(0);
210  gainDial->setObjectName(tr("Playback Gain"));
211  gainDial->setRangeMapper(new LinearRangeMapper
212  (-50, 50, -25, 25, tr("dB")));
213  gainDial->setShowToolTip(true);
214  connect(gainDial, SIGNAL(valueChanged(int)),
215  this, SLOT(playGainDialChanged(int)));
216  connect(params, SIGNAL(playGainChanged(float)),
217  this, SLOT(playGainChanged(float)));
218  connect(this, SIGNAL(changePlayGainDial(int)),
219  gainDial, SLOT(setValue(int)));
220  connect(gainDial, SIGNAL(mouseEntered()),
221  this, SLOT(mouseEnteredWidget()));
222  connect(gainDial, SIGNAL(mouseLeft()),
223  this, SLOT(mouseLeftWidget()));
224  playGainChanged(params->getPlayGain());
225  layout->setAlignment(gainDial, Qt::AlignVCenter);
226 
227  AudioDial *panDial = new AudioDial;
228  layout->addWidget(panDial);
229  panDial->setMeterColor(Qt::darkGreen);
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"));
237  panDial->setDefaultValue(0);
238  panDial->setObjectName(tr("Playback Pan / Balance"));
239  panDial->setShowToolTip(true);
240  connect(panDial, SIGNAL(valueChanged(int)),
241  this, SLOT(playPanDialChanged(int)));
242  connect(params, SIGNAL(playPanChanged(float)),
243  this, SLOT(playPanChanged(float)));
244  connect(this, SIGNAL(changePlayPanDial(int)),
245  panDial, SLOT(setValue(int)));
246  connect(panDial, SIGNAL(mouseEntered()),
247  this, SLOT(mouseEnteredWidget()));
248  connect(panDial, SIGNAL(mouseLeft()),
249  this, SLOT(mouseLeftWidget()));
250  playPanChanged(params->getPlayPan());
251  layout->setAlignment(panDial, Qt::AlignVCenter);
252 
253  } else {
254 
255  layout->insertStretch(-1, 10);
256  }
257 }
258 
259 void
260 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name,
261  bool rangeChanged)
262 {
263  PropertyContainer::PropertyType type = m_container->getPropertyType(name);
264  int row = m_layout->rowCount();
265 
266  int min = 0, max = 0, value = 0, deflt = 0;
267  value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
268 
269  bool have = (m_propertyControllers.find(name) !=
270  m_propertyControllers.end());
271 
272  QString groupName = m_container->getPropertyGroupName(name);
273  QString propertyLabel = m_container->getPropertyLabel(name);
274  QString iconName = m_container->getPropertyIconName(name);
275 
276 #ifdef DEBUG_PROPERTY_BOX
277  cerr << "PropertyBox[" << this
278  << "(\"" << m_container->getPropertyContainerName()
279  << "\")]";
280  cerr << "::updatePropertyEditor(\"" << name << "\"):";
281  cerr << " value " << value << ", have " << have << ", group \""
282  << groupName << "\"" << endl;
283 #endif
284 
285  bool inGroup = (groupName != QString());
286 
287  if (!have) {
288  if (inGroup) {
289  if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
290 #ifdef DEBUG_PROPERTY_BOX
291  cerr << "PropertyBox: adding label \"" << groupName << "\" and frame for group for \"" << name << "\"" << endl;
292 #endif
293  m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
294  QFrame *frame = new QFrame(m_mainWidget);
295  m_layout->addWidget(frame, row, 1, 1, 2);
296  m_groupLayouts[groupName] = new QGridLayout;
297  m_groupLayouts[groupName]->setMargin(0);
298  frame->setLayout(m_groupLayouts[groupName]);
299  }
300  } else {
301 #ifdef DEBUG_PROPERTY_BOX
302  cerr << "PropertyBox: adding label \"" << propertyLabel << "\"" << endl;
303 #endif
304  m_layout->addWidget(new QLabel(propertyLabel, m_mainWidget), row, 0);
305  }
306  }
307 
308  switch (type) {
309 
310  case PropertyContainer::ToggleProperty:
311  {
312  QAbstractButton *button = 0;
313 
314  if (have) {
315  button = dynamic_cast<QAbstractButton *>(m_propertyControllers[name]);
316  assert(button);
317  } else {
318 #ifdef DEBUG_PROPERTY_BOX
319  cerr << "PropertyBox: creating new checkbox" << endl;
320 #endif
321  if (iconName != "") {
322  button = new NotifyingPushButton();
323  button->setCheckable(true);
324  QIcon icon(IconLoader().load(iconName));
325  button->setIcon(icon);
326  button->setObjectName(name);
327  button->setFixedSize(QSize(18, 18));
328  } else {
329  button = new NotifyingCheckBox();
330  button->setObjectName(name);
331  }
332  connect(button, SIGNAL(toggled(bool)),
333  this, SLOT(propertyControllerChanged(bool)));
334  connect(button, SIGNAL(mouseEntered()),
335  this, SLOT(mouseEnteredWidget()));
336  connect(button, SIGNAL(mouseLeft()),
337  this, SLOT(mouseLeftWidget()));
338  if (inGroup) {
339  button->setToolTip(propertyLabel);
340  m_groupLayouts[groupName]->addWidget
341  (button, 0, m_groupLayouts[groupName]->columnCount());
342  } else {
343  m_layout->addWidget(button, row, 1, 1, 2);
344  }
345  m_propertyControllers[name] = button;
346  }
347 
348  if (button->isChecked() != (value > 0)) {
349  button->blockSignals(true);
350  button->setChecked(value > 0);
351  button->blockSignals(false);
352  }
353  break;
354  }
355 
356  case PropertyContainer::RangeProperty:
357  {
358  AudioDial *dial;
359 
360  if (have) {
361  dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
362  assert(dial);
363  if (rangeChanged) {
364  dial->blockSignals(true);
365  dial->setMinimum(min);
366  dial->setMaximum(max);
367  dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
368  dial->blockSignals(false);
369  }
370 
371  } else {
372 #ifdef DEBUG_PROPERTY_BOX
373  cerr << "PropertyBox: creating new dial" << endl;
374 #endif
375  dial = new AudioDial();
376  dial->setObjectName(name);
377  dial->setMinimum(min);
378  dial->setMaximum(max);
379  dial->setPageStep(1);
380  dial->setNotchesVisible((max - min) <= 12);
381  dial->setDefaultValue(deflt);
382  dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
383  dial->setShowToolTip(true);
384  connect(dial, SIGNAL(valueChanged(int)),
385  this, SLOT(propertyControllerChanged(int)));
386  connect(dial, SIGNAL(mouseEntered()),
387  this, SLOT(mouseEnteredWidget()));
388  connect(dial, SIGNAL(mouseLeft()),
389  this, SLOT(mouseLeftWidget()));
390 
391  if (inGroup) {
392  dial->setFixedWidth(24);
393  dial->setFixedHeight(24);
394  m_groupLayouts[groupName]->addWidget
395  (dial, 0, m_groupLayouts[groupName]->columnCount());
396  } else {
397  dial->setFixedWidth(32);
398  dial->setFixedHeight(32);
399  m_layout->addWidget(dial, row, 1);
400  QLabel *label = new QLabel(m_mainWidget);
401  connect(dial, SIGNAL(valueChanged(int)),
402  label, SLOT(setNum(int)));
403  label->setNum(value);
404  m_layout->addWidget(label, row, 2);
405  }
406 
407  m_propertyControllers[name] = dial;
408  }
409 
410  if (dial->value() != value) {
411  dial->blockSignals(true);
412  dial->setValue(value);
413  dial->blockSignals(false);
414  }
415  break;
416  }
417 
418  case PropertyContainer::ValueProperty:
419  case PropertyContainer::UnitsProperty:
420  case PropertyContainer::ColourProperty:
421  {
422  NotifyingComboBox *cb;
423 
424  if (have) {
425  cb = dynamic_cast<NotifyingComboBox *>(m_propertyControllers[name]);
426  assert(cb);
427  } else {
428 #ifdef DEBUG_PROPERTY_BOX
429  cerr << "PropertyBox: creating new combobox" << endl;
430 #endif
431 
432  cb = new NotifyingComboBox();
433  cb->setObjectName(name);
434  cb->setDuplicatesEnabled(false);
435  }
436 
437  if (!have || rangeChanged) {
438 
439  cb->blockSignals(true);
440  cb->clear();
441  cb->setEditable(false);
442 
443  if (type == PropertyContainer::ValueProperty) {
444 
445  for (int i = min; i <= max; ++i) {
446  cb->addItem(m_container->getPropertyValueLabel(name, i));
447  }
448 
449  } else if (type == PropertyContainer::UnitsProperty) {
450 
451  QStringList units = UnitDatabase::getInstance()->getKnownUnits();
452  for (int i = 0; i < units.size(); ++i) {
453  cb->addItem(units[i]);
454  }
455 
456  cb->setEditable(true);
457 
458  } else { // ColourProperty
459 
461  // manages its own Add New Colour entry...
462 
464  for (int i = 0; i < db->getColourCount(); ++i) {
465  QString name = db->getColourName(i);
466  cb->addItem(db->getExamplePixmap(i, QSize(12, 12)), name);
467  }
468  cb->addItem(tr("Add New Colour..."));
469  }
470 
471  cb->blockSignals(false);
472  if (cb->count() < 20 && cb->count() > cb->maxVisibleItems()) {
473  cb->setMaxVisibleItems(cb->count());
474  }
475  }
476 
477  if (!have) {
478  connect(cb, SIGNAL(activated(int)),
479  this, SLOT(propertyControllerChanged(int)));
480  connect(cb, SIGNAL(mouseEntered()),
481  this, SLOT(mouseEnteredWidget()));
482  connect(cb, SIGNAL(mouseLeft()),
483  this, SLOT(mouseLeftWidget()));
484 
485  if (inGroup) {
486  cb->setToolTip(propertyLabel);
487  m_groupLayouts[groupName]->addWidget
488  (cb, 0, m_groupLayouts[groupName]->columnCount());
489  } else {
490  m_layout->addWidget(cb, row, 1, 1, 2);
491  }
492  m_propertyControllers[name] = cb;
493  }
494 
495  cb->blockSignals(true);
496  if (type == PropertyContainer::ValueProperty ||
497  type == PropertyContainer::ColourProperty) {
498  if (cb->currentIndex() != value) {
499  cb->setCurrentIndex(value);
500  }
501  } else {
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);
507  break;
508  }
509  }
510  }
511  }
512  cb->blockSignals(false);
513 
514 #ifdef Q_OS_MAC
515  // Crashes on startup without this, for some reason
516  cb->setMinimumSize(QSize(10, 10));
517 #endif
518 
519  break;
520  }
521 
522  case PropertyContainer::InvalidProperty:
523  default:
524  break;
525  }
526 }
527 
528 void
530 {
531  if (pc != m_container) return;
532 
533 #ifdef DEBUG_PROPERTY_BOX
534  SVDEBUG << "PropertyBox::propertyContainerPropertyChanged" << endl;
535 #endif
536 
537  PropertyContainer::PropertyList properties = m_container->getProperties();
538  size_t i;
539 
540  blockSignals(true);
541 
542  for (i = 0; i < properties.size(); ++i) {
543  updatePropertyEditor(properties[i]);
544  }
545 
546  blockSignals(false);
547 }
548 
549 void
551 {
552  blockSignals(true);
553 
554  PropertyContainer::PropertyList properties = m_container->getProperties();
555  for (size_t i = 0; i < properties.size(); ++i) {
556  updatePropertyEditor(properties[i], true);
557  }
558 
559  blockSignals(false);
560 }
561 
562 void
564 {
565 #ifdef DEBUG_PROPERTY_BOX
566  cerr << "PropertyBox[" << this << "]: unitDatabaseChanged" << endl;
567 #endif
568  blockSignals(true);
569 
570 // cerr << "my container is " << m_container << endl;
571 // cerr << "my container's name is... " << endl;
572 // cerr << m_container->objectName() << endl;
573 
574  PropertyContainer::PropertyList properties = m_container->getProperties();
575  for (size_t i = 0; i < properties.size(); ++i) {
576  if (m_container->getPropertyType(properties[i]) ==
577  PropertyContainer::UnitsProperty) {
578  updatePropertyEditor(properties[i]);
579  }
580  }
581 
582  blockSignals(false);
583 }
584 
585 void
587 {
588  blockSignals(true);
589 
590  PropertyContainer::PropertyList properties = m_container->getProperties();
591  for (size_t i = 0; i < properties.size(); ++i) {
592  if (m_container->getPropertyType(properties[i]) ==
593  PropertyContainer::ColourProperty) {
594  updatePropertyEditor(properties[i], true);
595  }
596  }
597 
598  blockSignals(false);
599 }
600 
601 void
603 {
604  propertyControllerChanged(on ? 1 : 0);
605 }
606 
607 void
609 {
610  QObject *obj = sender();
611  QString name = obj->objectName();
612 
613 #ifdef DEBUG_PROPERTY_BOX
614  SVDEBUG << "PropertyBox::propertyControllerChanged(" << name << ", " << value << ")" << endl;
615 #endif
616 
617  PropertyContainer::PropertyType type = m_container->getPropertyType(name);
618 
619  Command *c = 0;
620 
621  if (type == PropertyContainer::UnitsProperty) {
622 
623  NotifyingComboBox *cb = dynamic_cast<NotifyingComboBox *>(obj);
624  if (cb) {
625  QString unit = cb->currentText();
626  c = m_container->getSetPropertyCommand
627  (name, UnitDatabase::getInstance()->getUnitId(unit));
628  }
629 
630  } else if (type == PropertyContainer::ColourProperty) {
631 
632  if (value == int(ColourDatabase::getInstance()->getColourCount())) {
633  addNewColour();
634  if (value == int(ColourDatabase::getInstance()->getColourCount())) {
636  return;
637  }
638  }
639  c = m_container->getSetPropertyCommand(name, value);
640 
641  } else if (type != PropertyContainer::InvalidProperty) {
642 
643  c = m_container->getSetPropertyCommand(name, value);
644  }
645 
646  if (c) CommandHistory::getInstance()->addCommand(c, true, true);
647 
648  updateContextHelp(obj);
649 }
650 
651 void
653 {
654  QColor newColour = QColorDialog::getColor();
655  if (!newColour.isValid()) return;
656 
657  ColourNameDialog dialog(tr("Name New Colour"),
658  tr("Enter a name for the new colour:"),
659  newColour, newColour.name(), this);
660  dialog.showDarkBackgroundCheckbox(tr("Prefer black background for this colour"));
661  if (dialog.exec() == QDialog::Accepted) {
664  int index = db->addColour(newColour, dialog.getColourName());
665  db->setUseDarkBackground(index, dialog.isDarkBackgroundChecked());
666  }
667 }
668 
669 void
671 {
672  m_playButton->setState(audible);
673 }
674 
675 void
677 {
678  PlayParameters *params = m_container->getPlayParameters();
679  if (!params) return;
680 
681  if (params->isPlayAudible() != audible) {
682  PlayParameterRepository::EditCommand *command =
683  new PlayParameterRepository::EditCommand(params);
684  command->setPlayAudible(audible);
685  CommandHistory::getInstance()->addCommand(command, true, true);
686  }
687 }
688 
689 void
691 {
692  int dialValue = lrint(log10(gain) * 20.0);
693  if (dialValue < -50) dialValue = -50;
694  if (dialValue > 50) dialValue = 50;
695  emit changePlayGainDial(dialValue);
696 }
697 
698 void
700 {
701  QObject *obj = sender();
702 
703  PlayParameters *params = m_container->getPlayParameters();
704  if (!params) return;
705 
706  float gain = pow(10, float(dialValue) / 20.0);
707 
708  if (params->getPlayGain() != gain) {
709  PlayParameterRepository::EditCommand *command =
710  new PlayParameterRepository::EditCommand(params);
711  command->setPlayGain(gain);
712  CommandHistory::getInstance()->addCommand(command, true, true);
713  }
714 
715  updateContextHelp(obj);
716 }
717 
718 void
720 {
721  int dialValue = lrint(pan * 50.0);
722  if (dialValue < -50) dialValue = -50;
723  if (dialValue > 50) dialValue = 50;
724  emit changePlayPanDial(dialValue);
725 }
726 
727 void
729 {
730  QObject *obj = sender();
731 
732  PlayParameters *params = m_container->getPlayParameters();
733  if (!params) return;
734 
735  float pan = float(dialValue) / 50.0;
736  if (pan < -1.0) pan = -1.0;
737  if (pan > 1.0) pan = 1.0;
738 
739  if (params->getPlayPan() != pan) {
740  PlayParameterRepository::EditCommand *command =
741  new PlayParameterRepository::EditCommand(params);
742  command->setPlayPan(pan);
743  CommandHistory::getInstance()->addCommand(command, true, true);
744  }
745 
746  updateContextHelp(obj);
747 }
748 
749 void
751 {
752  PlayParameters *params = m_container->getPlayParameters();
753  if (!params) return;
754 
755  QString clip = params->getPlayClipId();
756 
757  PlayParameterRepository::EditCommand *command =
758  new PlayParameterRepository::EditCommand(params);
759 
760  QInputDialog *dialog = new QInputDialog(this);
761 
762  QDir dir(":/samples");
763  QStringList clipFiles = dir.entryList(QStringList() << "*.wav", QDir::Files);
764 
765  QStringList clips;
766  foreach (QString str, clipFiles) {
767  clips.push_back(str.replace(".wav", ""));
768  }
769  dialog->setComboBoxItems(clips);
770 
771  dialog->setLabelText(tr("Set playback clip:"));
772 
773  QComboBox *cb = dialog->findChild<QComboBox *>();
774  if (cb) {
775  for (int i = 0; i < cb->count(); ++i) {
776  if (cb->itemText(i) == clip) {
777  cb->setCurrentIndex(i);
778  }
779  }
780  }
781 
782  connect(dialog, SIGNAL(textValueChanged(QString)),
783  this, SLOT(playClipChanged(QString)));
784 
785  if (dialog->exec() == QDialog::Accepted) {
786  QString newClip = dialog->textValue();
787  command->setPlayClipId(newClip);
788  CommandHistory::getInstance()->addCommand(command, true);
789  } else {
790  delete command;
791  // restore in case we mucked about with the configuration
792  // as a consequence of signals from the dialog
793  params->setPlayClipId(clip);
794  }
795 
796  delete dialog;
797 }
798 
799 void
801 {
802  PlayParameters *params = m_container->getPlayParameters();
803  if (!params) return;
804 
805  params->setPlayClipId(id);
806 }
807 
808 void
810 {
811  if (m_showButton) m_showButton->setState(visible);
812 }
813 
814 void
816 {
817  updateContextHelp(sender());
818 }
819 
820 void
822 {
823  QWidget *w = dynamic_cast<QWidget *>(o);
824  if (!w) return;
825 
826  if (!m_container) return;
827  QString cname = m_container->getPropertyContainerName();
828  if (cname == "") return;
829 
830  QString wname = w->objectName();
831 
832  QString extraText;
833  AudioDial *dial = dynamic_cast<AudioDial *>(w);
834  if (dial) {
835  float mv = dial->mappedValue();
836  QString unit = "";
837  if (dial->rangeMapper()) unit = dial->rangeMapper()->getUnit();
838  if (unit != "") {
839  extraText = tr(" (current value: %1%2)").arg(mv).arg(unit);
840  } else {
841  extraText = tr(" (current value: %1)").arg(mv);
842  }
843  }
844 
845  if (w == m_showButton) {
846  emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
847  } else if (w == m_playButton) {
848  emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
849  } else if (wname == "") {
850  return;
851  } else if (dynamic_cast<QAbstractButton *>(w)) {
852  emit contextHelpChanged(tr("Toggle %1 property of %2")
853  .arg(wname).arg(cname));
854  } else {
855  emit contextHelpChanged(tr("Adjust %1 property of %2%3")
856  .arg(wname).arg(cname).arg(extraText));
857  }
858 }
859 
860 void
862 {
863  if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
864  emit contextHelpChanged("");
865  }
866 }
867 
868 
Very trivial enhancement to QComboBox to make it emit signals when the mouse enters and leaves (for c...
QString getColourName(int c) const
QGridLayout * m_layout
Definition: PropertyBox.h:82
void propertyContainerPropertyChanged(PropertyContainer *)
QFrame * m_viewPlayFrame
Definition: PropertyBox.h:84
Very trivial enhancement to QPushButton to make it emit signals when the mouse enters and leaves (for...
The base class for visual representations of the data found in a Model.
Definition: Layer.h:52
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)
Definition: AudioDial.cpp:339
void mouseEnteredWidget()
void playPanDialChanged(int)
std::map< QString, QWidget * > m_propertyControllers
Definition: PropertyBox.h:89
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).
Definition: AudioDial.cpp:326
float mappedValue() const
Definition: AudioDial.cpp:390
void propertyControllerChanged(int)
QPixmap getExamplePixmap(int index, QSize size) const
QVBoxLayout * m_mainBox
Definition: PropertyBox.h:85
void addCommand(Command *command)
Add a command to the command history.
int addColour(QColor, QString)
void updatePropertyEditor(PropertyContainer::PropertyName, bool rangeChanged=false)
LEDButton * m_showButton
Definition: PropertyBox.h:86
QWidget * m_mainWidget
Definition: PropertyBox.h:81
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...
Definition: AudioDial.h:59
void layerVisibilityChanged(bool)
void showLayer(bool)
void playPanChanged(float)
void propertyContainerPropertyRangeChanged(PropertyContainer *)
void changePlayPanDial(int)
std::map< QString, QGridLayout * > m_groupLayouts
Definition: PropertyBox.h:88
void addNewColour()
PropertyContainer * m_container
Definition: PropertyBox.h:83
int getColourCount() const
void editPlayParameters()
void setValue(int value)
Definition: AudioDial.cpp:347
static CommandHistory * getInstance()
void playGainChanged(float)
void setState(bool)
Definition: LEDButton.cpp:283
void mouseLeftWidget()
PropertyBox(PropertyContainer *)
Definition: PropertyBox.cpp:53
void setRangeMapper(RangeMapper *mapper)
Definition: AudioDial.cpp:100
void populateViewPlayFrame()
LEDButton * m_playButton
Definition: PropertyBox.h:87
void playAudibleButtonChanged(bool)
void playClipChanged(QString)
void changePlayGainDial(int)
void showDarkBackgroundCheckbox(QString text)
void unitDatabaseChanged()
static ColourDatabase * getInstance()
const RangeMapper * rangeMapper() const
Definition: AudioDial.h:75
void setShowToolTip(bool show)
Definition: AudioDial.cpp:381