comparison widgets/PropertyBox.cpp @ 374:64e84e5efb76 spectrogram-cache-rejig

* Merge from trunk
author Chris Cannam
date Wed, 27 Feb 2008 11:59:42 +0000
parents 3101c68a00c1
children
comparison
equal deleted inserted replaced
332:6440e280122e 374:64e84e5efb76
27 #include "plugin/RealTimePluginInstance.h" 27 #include "plugin/RealTimePluginInstance.h"
28 #include "plugin/PluginXml.h" 28 #include "plugin/PluginXml.h"
29 29
30 #include "AudioDial.h" 30 #include "AudioDial.h"
31 #include "LEDButton.h" 31 #include "LEDButton.h"
32 #include "IconLoader.h"
32 33
33 #include "NotifyingCheckBox.h" 34 #include "NotifyingCheckBox.h"
34 #include "NotifyingComboBox.h" 35 #include "NotifyingComboBox.h"
36 #include "NotifyingPushButton.h"
35 #include "ColourNameDialog.h" 37 #include "ColourNameDialog.h"
36 38
37 #include <QGridLayout> 39 #include <QGridLayout>
38 #include <QHBoxLayout> 40 #include <QHBoxLayout>
39 #include <QVBoxLayout> 41 #include <QVBoxLayout>
268 bool have = (m_propertyControllers.find(name) != 270 bool have = (m_propertyControllers.find(name) !=
269 m_propertyControllers.end()); 271 m_propertyControllers.end());
270 272
271 QString groupName = m_container->getPropertyGroupName(name); 273 QString groupName = m_container->getPropertyGroupName(name);
272 QString propertyLabel = m_container->getPropertyLabel(name); 274 QString propertyLabel = m_container->getPropertyLabel(name);
275 QString iconName = m_container->getPropertyIconName(name);
273 276
274 #ifdef DEBUG_PROPERTY_BOX 277 #ifdef DEBUG_PROPERTY_BOX
275 std::cerr << "PropertyBox[" << this 278 std::cerr << "PropertyBox[" << this
276 << "(\"" << m_container->getPropertyContainerName().toStdString() 279 << "(\"" << m_container->getPropertyContainerName().toStdString()
277 << "\")]"; 280 << "\")]";
305 308
306 switch (type) { 309 switch (type) {
307 310
308 case PropertyContainer::ToggleProperty: 311 case PropertyContainer::ToggleProperty:
309 { 312 {
310 NotifyingCheckBox *cb; 313 QAbstractButton *button = 0;
311 314
312 if (have) { 315 if (have) {
313 cb = dynamic_cast<NotifyingCheckBox *>(m_propertyControllers[name]); 316 button = dynamic_cast<QAbstractButton *>(m_propertyControllers[name]);
314 assert(cb); 317 assert(button);
315 } else { 318 } else {
316 #ifdef DEBUG_PROPERTY_BOX 319 #ifdef DEBUG_PROPERTY_BOX
317 std::cerr << "PropertyBox: creating new checkbox" << std::endl; 320 std::cerr << "PropertyBox: creating new checkbox" << std::endl;
318 #endif 321 #endif
319 cb = new NotifyingCheckBox(); 322 if (iconName != "") {
320 cb->setObjectName(name); 323 button = new NotifyingPushButton();
321 connect(cb, SIGNAL(stateChanged(int)), 324 button->setCheckable(true);
322 this, SLOT(propertyControllerChanged(int))); 325 QIcon icon(IconLoader().load(iconName));
323 connect(cb, SIGNAL(mouseEntered()), 326 button->setIcon(icon);
327 button->setObjectName(name);
328 button->setFixedSize(QSize(18, 18));
329 } else {
330 button = new NotifyingCheckBox();
331 button->setObjectName(name);
332 }
333 connect(button, SIGNAL(toggled(bool)),
334 this, SLOT(propertyControllerChanged(bool)));
335 connect(button, SIGNAL(mouseEntered()),
324 this, SLOT(mouseEnteredWidget())); 336 this, SLOT(mouseEnteredWidget()));
325 connect(cb, SIGNAL(mouseLeft()), 337 connect(button, SIGNAL(mouseLeft()),
326 this, SLOT(mouseLeftWidget())); 338 this, SLOT(mouseLeftWidget()));
327 if (inGroup) { 339 if (inGroup) {
328 cb->setToolTip(propertyLabel); 340 button->setToolTip(propertyLabel);
329 m_groupLayouts[groupName]->addWidget(cb); 341 m_groupLayouts[groupName]->addWidget(button);
330 } else { 342 } else {
331 m_layout->addWidget(cb, row, 1, 1, 2); 343 m_layout->addWidget(button, row, 1, 1, 2);
332 } 344 }
333 m_propertyControllers[name] = cb; 345 m_propertyControllers[name] = button;
334 } 346 }
335 347
336 if (cb->isChecked() != (value > 0)) { 348 if (button->isChecked() != (value > 0)) {
337 cb->blockSignals(true); 349 button->blockSignals(true);
338 cb->setChecked(value > 0); 350 button->setChecked(value > 0);
339 cb->blockSignals(false); 351 button->blockSignals(false);
340 } 352 }
341 break; 353 break;
342 } 354 }
343 355
344 case PropertyContainer::RangeProperty: 356 case PropertyContainer::RangeProperty:
575 587
576 blockSignals(false); 588 blockSignals(false);
577 } 589 }
578 590
579 void 591 void
592 PropertyBox::propertyControllerChanged(bool on)
593 {
594 propertyControllerChanged(on ? 1 : 0);
595 }
596
597 void
580 PropertyBox::propertyControllerChanged(int value) 598 PropertyBox::propertyControllerChanged(int value)
581 { 599 {
582 QObject *obj = sender(); 600 QObject *obj = sender();
583 QString name = obj->objectName(); 601 QString name = obj->objectName();
584 602
622 { 640 {
623 QColor newColour = QColorDialog::getColor(); 641 QColor newColour = QColorDialog::getColor();
624 if (!newColour.isValid()) return; 642 if (!newColour.isValid()) return;
625 643
626 ColourNameDialog dialog(tr("Name New Colour"), 644 ColourNameDialog dialog(tr("Name New Colour"),
627 tr("Enter name for the new colour:"), 645 tr("Enter a name for the new colour:"),
628 newColour, "", this); 646 newColour, newColour.name(), this);
629 dialog.showDarkBackgroundCheckbox(tr("Prefer black background for this colour")); 647 dialog.showDarkBackgroundCheckbox(tr("Prefer black background for this colour"));
630 if (dialog.exec() == QDialog::Accepted) { 648 if (dialog.exec() == QDialog::Accepted) {
631 //!!! command 649 //!!! command
632 ColourDatabase *db = ColourDatabase::getInstance(); 650 ColourDatabase *db = ColourDatabase::getInstance();
633 int index = db->addColour(newColour, dialog.getColourName()); 651 int index = db->addColour(newColour, dialog.getColourName());
760 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname)); 778 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
761 } else if (w == m_playButton) { 779 } else if (w == m_playButton) {
762 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname)); 780 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
763 } else if (wname == "") { 781 } else if (wname == "") {
764 return; 782 return;
765 } else if (dynamic_cast<NotifyingCheckBox *>(w)) { 783 } else if (dynamic_cast<QAbstractButton *>(w)) {
766 emit contextHelpChanged(tr("Toggle %1 property of %2") 784 emit contextHelpChanged(tr("Toggle %1 property of %2")
767 .arg(wname).arg(cname)); 785 .arg(wname).arg(cname));
768 } else { 786 } else {
769 emit contextHelpChanged(tr("Adjust %1 property of %2%3") 787 emit contextHelpChanged(tr("Adjust %1 property of %2%3")
770 .arg(wname).arg(cname).arg(extraText)); 788 .arg(wname).arg(cname).arg(extraText));