comparison widgets/PropertyBox.cpp @ 1602:a798a7b5e215

Further removal of Qt 5.6+-only APIs
author Chris Cannam
date Wed, 29 Apr 2020 14:46:37 +0100
parents 26e80a450e74
children 5feb1a8318df
comparison
equal deleted inserted replaced
1601:4739a1b2266f 1602:a798a7b5e215
59 59
60 PropertyBox::PropertyBox(PropertyContainer *container) : 60 PropertyBox::PropertyBox(PropertyContainer *container) :
61 m_container(container), 61 m_container(container),
62 m_showButton(nullptr), 62 m_showButton(nullptr),
63 m_playButton(nullptr), 63 m_playButton(nullptr),
64 m_lastContextMenu(nullptr) 64 m_lastContextMenu(nullptr),
65 m_contextMenuOn(nullptr)
65 { 66 {
66 #ifdef DEBUG_PROPERTY_BOX 67 #ifdef DEBUG_PROPERTY_BOX
67 SVDEBUG << "PropertyBox[" << this << "(\"" << 68 SVDEBUG << "PropertyBox[" << this << "(\"" <<
68 container->getPropertyContainerName() << "\" at " << container << ")]::PropertyBox" << endl; 69 container->getPropertyContainerName() << "\" at " << container << ")]::PropertyBox" << endl;
69 #endif 70 #endif
693 int min = 0, max = 0, value = 0, deflt = 0; 694 int min = 0, max = 0, value = 0, deflt = 0;
694 value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt); 695 value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
695 696
696 delete m_lastContextMenu; 697 delete m_lastContextMenu;
697 QMenu *m = new QMenu; 698 QMenu *m = new QMenu;
699
698 m_lastContextMenu = m; 700 m_lastContextMenu = m;
699 701 m_contextMenuOn = obj;
700 if (auto button = qobject_cast<QAbstractButton *>(obj)) { 702
703 if (qobject_cast<QAbstractButton *>(obj)) {
701 if (value > 0) { 704 if (value > 0) {
702 MenuTitle::addTitle(m, tr("%1: On").arg(label)); 705 MenuTitle::addTitle(m, tr("%1: On").arg(label));
703 } else { 706 } else {
704 MenuTitle::addTitle(m, tr("%1: Off").arg(label)); 707 MenuTitle::addTitle(m, tr("%1: Off").arg(label));
705 } 708 }
706 709 m->addAction(tr("&Reset to Default"), this,
707 m->addAction(tr("&Reset to Default"), 710 SLOT(propertyControllerResetRequested()));
708 [=]() {
709 button->setChecked(deflt > 0);
710 });
711 711
712 } else if (auto cb = qobject_cast<QComboBox *>(obj)) { 712 } else if (auto cb = qobject_cast<QComboBox *>(obj)) {
713 MenuTitle::addTitle(m, tr("%1: %2").arg(label).arg(cb->itemText(value))); 713 MenuTitle::addTitle(m, tr("%1: %2").arg(label).arg(cb->itemText(value)));
714 m->addAction(tr("&Reset to Default"), 714 m->addAction(tr("&Reset to Default"), this,
715 [=]() { 715 SLOT(propertyControllerResetRequested()));
716 cb->setCurrentIndex(deflt); 716
717 });
718 } else { 717 } else {
719 // AudioDial has its own context menu, we don't handle it here 718 // AudioDial has its own context menu, we don't handle it here
720 return; 719 return;
721 } 720 }
722 721
723 m->popup(qobject_cast<QWidget *>(sender())->mapToGlobal(pos)); 722 m->popup(qobject_cast<QWidget *>(sender())->mapToGlobal(pos));
723 }
724
725 void
726 PropertyBox::propertyControllerResetRequested()
727 {
728 if (!m_contextMenuOn) return;
729
730 QString name = m_contextMenuOn->objectName();
731
732 QString label = m_container->getPropertyLabel(name);
733 int min = 0, max = 0, value = 0, deflt = 0;
734 value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
735
736 if (auto button = qobject_cast<QAbstractButton *>(m_contextMenuOn)) {
737 button->setChecked(deflt > 0);
738 } else if (auto cb = qobject_cast<QComboBox *>(m_contextMenuOn)) {
739 cb->setCurrentIndex(deflt);
740 }
724 } 741 }
725 742
726 void 743 void
727 PropertyBox::playAudibleChanged(bool audible) 744 PropertyBox::playAudibleChanged(bool audible)
728 { 745 {